Repository navigation
perf(react-router): render createLink components in one layer - #9013
schiller-manuel wants to merge 1 commit into
Conversation
createLink returned a forwardRef component that rendered a memoized Link
with a props copy and an internal `_asChild` host, so every custom Link
paid an extra component and a spread. createLink now returns the
memoized Link implementation with its host bound directly, and Link is
createLink('a').
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
🦋 Changeset detectedLatest commit: f651b05 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 |
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
View your CI Pipeline Execution ↗ for commit f651b05
💡 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 Preview1 package(s) bumped directly, 4 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. |
Merging this PR will regress 1 benchmark2 warnings, 1 note
Warning Please fix the performance issues or acknowledge them on CodSpeed. Performance Changes
Tip Investigate this regression by commenting Comparing Footnotes
|
Agent assessment
Self-reported assessment, not an independent review.
Assessed revision:
f651b053948ade7a7022c41d08c8a3e09486b7bftest:unit,test:types,test:eslint,test:buildpass locally.↑
Linkis nowcreateLink('a'), so every existingLinktest (refs, memo, SSR, state props) runs the created-link path;link-memo.test.tsxalready drives memo bail-out throughcreateLink(Host).↑
_asChildwas only ever passed throughas anycasts; never typed or documented.↓ Local instruction counts are bimodal, so the create-link gain ranges from -3% to -10% by run mode; CodSpeed results not yet observed.
↓ No React e2e app uses
createLink.🎯 Changes
Stacked on #9010 (adds the
create-linkbenchmark this PR is measured with).createLink(Comp)used to wrapLink:That's 3 fibers per custom link (ForwardRef → Memo → ForwardRef) plus a props copy. Now
createLinkreturns the memoized implementation with the host bound directly, andLinkiscreateLink('a'):Custom links drop to 2 fibers, same as
Link. The internal_asChildprop goes away (also dropped fromROUTER_OPTION_KEYS). Memo now compares the user's props directly instead of the copy plus_asChild, so bail-out behavior is unchanged. In React DevTools, custom links now show up as the same anonymousMemoasLinkinstead ofForwardRef(CreatedLink)>Memo.Benchmarks (React, local, baseline = #9010 head)
Instructions retired per lap (macOS
/usr/bin/time -l, 300 laps minus setup-only runs, interleaved, 8 runs per side):Run totals cluster in two modes, so treat create-link as roughly -3% to -10%. A separate tighter run measured -3.4% with a same-commit spread of 0.8%. Every create-link candidate run except one beat every baseline run. link-mount's minimums match, as expected:
Linkkeeps the same Memo → ForwardRef structure.Walltime
vitest bench, 4 interleaved runs per side: create-link median 232 → 258 hz (best 254.8 → 263.4 hz). link-mount moved both ways within ±3% rme (best 323 vs 303 hz) on a noisy machine.Bundle size
Full
benchmark:bundle-size:run, gzip: every scenario ≤ 0.Attribution: keeping
areLinkPropsEqualbelowLinkcosts +10 B on react-router.minimal. Keeping_asChildinROUTER_OPTION_KEYScosts up to +8 B. Afunction createLinkdeclaration costs +11 B on react-start.minimal.Overlap with #9005
#9005 (
perf(react-router): avoid Link's props copy and no-op preload handlers) touches the same render function. Rebasing onto it conflicts in one hunk oflink.tsx: keep this PR'screateLinkbody and take #9005'slinkProps.children = ...; return jsx(Comp, linkProps)render tail.Follow-ups (not changed here)
route.tsx:RouteApi.Link,Route.Linkand the root route'sLinkare stillforwardRef((props, ref) => <Link ref={ref} from={...} {...props} />), the same extra layer plus a spread.createLinkare unchanged; both still wrapLinkwith_asChild.AI-authored (GitHub Copilot), reviewed by me.
✅ Checklist
Validation:
CI=1 NX_DAEMON=false pnpm nx run-many -p @tanstack/react-router -t test:unit,test:types,test:eslint,test:build --skipRemoteCache: passedpnpm benchmark:bundle-size:run(full, baseline vs this PR): passed, gzip ≤ 0 everywhere🚀 Release Impact
Summary by CodeRabbit
createLinknow render consistently with standard links, including conditional children that reflect whether a link is active.