Skip to content

fix(three): accept array springs on vector and euler props - #2688

Open
imeerkhurram wants to merge 1 commit into
pmndrs:nextfrom
imeerkhurram:fix/three-array-spring-props
Open

imeerkhurram wants to merge 1 commit into
pmndrs:nextfrom
imeerkhurram:fix/three-array-spring-props

Conversation

@imeerkhurram

Copy link
Copy Markdown

Why

Resolves #2312

With @react-spring/three, a spring made from an array cannot be passed to rotation. On next (@react-three/fiber 9.8, @types/three 0.187) the same happens for position and scale:

const { position, rotation } = useSpring({
  position: [0, 0, 0] as const,
  rotation: [0, Math.PI / 2, 0] as const,
})

<animated.group position={position} rotation={rotation} />
// Type 'SpringValue<[0, 0, 0]>' is not assignable to type 'number | FluidValue<number, any> | ...'

It works at runtime; only the types reject it.

In targets/three/src/animated.ts, AnimatedProp gives array members of a prop type ([x, y, z]) no FluidValue of their own. The only FluidValue comes from AnimatedLeaf, and that has two gaps:

  • It runs only for the primitive members of the prop type. rotation in fiber 8 (THREE.Euler | [x, y, z, order?]) has no primitive member, so it got no FluidValue at all. That is the case in the issue.
  • Its Extract<T, ReadonlyArray<number | string>> drops tuples that have optional elements, because an optional element adds undefined. The Euler tuple is [x, y, z, order?], and with current @types/three (Vector3.set(x, y, z?)) the Vector3 tuple is [x, y, z?]. Fiber 9 added number to Euler, but the tuples are still dropped, so position, rotation and scale all end up accepting only FluidValue<number>.

What

  • The array branch of AnimatedProp now also accepts FluidValue<Tuple> when the tuple holds numbers, strings or undefined. It sits next to AnimatedStyles, so it does not depend on the prop type having a primitive member.
  • Added targets/three/src/animated.test-d.tsx. It checks that position, rotation and scale springs built from tuples are assignable to the animated.mesh props, and that a SpringValue<string> or SpringValue<[string, string]> is still rejected. A second case is the reproduction from the issue on animated.group.
  • Added targets/**/src/**/*.test-d.{ts,tsx} to the types project in vitest.config.ts so pnpm test:types runs type tests for the targets. Before this, only packages/** was included.
  • Changeset: @react-spring/three patch.

Without the source change, the new type test fails (5 type errors, both cases). With it, everything passes:

  • pnpm format:check: clean
  • pnpm lint: exit 0, no new warnings
  • pnpm build-ci: 8/8 tasks
  • pnpm check:types: clean
  • pnpm test:types: 20 files, 54 tests, no type errors
  • pnpm test:unit: 35 files, 454 tests passed
  • pnpm test:e2e: 3 files, 13 tests passed

I also checked that widening the new branch to FluidValue<any> makes the negative assertions fail, so the test guards both directions.

Checklist

  • Linked an issue (Resolves #…)
  • pnpm format:check, pnpm lint, pnpm check:types and pnpm test:unit pass locally
  • New tests fail without the fix
  • Changeset added (if published behaviour changes)
  • Documentation updated
  • Demo added
  • Ready to be merged

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-bot

changeset-bot Bot commented Nov 28, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: c4f3e30

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 8 packages
Name Type
@react-spring/three Patch
@react-spring/animated Patch
@react-spring/core Patch
@react-spring/parallax Patch
@react-spring/rafz Patch
@react-spring/shared Patch
@react-spring/types Patch
@react-spring/web Patch

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

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug]: type error: animated group rotation prop does not accept array or euler object

1 participant