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

useLocale usage causes additional re-render #7344

Open
ohazda opened this issue Nov 8, 2024 · 0 comments
Open

useLocale usage causes additional re-render #7344

ohazda opened this issue Nov 8, 2024 · 0 comments

Comments

@ohazda
Copy link

ohazda commented Nov 8, 2024

Provide a general summary of the issue here

I am unsure whether I am doing something wrong or if some improvements could be made. I am using I18Provider with an explicitly set locale already determined by the server as it is described in the documentation.

As soon as I add useLocale to the component I can see an additional render, and here is where my confusion is. Why this rerender is happening?

🤔 Expected Behavior?

In my opinion, there should not be any additional re-render to the components that are using useLocale and there is a specified language already.

😯 Current Behavior

It causes rerender when using SSR. Possibly because the useDefaultLocale is using useIsSSR hook.

💁 Possible Solution

I think we should just skip the execution of this hook https://github.com/adobe/react-spectrum/blob/main/packages/%40react-aria/i18n/src/context.tsx#L31 if the locale is already provided. Otherwise, it still connects to the SSR Provider and triggers rerender.

🔦 Context

No response

🖥️ Steps to Reproduce

Very basic example: https://stackblitz.com/edit/stackblitz-starters-rxc7ky?file=app%2Fpage.tsx

Version

1.4.1 (react-spectrum-components)

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?

Any

🧢 Your Company/Team

No response

🕷 Tracking Issue

No response

@ohazda ohazda changed the title useLocale causes additional re-render useLocale usage causes additional re-render Nov 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 🩺 To Triage
Development

No branches or pull requests

1 participant