refactor(react-router): Reduce bundle size by sharing hook structuralSharing logic#7577
refactor(react-router): Reduce bundle size by sharing hook structuralSharing logic#7577Sheraff wants to merge 1 commit into
Conversation
📝 WalkthroughWalkthroughThis PR consolidates duplicated structural-sharing logic across four React Router hooks ( ChangesStructural Sharing Refactoring
Estimated Code Review Effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly Related PRs
Suggested Labels
Suggested Reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
|
View your CI Pipeline Execution ↗ for commit a1d2860
💡 Verify your cache is correct by running tasks in a sandbox. 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
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. |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/react-router/src/useMatch.tsx (1)
30-67: MakeuseStructuralSharingtruly internal
useStructuralSharingis exported frompackages/react-router/src/useMatch.tsx, but it’s not re-exported from the public entrypoint (packages/react-router/src/index.tsx), andpackages/react-router/package.jsononly exposes.and./ssr/*. If it’s only for intra-package reuse, consider making it non-exported (or moving it to a private helper module) to avoid implying a public API surface.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/react-router/src/useMatch.tsx` around lines 30 - 67, The function useStructuralSharing is currently exported from useMatch.tsx but is intended as an internal helper; remove the export (make it a module-private function) or move it into a private helper file and update internal imports so it is not part of the package public surface (adjust any internal references to useStructuralSharing accordingly and ensure the symbol is no longer exported from the package entrypoint).
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@packages/react-router/src/useMatch.tsx`:
- Around line 30-67: The function useStructuralSharing is currently exported
from useMatch.tsx but is intended as an internal helper; remove the export (make
it a module-private function) or move it into a private helper file and update
internal imports so it is not part of the package public surface (adjust any
internal references to useStructuralSharing accordingly and ensure the symbol is
no longer exported from the package entrypoint).
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: f0782a0b-f3d0-498c-ae83-a3d7c64459d3
📒 Files selected for processing (5)
.changeset/silent-ghosts-sit.mdpackages/react-router/src/Matches.tsxpackages/react-router/src/useLocation.tsxpackages/react-router/src/useMatch.tsxpackages/react-router/src/useRouterState.tsx
There was a problem hiding this comment.
Important
At least one additional CI pipeline execution has run since the conclusion below was written and it may no longer be applicable.
Nx Cloud has identified a possible root cause for your failed CI:
We determined this failure is unrelated to the PR changes, which only refactor structural sharing logic within @tanstack/react-router hooks. The error originates in a compiled artifact of e2e-utils (dist/esm/users.js missing a named export), a package untouched by this PR. Our classification is environment_state — the e2e-utils dist files need to be rebuilt in the environment.
No code changes were suggested for this issue.
Trigger a rerun:
🎓 Learn more about Self-Healing CI on nx.dev
Merging this PR will improve performance by 5.9%
|
| Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|
| ⚡ | ssr request loop (vue) |
481.7 ms | 454.9 ms | +5.9% |
Tip
Curious why this is faster? Comment @codspeedbot explain why this is faster on this PR, or directly use the CodSpeed MCP with your agent.
Comparing refactor-react-router-hook-selector-bundle-size (a1d2860) with main (4a93cff)
Footnotes
-
1 benchmark was skipped, so the baseline result was used instead. If it was deleted from the codebase, click here and archive it to remove it from the performance reports. ↩
Summary by CodeRabbit
@tanstack/react-routerby consolidating structural sharing logic across routing hooks, eliminating code duplication and improving package efficiency while maintaining full backward compatibility and identical user-facing functionality.