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

[Bug]: Next.js 14: Modal window showPreferences does not open after language switch #753

Open
spalz opened this issue Nov 11, 2024 · 3 comments

Comments

@spalz
Copy link

spalz commented Nov 11, 2024

Expected Behavior

The modal window showPreferences should open correctly after switching the language, both via the data attribute and onClick event.

Current Behavior

After switching the language, the modal window showPreferences does not open, neither via the data attribute nor the onClick event.

Steps to reproduce

Reproducing the error:
https://stackblitz.com/~/github.com/spalz/CookieConsent

Steps to reproduce:

  1. Switch the language on the page.
  2. Try to open the modal window showPreferences using either the data attribute or the onClick event.
  3. Observe that the modal window does not open.å

Proposed fix or additional info.

Stack:

nextjs: "14.x.x"
translate package intl or i18n

Screen.Recording.2024-11-11.at.13.24.36.mov

Version

3.0.1

On which browser do you see the issue?

No response

@spalz spalz added the bug Something isn't working label Nov 11, 2024
@github-actions github-actions bot added the triage yet to be reviewed label Nov 11, 2024
@orestbida orestbida removed bug Something isn't working triage yet to be reviewed labels Nov 11, 2024
@orestbida
Copy link
Owner

The language change causes a full page re-render, and the markup generated by the plugin is being destroyed.

Since this is a vanilla js plugin (and not a react component) you need to be extra careful on how you initialize the plugin.

You need to initialize the plugin on a higher level, so that it does not get re-rendered. Here is a demo. Try navigating between pages, and you'll see that the markup is not destroyed.

@spalz
Copy link
Author

spalz commented Nov 11, 2024

@orestbida thanks for the reply! I spent the whole day figuring out how to set it up so that it wouldn’t reset when switching languages.

I actually figured out a solution using provider, and I’ll share it later as an example for Next.js with the app router.

@xInfinitYz
Copy link

@orestbida thanks for the reply! I spent the whole day figuring out how to set it up so that it wouldn’t reset when switching languages.

I actually figured out a solution using provider, and I’ll share it later as an example for Next.js with the app router.

Would you mind to share more info?

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

3 participants