Repository navigation
Conversation
…e context When beforeLoad returns null, treat it the same as undefined (no-op) instead of storing it as __beforeLoadContext: null. This is consistent with how the context route option already handles null returns via ?? undefined, and prevents null from silently interfering with context accumulation. Closes TanStack#7110
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughThis pull request fixes route context handling in TanStack Router by treating Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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 |
|
View your CI Pipeline Execution ↗ for commit ee99b33
☁️ Nx Cloud last updated this comment at |
Bundle Size Benchmarks
Trend sparkline is historical gzip bytes ending with this PR measurement; lower is better. |
More templates
@tanstack/arktype-adapter
@tanstack/eslint-plugin-router
@tanstack/history
@tanstack/nitro-v2-vite-plugin
@tanstack/react-router
@tanstack/react-router-devtools
@tanstack/react-router-ssr-query
@tanstack/react-start
@tanstack/react-start-client
@tanstack/react-start-server
@tanstack/router-cli
@tanstack/router-core
@tanstack/router-devtools
@tanstack/router-devtools-core
@tanstack/router-generator
@tanstack/router-plugin
@tanstack/router-ssr-query-core
@tanstack/router-utils
@tanstack/router-vite-plugin
@tanstack/solid-router
@tanstack/solid-router-devtools
@tanstack/solid-router-ssr-query
@tanstack/solid-start
@tanstack/solid-start-client
@tanstack/solid-start-server
@tanstack/start-client-core
@tanstack/start-fn-stubs
@tanstack/start-plugin-core
@tanstack/start-server-core
@tanstack/start-static-server-functions
@tanstack/start-storage-context
@tanstack/valibot-adapter
@tanstack/virtual-file-routes
@tanstack/vue-router
@tanstack/vue-router-devtools
@tanstack/vue-router-ssr-query
@tanstack/vue-start
@tanstack/vue-start-client
@tanstack/vue-start-server
@tanstack/zod-adapter
commit: |
…k, fix pendingMs-0 blank frame Issue sweep across open issues/PRs overlapping this branch's scope. Each issue got a repro test asserting the desired behavior: - Fixed by this work (tests pass): #7602, #7457, #7367, #7635, #4684, #6221, #7379, #4696, #4444, #6107, #5106, #7638, #4572, #3179, #4112, #2980, #2905, #2182, #3928, #6371 — plus test ports pinning the intent of external PRs #7003, #7051, #6645, #7114 (via #7110 repro) and #4614. - Fixed here: #4759 — a pendingMs-0 pending publication deferred to a macrotask painted one blank frame on bare initial loads; publication is now synchronous when nothing is rendered yet (the timer path stays for displayed content, whose later snapshot is fresher). - Known gap kept as an expected failure: #5778 — preloads borrowing an active ancestor derive context from its committed snapshot, not live router.options.context; fixing means changing the read-only borrow protocol (dedicated follow-up). The documented invalidate() workaround is pinned. Co-Authored-By: Claude Fable 5 <[email protected]>
|
Closing as obsolete: the loader was rewritten in #7805 and load-matches.ts no longer exists, so this change no longer applies. |
Summary
When
beforeLoadreturnsnull, it is now treated the same asundefined(no-op) instead of being stored as__beforeLoadContext: null.Problem
When a route's
beforeLoadfunction returnsnull(e.g. from a server function),useRouteContext()returns an empty object{}instead of preserving the parent context. This happens because:nullis stored as__beforeLoadContext: nullObject.assign(context, ..., null)or{...parentContext, ...null}, null is silently ignoredMeanwhile, the
contextroute option already handles this correctly withroute.options.context(contextFnContext) ?? undefined.Fix
In
updateContextwithinload-matches.ts, treatnullthe same asundefined— skip storing it as__beforeLoadContext. This makesbeforeLoadconsistent with thecontextoption behavior.Tests
Added two tests to
routeContext.test.tsx:route context preserved when beforeLoad returns null(sync)route context preserved when async beforeLoad returns null(async)Both verify that parent context (
{ foo: 'bar' }) is preserved whenbeforeLoadreturnsnull.Closes #7110
Summary by CodeRabbit
beforeLoadhook returnsnull. Null values are now treated as no-op, aligning with standard context behavior.