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

I18nProvider breaks client hydration in TanStack Start #7474

Open
justblender opened this issue Dec 4, 2024 · 1 comment
Open

I18nProvider breaks client hydration in TanStack Start #7474

justblender opened this issue Dec 4, 2024 · 1 comment

Comments

@justblender
Copy link

Provide a general summary of the issue here

TanStack Start utilizes server-side rendering (SSR), which requires wrapping the application with I18nProvider to ensure that the locale of the content rendered on the server matches the locale expected by the browser. This requirement is outlined in the documentation guide.

However, there appears to be an issue with the I18nProvider when used within this framework, as it is causing hydration errors.

🤔 Expected Behavior?

Hydration should work flawlessly.

😯 Current Behavior

Hydration breaks when the application is wrapped with I18nProvider and causes the entire page to go blank for a split second as it switches to client rendering.

React warning:

Error: This Suspense boundary received an update before it finished hydrating. This caused the boundary to switch to client rendering. The usual way to fix this is to wrap the original update in startTransition.

💁 Possible Solution

From what I've gathered, useDefaultLocale() hook seems to be the culprit here.

export function I18nProvider(props: I18nProviderProps) {
let {locale, children} = props;
let defaultLocale = useDefaultLocale();

useEffect(() => {
if (listeners.size === 0) {
window.addEventListener('languagechange', updateLocale);
}
listeners.add(setDefaultLocale);
return () => {
listeners.delete(setDefaultLocale);
if (listeners.size === 0) {
window.removeEventListener('languagechange', updateLocale);
}
};
}, []);

Perhaps we should update the state (line 70) using startTransition? Not sure, I'm not very Suspense-pilled.

🔦 Context

No response

🖥️ Steps to Reproduce

https://stackblitz.com/edit/tanstack-router-ugkb9t?file=app%2Froutes%2F__root.tsx

Omitting I18nProvider gets rid of the above-mentioned React warning in the console logs.

Version

1.5.0

What browsers are you seeing the problem on?

Firefox, Chrome, Safari, Microsoft Edge

If other, please specify.

No response

What operating system are you using?

macOS 15.1

🧢 Your Company/Team

No response

🕷 Tracking Issue

No response

@herkulano
Copy link

This is likely related to #7344

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants