feat(react-router): allow pendingComponent: false to opt out of the default pending fallback - #8093
Conversation
…efault pending fallback Fixes TanStack#7773. Mirrors the existing errorComponent?: false | null | undefined | ErrorRouteComponent pattern. false survives the ?? fallback chain in Match.tsx and load-client.ts (only null/undefined are nullish), so the runtime already treats it as "render nothing" -- this widens the type to allow passing it.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
Included review availability: Your plan includes up to 10 reviews per rolling hour; 9 remain after this review. 📝 WalkthroughWalkthroughThe route option contract and documentation now support explicit pending-component opt-out values. Tests verify that ChangesPending component opt-out
Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk: ⚪ Minimal · up to This localized change allows routes to opt out of the default pending fallback while preserving normal fallback inheritance for other routes; no actionable merge-blocking risk remains beyond normal checks and review. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Updates the RouteOptions API reference for TanStack#7773 -- false now opts a route out of routerOptions.defaultPendingComponent entirely.
37f9414 to
8faea26
Compare
| render(<RouterProvider router={router} />) | ||
|
|
||
| await act(async () => { | ||
| await vi.advanceTimersByTimeAsync(0) |
There was a problem hiding this comment.
advancing by 0? does that do anything? same below
There was a problem hiding this comment.
You're right, advancing by 0ms doesn't do anything, that was missed before. Thanks for flagging it, fixed now in 5c44c9a.
…mponent test The opt-out case never schedules a pending timer (pendingComponent: false short-circuits before pendingMs/pendingMinMs come into play), so it doesn't need fake timers at all. The default-inheritance case only needs fake timers to cross the pendingMinMs boundary, tightened to a 99ms/+1ms check.
Description
Fixes #7773.
Adds a way to opt a route out of the router-wide default pending fallback entirely, using the same convention
errorComponentalready ships with:Why this is a one-line, logic-free change
Both
pendingComponentanderrorComponentare read through the same?? defaultpattern, and??only falls through onnull/undefined—falseis not nullish, so it survives.Match.tsx#renderPending(render):route?.options.pendingComponent ?? router.options.defaultPendingComponent, thenif (!PendingComponent) return null.load-client.ts(pending-status timing calc): same??, thenif (!component ...) return.false ?? defaultstaysfalse, and the subsequent truthy checks already treat falsy as "nothing to render" — same aserrorComponent'srouteErrorComponent ? CatchBoundary : SafeFragment. So the runtime already does the right thing withfalse; it's only blocked by the type today. No changes needed in either file, confirmed by tracing every reference to.pendingComponentin the React path.Test plan
Added
packages/react-router/tests/issue-7773-pending-component-opt-out.test.tsx:pendingComponent: falsenever shows the router-widedefaultPendingComponent, even withdefaultPendingMs: 0, and still renders its real content once the loader resolves.Ran together with the existing pending/error-boundary suites — 64/64 passing, no regressions.
test:types(tsc onsrc) — cleaneslinton changed files — cleanprettier --check— cleanvitest runon the new + related pending/error test files — 64/64 passStatus
Opening as a draft — proposed this approach on #7773 and haven't gotten maintainer sign-off yet, since it's technically an API surface change per CONTRIBUTING.md. Marking draft rather than requesting review until that lands.
AI assistance
Used AI to help trace the
??/fallback-chain call sites and draft the diff and test. Reviewed and verified the control-flow claims myself and can walk through the reasoning in review.Summary by CodeRabbit
New Features
pendingComponenttofalse.Documentation