Skip to content

fix(core): read useTransition defaults from props functions - #2660

Merged
joshuaellis merged 2 commits into
pmndrs:nextfrom
charan-rathore:fix/use-transition-factory-defaults
Nov 23, 2026
Merged

joshuaellis merged 2 commits into
pmndrs:nextfrom
charan-rathore:fix/use-transition-factory-defaults

Conversation

@charan-rathore

@charan-rathore charan-rathore commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Why

Handlers and explicit default props returned by a useTransition props function were not applied like the same props in object form.

Resolves #2048. The regression tests reproduce the reported behavior; the original CodeSandbox was not run.

What

Resolve the props function once per render and reuse its result for defaults, keys, transition phases and initial values. This also removes the shadowed props variables.

Use a patch-level core changeset, as requested in review. Move the regression tests into useTransition.test.tsx and remove the unused manual fixture and separate test files.

Local validation on Node 24.22.0, pnpm 12.14.0, React 19.3.1 and Chromium 156:

  • Native useTransition tests: unchanged next 18 passed / 11 failed; submitted source 26 passed / 3 failed; revised source 29 passed. The 11 new cases cover 8 returned-default regressions and 3 once-per-render cases. All 18 existing native cases remain.
  • After the final test-only layout-effect edit: full unit suite 422 passed in 35 files; 50 type tests, repository TypeScript, lint, formatting and whitespace checks passed.
  • Before that final test-only edit: 8 uncached build tasks and 13 E2E tests passed. The production source was unchanged between those checks and the final revision.
  • Lint has 95 warnings and 0 errors. Browser logs retain act-environment and legacy-JSX warnings; no unhandled errors were reported.

These checks used existing hash-matching locked dependencies, not a fresh frozen install. Exploratory render timings were mixed, so no speed improvement is claimed. The patch-level proposal does not publish a release.

Checklist

  • Documentation updated through the changeset.
  • Ready to be merged, subject to maintainer review.

AI assistance was used for source auditing, implementation, and test execution.

@changeset-bot

changeset-bot Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 0159115

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/core Patch
@react-spring/animated Patch
@react-spring/parallax Patch
@react-spring/rafz Patch
@react-spring/shared Patch
@react-spring/types Patch
@react-spring/three 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

@joshuaellis joshuaellis left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for picking this up, the fix itself is right (reading the defaults from the object the function returns) and the new tests fail on next without it 👍🏼

few things before merging, mostly around how it lands. i also don't think this needs to be a breaking change, see the changeset comments.

deps?: any[]
): any {
const propsFn = is.fun(props) && props
const p = propsFn ? propsFn() : props

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is now the sixth place we resolve the props function, and the two inner const ps further down shadow it. could we resolve it once here and use p everywhere? usePresence already does that. the other propsFn ? propsFn() : props calls are at 176, 220, 259 and 321

@@ -0,0 +1,9 @@
---
'@react-spring/core': major

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't think this is breaking. top-level config already applies when props is a function, so the only timing change is an explicit default: { config }, which the object form already honours. the handlers never fired, so nobody can depend on them not firing. can we make this a patch and drop the ! from the PR title?

'@react-spring/core': major
---

fix!: useTransition reads default props returned by a props function

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this reads more like PR notes than a changelog entry. one sentence on what now works is enough, something like "handlers and default props declared in a useTransition props function now apply, as they do in the object form"

@@ -0,0 +1,15 @@
# useTransition props-function defaults reproduction

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what runs this? nothing in the repo picks up tests/fixtures, so i'd rather not carry a page you have to run by hand. the unit tests are the regression guard

@@ -0,0 +1,76 @@
import * as React from 'react'

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can these live in useTransition.test.tsx? we keep one test file per module. also 15 of the 23 new tests pass on next without the fix, could we keep the ones that actually guard it?

@charan-rathore charan-rathore changed the title fix(core)!: read useTransition defaults from props functions fix(core): read useTransition defaults from props functions Nov 22, 2026
@charan-rathore

Copy link
Copy Markdown
Contributor Author

Thanks for the detailed review. Updated this to resolve the props function once and reuse the result throughout. The changeset is now patch-level, the title no longer marks a breaking change, and the changelog is one sentence.

The tests now live in useTransition.test.tsx. The eight returned-default cases fail on unchanged next; three additional cases fail on the previous PR source and check once-per-render resolution with empty, single-item and multi-item transitions. All 18 existing tests remain. The unused manual fixture and separate test files are removed.

The revised native file passes 29 tests. The full unit suite and type checks pass locally. Build and 13 E2E tests passed on the same production source before the last test-only layout-effect edit; unit, type, lint and format checks were rerun afterward. Existing lint and browser warnings remain. These are local checks, not a claim that upstream CI has run.

@joshuaellis
joshuaellis merged commit 59279bf into pmndrs:next Nov 23, 2026
15 checks passed
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]: callbacks are not called with imperative useTransition style

2 participants