fix(seo): warn when a domain setup has no locale to annotate as x-default - #4092
Conversation
…fault` `x-default` annotates the whole cluster of domains, so #4089 started resolving it from the configured `defaultLocale` rather than the current domain's own default. That option is optional under `multiDomainLocales` and the guide left it out, so those sites quietly stopped annotating a fallback at all. Leaving it out is still allowed, a cluster has no other way to name a fallback and `x-default` is optional, but it is no longer silent. The warning is logged where the alternate links are generated rather than at build time, a project that does not use the SEO features has nothing to annotate. The head test helper resolves both `defaultLocale`s the way the runtime does instead of taking them, which is what let the original bug through - it asserted the correct `x-default` while the code emitted one per domain.
WalkthroughAdds optional cluster-wide Estimated code review effort: 3 (Moderate) | ~20 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
test/routing-head.test.ts (1)
170-181: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winCover the warning side effect, not just the predicate.
This test only calls
missesClusterFallbackdirectly. Add a test that generates the head twice with a missing fallback, spies onconsole.warn, and asserts the development warning is emitted exactly once; this validates thewarnedClusterFallbackguard insrc/runtime/routing/head.ts:40-43.🤖 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 `@test/routing-head.test.ts` around lines 170 - 181, The existing test only validates the missesClusterFallback predicate; add coverage for the head-generation warning side effect. Generate the head twice using a context with a missing cluster fallback, spy on console.warn, and assert the development warning is emitted exactly once, exercising the warnedClusterFallback guard in the head-generation flow.
🤖 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.
Inline comments:
In `@docs/content/docs/02.guide/10.multi-domain-locales.md`:
- Around line 218-223: The defaultLocale documentation should qualify that the
missing-value warning is emitted only in development and when SEO alternate
links are generated for a multi-domain setup. Update the warning sentence in the
“defaultLocale and x-default” section while preserving the existing explanation
of optional configuration and x-default behavior.
---
Nitpick comments:
In `@test/routing-head.test.ts`:
- Around line 170-181: The existing test only validates the
missesClusterFallback predicate; add coverage for the head-generation warning
side effect. Generate the head twice using a context with a missing cluster
fallback, spy on console.warn, and assert the development warning is emitted
exactly once, exercising the warnedClusterFallback guard in the head-generation
flow.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: df6062dd-026a-4d41-9c97-840910ce7eb5
📒 Files selected for processing (3)
docs/content/docs/02.guide/10.multi-domain-locales.mdsrc/runtime/routing/head.tstest/routing-head.test.ts
|
|
||
| ## `defaultLocale` and `x-default` | ||
|
|
||
| The domains are annotated as one cluster, each page links to its alternates on the other domains. A cluster has a single fallback for unmatched languages, so the `x-default` alternate is taken from `defaultLocale` rather than from the locale a domain happens to default to - otherwise every domain would name a different one. | ||
|
|
||
| `defaultLocale` is optional here, since each domain resolves its own unprefixed locale through `defaultForDomains`. Leaving it out means no `x-default` is annotated at all, which is allowed but drops a signal for visitors whose language matches none of your locales. A warning is logged when it isn't set. |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Qualify when the warning is emitted.
The runtime only logs this warning in development and when SEO alternate links are being generated for a multi-domain setup. Please document those conditions to avoid implying that production always logs a warning whenever defaultLocale is omitted.
Proposed wording
- A warning is logged when it isn't set.
+ In development, a warning is logged when alternate links are generated without `defaultLocale`.📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| ## `defaultLocale` and `x-default` | |
| The domains are annotated as one cluster, each page links to its alternates on the other domains. A cluster has a single fallback for unmatched languages, so the `x-default` alternate is taken from `defaultLocale` rather than from the locale a domain happens to default to - otherwise every domain would name a different one. | |
| `defaultLocale` is optional here, since each domain resolves its own unprefixed locale through `defaultForDomains`. Leaving it out means no `x-default` is annotated at all, which is allowed but drops a signal for visitors whose language matches none of your locales. A warning is logged when it isn't set. | |
| ## `defaultLocale` and `x-default` | |
| The domains are annotated as one cluster, each page links to its alternates on the other domains. A cluster has a single fallback for unmatched languages, so the `x-default` alternate is taken from `defaultLocale` rather than from the locale a domain happens to default to - otherwise every domain would name a different one. | |
| `defaultLocale` is optional here, since each domain resolves its own unprefixed locale through `defaultForDomains`. Leaving it out means no `x-default` is annotated at all, which is allowed but drops a signal for visitors whose language matches none of your locales. In development, a warning is logged when alternate links are generated without `defaultLocale`. |
🤖 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 `@docs/content/docs/02.guide/10.multi-domain-locales.md` around lines 218 -
223, The defaultLocale documentation should qualify that the missing-value
warning is emitted only in development and when SEO alternate links are
generated for a multi-domain setup. Update the warning sentence in the
“defaultLocale and x-default” section while preserving the existing explanation
of optional configuration and x-default behavior.
x-defaulton every domain #4089x-defaultannotates a whole cluster of pages, and we deliberately cross-link the domains as one cluster, so #4089 started resolving it from the configureddefaultLocaleinstead of whichever locale the current domain defaults to — otherwise every domain declared a different fallback for the same cluster.defaultLocaleis optional undermultiDomainLocalesthough, since each domain resolves its own unprefixed locale throughdefaultForDomains, and the guide's example left it out. Those sites quietly stopped annotating a fallback at all. Leaving it out is still allowed,x-defaultis optional and a cluster has no other way to name a fallback, but it isn't silent any more and the guide covers it. The warning is logged where the alternate links are generated rather than at build time, since a project that doesn't use the SEO features has nothing to annotate.The head test helper was passing
routingOptions.defaultLocalestraight in rather than resolving it the waycreateComposableContextdoes, which is what let the original bug through — it asserted the correctx-defaultwhile the code emitted one per domain. It now derives it, and that alone makes the old wiring fail three of the domain tests.Summary by CodeRabbit
Documentation
defaultLocalein multi-domain locale setups.defaultLocalecontrolsx-defaultannotations and what happens when it is omitted.Bug Fixes
defaultLocaleis required but not configured.x-defaultlinks are omitted when no valid cluster fallback exists.Tests