feat: allow head route option to accept a static object#6950
feat: allow head route option to accept a static object#6950WolfieLeader wants to merge 6 commits intoTanStack:mainfrom
Conversation
Routes with static head content (e.g. favicon, charset, viewport meta) no longer need a function wrapper. The head option now accepts either a function or a plain object. Closes TanStack#6949
🦋 Changeset detectedLatest commit: f717225 The changes in this PR will be included in the next version bump. This PR includes changesets to release 27 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. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThe PR allows the Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 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 unit tests (beta)
📝 Coding Plan
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 |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/router-core/src/route.ts (1)
1386-1411: LGTM! Backwards-compatible union type for static head support.The type correctly allows both function and static object forms while maintaining the same shape. Existing function-based
headdefinitions continue to work.Consider extracting the duplicated object shape to a named type to reduce repetition:
♻️ Optional: Extract shared head content type
+type HeadContent = { + links?: AnyRouteMatch['links'] + scripts?: AnyRouteMatch['headScripts'] + meta?: AnyRouteMatch['meta'] + styles?: AnyRouteMatch['styles'] +} + head?: | (( ctx: AssetFnContextOptions< TRouteId, TFullPath, TParentRoute, TParams, TSearchValidator, TLoaderFn, TRouterContext, TRouteContextFn, TBeforeLoadFn, TLoaderDeps >, - ) => Awaitable<{ - links?: AnyRouteMatch['links'] - scripts?: AnyRouteMatch['headScripts'] - meta?: AnyRouteMatch['meta'] - styles?: AnyRouteMatch['styles'] - }>) - | { - links?: AnyRouteMatch['links'] - scripts?: AnyRouteMatch['headScripts'] - meta?: AnyRouteMatch['meta'] - styles?: AnyRouteMatch['styles'] - } + ) => Awaitable<HeadContent>) + | HeadContent🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/router-core/src/route.ts` around lines 1386 - 1411, The union type for the head property duplicates the object shape; extract that repeated shape into a named type (e.g., HeadContent) and replace the inline object in the union with that type and AssetFnContextOptions<...> returning Awaitable<HeadContent>; update references in this declaration (the head property, AssetFnContextOptions generic usage, and AnyRouteMatch usages) so the union becomes either (ctx => Awaitable<HeadContent>) | HeadContent to remove duplication and improve readability.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@packages/router-core/src/route.ts`:
- Around line 1386-1411: The union type for the head property duplicates the
object shape; extract that repeated shape into a named type (e.g., HeadContent)
and replace the inline object in the union with that type and
AssetFnContextOptions<...> returning Awaitable<HeadContent>; update references
in this declaration (the head property, AssetFnContextOptions generic usage, and
AnyRouteMatch usages) so the union becomes either (ctx =>
Awaitable<HeadContent>) | HeadContent to remove duplication and improve
readability.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: d62e5aab-f9e1-4b95-aaff-483530149f6f
📒 Files selected for processing (4)
packages/router-core/src/load-matches.tspackages/router-core/src/route.tspackages/router-core/src/ssr/ssr-client.tspackages/router-core/tests/load.test.ts
Bundle Size Benchmarks
Trend sparkline is historical gzip bytes ending with this PR measurement; lower is better. |
|
View your CI Pipeline Execution ↗ for commit 89d8cf1
☁️ Nx Cloud last updated this comment at |
|
@lachlancollins Thank's for the help! |
Summary
headroute option now accepts either a function or a plain static objectheadusage continues to work unchangedBefore:
After (also valid):
Closes #6949
Changes
packages/router-core/src/route.ts— Madeheadtype a union of function and static objectpackages/router-core/src/load-matches.ts— Addedtypeofcheck before callingheadpackages/router-core/src/ssr/ssr-client.ts— Sametypeofcheck in the SSR hydration pathpackages/router-core/tests/load.test.ts— Added tests for static object head and mixed hierarchyTest plan
headwith meta tags and linksheadon root + functionheadon childSummary by CodeRabbit