Allow localization of query parameters via useSetI18nParams#3869
Allow localization of query parameters via useSetI18nParams#3869Tofandel wants to merge 2 commits into
Conversation
WalkthroughThe diff changes locale switching to compute localized dynamic params and split them into params and query, then merge those into route.params and route.query respectively. switchLocalePath now conditionally clears the route hash when SSR hydration is active. A new composable API, isHydratingSSR, exposes the SSR hydration state. A minor type annotation was added in domainFromLocale. Tests and fixtures were updated: added test helpers to override localized params, an isHydratingSSR test hook, translated-query navigation in fixtures, and console interception/assertions to ensure no hydration warnings. Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes
Pre-merge checks and finishing touches✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (5)
🚧 Files skipped from review as they are similar to previous changes (5)
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 |
| expect(await page.locator('#switch-locale-path .en').innerText()).toEqual('/en/about#foo=bar') | ||
|
|
||
| // We don't force a rerender on mounted, so the hash will not be present for switchLocale | ||
| expect(await page.locator('#switch-locale-path .ja').innerText()).toEqual('/ja/about') |
There was a problem hiding this comment.
I modified this test because the current behavior would have logged this in the console
[Vue warn]: Hydration attribute mismatch on <a href="/hu/termek-kategoria/nappali/" class title="Magyar">HU</a>
- rendered on server: href="/hu/termek-kategoria/nappali/"
- expected on client: href="/hu/termek-kategoria/nappali/#quote"
Note: this mismatch is check-only. The DOM will not be rectified in production due to performance overhead.
You should fix the source of the mismatch.
Hydration completed but contains mismatches.
Meaning in a production build, the dom would not have been corrected like on the playwright test and an error about hydration mismatch would have been logged.
There is sadly not much that we can do about this unless we change the return of switchLocalePath to a computed so that we can update it once the hydration is done. (Which would be a breaking change)
🔗 Linked issue
#3377
📚 Description
Since we know which params and query args are available on a route we are already on, we can split them correctly between params and query without additional changes to setI18nParams
Also prevents the hash being included in switchLocalePath if the app is being hydrated from SSR (because the hash is never sent to the server and would be missing from the SSR, causing hydration mismatch)
Summary by CodeRabbit
Bug Fixes
New Features
Tests