Skip to content

fix(Link): prevent double-prefixing with @nuxtjs/i18n auto-localization#6404

Merged
benjamincanac merged 2 commits into
v4from
pr/6400
Apr 27, 2026
Merged

fix(Link): prevent double-prefixing with @nuxtjs/i18n auto-localization#6404
benjamincanac merged 2 commits into
v4from
pr/6400

Conversation

@benjamincanac

Copy link
Copy Markdown
Member

🔗 Linked issue

Resolves #6400

❓ Type of change

  • 📖 Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • 👌 Enhancement (improving an existing functionality)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

📚 Description

📝 Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@github-actions github-actions Bot added the v4 #4488 label Apr 27, 2026
@coderabbitai

coderabbitai Bot commented Apr 27, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 37c38400-c491-48f1-87db-686aed098c86

📥 Commits

Reviewing files that changed from the base of the PR and between b8c8be9 and 95cb6a5.

📒 Files selected for processing (1)
  • src/runtime/components/Link.vue
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/runtime/components/Link.vue

📝 Walkthrough

Walkthrough

Adds a locale prop to the Link component (boolean | string) to control i18n auto-localization: false leaves string to/href paths untouched; true/undefined uses Nuxt i18n $localePath; a string value is passed to $localePath. Implements detection of existing locale prefixes using nuxtApp.$i18n.localeCodes to avoid double-prefixing. Omits locale from forwarded Nuxt link props and updates LinkPropsKeys and the linkKeys array in utils so locale is included in prop picking/omission behavior.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main fix: preventing double-prefixing with i18n auto-localization, matching the core issue resolved.
Description check ✅ Passed The description is related to the changeset, linking issue #6400 and marking it as a bug fix, though lacking detailed explanation of implementation approach.
Linked Issues check ✅ Passed The PR addresses the core requirement from issue #6400 by adding a locale prop to control i18n auto-localization and implementing locale-prefix detection to prevent double-prefixing.
Out of Scope Changes check ✅ Passed All changes are directly scoped to the linked issue: adding locale prop to Link component and updating related utilities for locale prefix handling.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch pr/6400

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/runtime/components/Link.vue (1)

87-95: Add an explicit @defaultValue for locale and align with runtime defaulting.

Line 89 describes default behavior, but the new prop is missing a formal @defaultValue tag 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 | string
 const 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 @defaultValue for 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

📥 Commits

Reviewing files that changed from the base of the PR and between e3cdbc5 and b8c8be9.

📒 Files selected for processing (2)
  • src/runtime/components/Link.vue
  • src/runtime/utils/link.ts

Comment thread src/runtime/components/Link.vue
@pkg-pr-new

pkg-pr-new Bot commented Apr 27, 2026

Copy link
Copy Markdown
npm i https://pkg.pr.new/@nuxt/ui@6404

commit: 95cb6a5

@benjamincanac
benjamincanac merged commit dde09d0 into v4 Apr 27, 2026
24 checks passed
@benjamincanac
benjamincanac deleted the pr/6400 branch April 27, 2026 19:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

v4 #4488

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Documentation] [Link] Way to bypass automatic locale link

1 participant