Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Link references the wrong locale, and all prefetch=true causes errors when using createNavigation. #1462

Closed
3 tasks done
varmil opened this issue Oct 24, 2024 · 1 comment · Fixed by #1463
Closed
3 tasks done
Labels
bug Something isn't working

Comments

@varmil
Copy link

varmil commented Oct 24, 2024

Description

OK

// routing.ts
export const { Link, getPathname, redirect, usePathname, useRouter } =
  createLocalizedPathnamesNavigation({
    locales: routing.locales,
    pathnames: { '/': '/' }
  })

---

// component.tsx
<Link href={`/${group}/channels/${basicInfo.id}`} prefetch={true}>
  ...
</Link>

NG

// routing.ts
export const { Link, getPathname, redirect, usePathname, useRouter } =
  createNavigation(routing)

---

// component.tsx
<Link href={`/${group}/channels/${basicInfo.id}`} prefetch={true}>
  ...
</Link>

Error Message

The `prefetch` prop is currently not supported when using the `locale` prop on `Link` to switch the locale.`

Hypothesis after code reading

Hypothesis after reading the code

When using createLocalizedPathnamesNavigation, the locale is ultimately set here. The same is true for the Client.

const finalLocale = locale || (await getLocale());

On the other hand, when using createNavigation, it appears that isChangingLocale is checked here without calculating finalLocale.

As a result, locale in createNavigation is probably undefined and isChangingLocale is always true.

versions

This is the version in which the bug was confirmed to occur.

"next-intl": "^3.23.3",
"next": "15.0.1",

Verifications

Mandatory reproduction URL

https://github.com/varmil/noxi/pull/626/files#diff-ee810f949a204706e7360b0af570aea479f0efb7103a3abaaceb8c0acfb8c9bdL5-R5

Reproduction description

Steps to reproduce:

  1. Clone the repo
  2. npm run dev in ./web dir. Go browser.
  3. See error on browser and server

Expected behaviour

Since I don't use a locale prop, we expect prefetch to proceed without error.

@varmil varmil added bug Something isn't working unconfirmed Needs triage. labels Oct 24, 2024
@amannn
Copy link
Owner

amannn commented Oct 24, 2024

Oh you're absolutely right, thanks for the bug report and the great analysis! Should have a fix ready soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants