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

The PAGE CRASHES when you add I18nProviderClient and write in input control #290

Closed
JuanPabloLira opened this issue Nov 15, 2023 · 8 comments · Fixed by #316
Closed

The PAGE CRASHES when you add I18nProviderClient and write in input control #290

JuanPabloLira opened this issue Nov 15, 2023 · 8 comments · Fixed by #316
Labels
bug Something isn't working

Comments

@JuanPabloLira
Copy link

JuanPabloLira commented Nov 15, 2023

Describe the bug
When you interact with an input in a client component wrapped by an I18nProviderClient before the dictionary has finished loading, the page crashes

To Reproduce
Steps to reproduce the behavior:
Use the project in codesandbox that provides the documentation, add an input control in the client component

https://codesandbox.io/p/sandbox/jovial-paper-skkprk?file=%2Fapp%2F%5Blocale%5D%2Fpage.tsx%3A1%2C1

1.- add <input autoFocus /> to the client component
2.- Reload the page and write immediately

Expected behavior
the page should not crash.

Screenshots
image

About (please complete the following information):

  • next-international version 1.1.3
  • Next.js version 14 and 13.5

Additional context
If you wait for the dictionary to finish loading completely, everything works perfectly.

@JuanPabloLira JuanPabloLira added the bug Something isn't working label Nov 15, 2023
@JuanPabloLira JuanPabloLira changed the title The page crashes when you add I18nProviderClient and write in input control The PAGE CRASHES when you add I18nProviderClient and write in input control Nov 15, 2023
@QuiiBz
Copy link
Owner

QuiiBz commented Nov 16, 2023

🤯 I have no idea where this is coming from. Might not even be related to next-international, but Next.js / React itself?

@JuanPabloLira
Copy link
Author

I think that if it has to do with next-international, if you do not wrap the components with the I18nProviderClient the page will not crash 😢

@Yovach
Copy link
Contributor

Yovach commented Nov 16, 2023

Even it's not great, you can use :

    {
      en: async () => {
        await new Promise(resolve => setTimeout(resolve, 100));
        return import('./en');
      },
      fr: async () => {
        await new Promise(resolve => setTimeout(resolve, 100));
        return import('./fr');
      },
    },

in locales/client.ts

@JuanPabloLira
Copy link
Author

Even it's not great, you can use :

    {
      en: async () => {
        await new Promise(resolve => setTimeout(resolve, 100));
        return import('./en');
      },
      fr: async () => {
        await new Promise(resolve => setTimeout(resolve, 100));
        return import('./fr');
      },
    },

in locales/client.ts

This change works to not block the page, but the javascript that loads later is blocked

@Yovach
Copy link
Contributor

Yovach commented Nov 16, 2023

The use hook seems to crash the browser (cf. https://github.com/QuiiBz/next-international/blob/main/packages/next-international/src/app/client/create-i18n-provider-client.tsx#L35) if we interact with the page before the locale is loaded

I tried to remove it and use it in a useMemo hook to call but I've an error despite this (from the React doc, https://react.dev/reference/react/use#caveats)

The use Hook must be called inside a Component or a Hook.

@QuiiBz
Copy link
Owner

QuiiBz commented Nov 17, 2023

Thanks for the investigation @Yovach, I'll take a look this weekend. But this is honestly a very strange behavior...

@Yovach
Copy link
Contributor

Yovach commented Nov 17, 2023

If you want to reproduce it easily:

  • add a <input autoFocus/> in a Client Component that calls useI18n
  • hold a key like A on your keyboard
  • click on the refresh button

Then, your CPU should get 100% of usage (wtf?)

Can we preload locales in the createI18nProviderClient function?

@QuiiBz
Copy link
Owner

QuiiBz commented Jan 8, 2024

Sorry for the delay - https://github.com/QuiiBz/next-international/releases/tag/1.2.0 has been published!

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.

3 participants