Repository navigation
fix(three): accept array springs on vector and euler props - #2688
Open
imeerkhurram wants to merge 1 commit into
Open
imeerkhurram wants to merge 1 commit into
imeerkhurram wants to merge 1 commit into
Conversation
Array props like position, rotation and scale only accepted a FluidValue through AnimatedLeaf. That runs only when the prop type also has a primitive member, and its Extract<T, ReadonlyArray<number | string>> drops tuples with optional elements. The Euler tuple has an optional order, and with current @types/three the Vector3 tuple has an optional z, so a spring of [x, y, z] could not be passed to position, rotation or scale. The array branch of AnimatedProp now also accepts a FluidValue of the tuple when its elements are numbers, strings or undefined. Type tests for the three target run in the types project now.
🦋 Changeset detectedLatest commit: c4f3e30 The changes in this PR will be included in the next version bump. This PR includes changesets to release 8 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Resolves #2312
With
@react-spring/three, a spring made from an array cannot be passed torotation. Onnext(@react-three/fiber9.8,@types/three0.187) the same happens forpositionandscale:It works at runtime; only the types reject it.
In
targets/three/src/animated.ts,AnimatedPropgives array members of a prop type ([x, y, z]) noFluidValueof their own. The onlyFluidValuecomes fromAnimatedLeaf, and that has two gaps:rotationin fiber 8 (THREE.Euler | [x, y, z, order?]) has no primitive member, so it got noFluidValueat all. That is the case in the issue.Extract<T, ReadonlyArray<number | string>>drops tuples that have optional elements, because an optional element addsundefined. TheEulertuple is[x, y, z, order?], and with current@types/three(Vector3.set(x, y, z?)) theVector3tuple is[x, y, z?]. Fiber 9 addednumbertoEuler, but the tuples are still dropped, soposition,rotationandscaleall end up accepting onlyFluidValue<number>.What
AnimatedPropnow also acceptsFluidValue<Tuple>when the tuple holds numbers, strings orundefined. It sits next toAnimatedStyles, so it does not depend on the prop type having a primitive member.targets/three/src/animated.test-d.tsx. It checks thatposition,rotationandscalesprings built from tuples are assignable to theanimated.meshprops, and that aSpringValue<string>orSpringValue<[string, string]>is still rejected. A second case is the reproduction from the issue onanimated.group.targets/**/src/**/*.test-d.{ts,tsx}to thetypesproject invitest.config.tssopnpm test:typesruns type tests for the targets. Before this, onlypackages/**was included.@react-spring/threepatch.Without the source change, the new type test fails (5 type errors, both cases). With it, everything passes:
pnpm format:check: cleanpnpm lint: exit 0, no new warningspnpm build-ci: 8/8 taskspnpm check:types: cleanpnpm test:types: 20 files, 54 tests, no type errorspnpm test:unit: 35 files, 454 tests passedpnpm test:e2e: 3 files, 13 tests passedI also checked that widening the new branch to
FluidValue<any>makes the negative assertions fail, so the test guards both directions.Checklist
Resolves #…)pnpm format:check,pnpm lint,pnpm check:typesandpnpm test:unitpass locally