fix(Link): prevent double-prefixing with @nuxtjs/i18n auto-localization#6404
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdds a Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/runtime/components/Link.vue (1)
87-95: Add an explicit@defaultValueforlocaleand align with runtime defaulting.Line 89 describes default behavior, but the new prop is missing a formal
@defaultValuetag and explicit runtime default alignment.💡 Suggested update
/** * Control i18n auto-localization when `@nuxtjs/i18n` is installed. + * `@defaultValue` true * - `undefined` / `true` (default): auto-localizes to the current locale using `$localePath`. * Paths already carrying a locale prefix (from e.g. `switchLocalePath()`) are detected * and left untouched to prevent double-prefixing. * - `false`: explicitly disables auto-localization. * - `string`: localizes to a specific locale (e.g. `'fr'`). */ locale?: boolean | stringconst props = withDefaults(defineProps<LinkProps>(), { as: 'button', type: 'button', ariaCurrentValue: 'page', - active: undefined + active: undefined, + locale: true })As per coding guidelines: Use
withDefaults()for runtime prop defaults and JSDoc@defaultValuefor documentation.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/runtime/components/Link.vue` around lines 87 - 95, Add an explicit JSDoc `@defaultValue` for the locale prop and ensure the runtime prop default matches it: update the locale prop JSDoc in Link.vue to include "@defaultValue undefined" (or "@defaultValue true" if you prefer documenting behavior as auto-localize) and set the runtime default using withDefaults around defineProps (e.g., withDefaults(defineProps<{ locale?: boolean | string }>(), { locale: undefined })) so the documented default and actual runtime default for the locale prop are aligned.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/runtime/components/Link.vue`:
- Around line 177-182: The existing localized-check in the Link component (using
i18n, localeCodes, path and localePath) fails to recognize localized paths that
include query or hash fragments (e.g. "/fr?x=1" or "/fr#top"), causing
double-prefixing; update the condition that currently tests path === `/${code}`
or path.startsWith(`/${code}/`) to also treat paths starting with `/${code}?` or
`/${code}#` as already localized (or use a single regex like
^/${code}(?:$|[/?#])) so the function returns the original path when matched,
otherwise fall back to calling localePath(path, props.locale).
---
Nitpick comments:
In `@src/runtime/components/Link.vue`:
- Around line 87-95: Add an explicit JSDoc `@defaultValue` for the locale prop and
ensure the runtime prop default matches it: update the locale prop JSDoc in
Link.vue to include "@defaultValue undefined" (or "@defaultValue true" if you
prefer documenting behavior as auto-localize) and set the runtime default using
withDefaults around defineProps (e.g., withDefaults(defineProps<{ locale?:
boolean | string }>(), { locale: undefined })) so the documented default and
actual runtime default for the locale prop are aligned.
🪄 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: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 81f03424-e384-4a64-af12-1d8082fbc1ae
📒 Files selected for processing (2)
src/runtime/components/Link.vuesrc/runtime/utils/link.ts
commit: |
🔗 Linked issue
Resolves #6400
❓ Type of change
📚 Description
📝 Checklist