Repository navigation
fix(core): read useTransition defaults from props functions - #2660
Conversation
🦋 Changeset detectedLatest commit: 0159115 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 |
joshuaellis
left a comment
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 | |||
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 | |||
There was a problem hiding this comment.
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' | |||
There was a problem hiding this comment.
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?
|
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 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. |
Why
Handlers and explicit default props returned by a
useTransitionprops 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.tsxand 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:
useTransitiontests: unchangednext18 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.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
AI assistance was used for source auditing, implementation, and test execution.