Repository navigation
perf(react-router): avoid Link's props copy and no-op preload handlers - #9005
Conversation
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
🦋 Changeset detectedLatest commit: c53dd28 The changes in this PR will be included in the next version bump. This PR includes changesets to release 5 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 |
|
View your CI Pipeline Execution ↗ for commit c53dd28
💡 With Ultracache enabled, Nx Cloud learns each task's file inputs in CI and uses them on later runs. Turn on Ultracache in workspace settings ↗ · Read docs ↗ ☁️ Nx Cloud last updated this comment at |
🚀 Changeset Version Preview2 package(s) bumped directly, 21 bumped as dependents. 🟩 Patch bumps
|
Bundle Size Benchmarks
The following scenarios have bundle-size changes compared with the baseline:
Current gzip tracks all emitted client JS chunks. Initial gzip tracks only the entry/import graph. Trend sparkline is historical current gzip ending with this PR measurement; lower is better. |
Link renders through react/jsx-runtime's jsx, so React 19 uses its fresh props object for the element instead of copying it. Focus, hover and touch handlers are attached only for intent preloading; in other modes they were no-ops, and the element's own handlers pass through unchanged. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
77b7102 to
48e72ff
Compare
Merging this PR will regress 1 benchmark2 warnings
Warning Please fix the performance issues or acknowledge them on CodSpeed. Performance Changes
Tip Investigate this regression by commenting Comparing Footnotes
|
…ith jsx Document why Link calls jsx() directly: compiled JSX copies the spread props. Pin that non-intent Links attach element handlers as given, that a state-prop key stays the element key, and that React 19's jsx resolves defaultProps only for class hosts. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Agent assessment
Self-reported assessment, not an independent review.
Assessed revision:
c53dd283c40ae2b1b19fd3c447739a9ff57c627btest:unit,test:typesandtest:eslintpass at this revision.↑ Tests pin each behavior change: element handlers in every preload mode, already-prevented events with and without intent, a
keyin state props, anddefaultPropsfor function and class hosts. The handler anddefaultPropstests fail on the base, as intended.↑ The package build compiles
<Host {...linkProps} />tojsx(Host, { ...linkProps }), a copy, which justifies the directjsx()call.↑ React e2e apps with intent preloading (
basic-file-based,basic-file-based-code-splitting) passed at 77b7102; not rerun since, because later changes touch only tests and comments.↓ Calling
jsxdirectly is compiler-facing rather than documented public API.↓ Three user-visible behavior changes, listed in the PR body.
↓ Benchmark numbers are local wall-clock runs; CodSpeed CI results aren't inspected yet.
Stacked on #9003 (router-core static location slot). Base this review on that branch; it should land first.
🎯 Changes
Two React-only per-Link render savings:
Linkcallsjsxfromreact/jsx-runtimedirectly and puts its children intolinkProps. React 19'sjsxuses a key-less config object as the element's props instead of copying it (facebook/react#28768). React 18 still copies, so it is neutral there. Plain JSX can't do this: this package's build (Vite 8, oxc automatic runtime) compiles<Host {...linkProps} />tojsx(Host, { ...linkProps }), which copies. The direct call relies on the same invariant the compiler guarantees:linkPropsis fresh per render, never cached, and never mutated after the call. Development builds freezeelement.props.onBlur,onFocus,onMouseEnter,onMouseLeaveandonTouchStartare composed only forpreload === 'intent'. In every other mode they did nothing, so the element's own handlers now pass through as given. The handlers no longer re-check the mode, andenqueuePreloadno longer depends onpreload.Behavior changes, each pinned by a test:
onFocus,onBlur,onMouseEnter,onMouseLeaveandonTouchStartare attached as given. They now run even whenevent.defaultPreventedis already true, as on a plain<a>. Previously,composeHandlersskipped them. Intent Links still skip them.defaultPropson custom hosts: React 19'sjsxappliesdefaultPropsonly to class components. A function component passed tocreateLinkno longer gets itsdefaultProps;createElementused to apply them. This matches React 19 JSX everywhere else. Use default parameters instead.keyin state props: akeyinactiveProps/inactivePropsis still the element's key, not a prop. React's development build now logs its "key spread into JSX" warning for it.Client-nav benchmarks
Local
vitest bench(jsdom, production builds), 6 interleaved base/candidate rounds on the same machine. Means are medians across rounds. Solid and Vue builds are byte-identical, so they are the noise controls.link-churn(React)link-mount(React,defaultPreload: false)link-mountintent (React)link-mount(Solid, control)link-mountintent (Solid, control)link-mount(Vue, control)link-mountintent (Vue, control)The controls show about ±4% same-code noise.
link-churnimproved in 5 of 6 rounds andlink-mount(React) in 5 of 6. The intent variant is within noise. Baseline is this PR's base branch.Bundle size
Full
benchmark:bundle-sizerun against the base branch (gzip bytes).react-router.minimalwas re-measured after rebasing onto #9003's latest head; the other rows are from the previous base:✅ Checklist
Validation:
pnpm nx run-many -p @tanstack/react-router -t test:unit test:types test:eslint: passedpnpm nx run-many -p tanstack-router-e2e-react-basic-file-based tanstack-router-e2e-react-basic-file-based-code-splitting -t test:e2e: passedpnpm benchmark:bundle-size:run --baseline <base>(all scenarios): no growth, React −15 to −39 B gzip🚀 Release Impact
AI-assisted: written with GitHub Copilot.
Summary by CodeRabbit
defaultProps.