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] Nesting Layouts with next-themes #511

Open
NavOrange opened this issue Mar 27, 2025 · 10 comments
Open

[BUG] Nesting Layouts with next-themes #511

NavOrange opened this issue Mar 27, 2025 · 10 comments
Labels
bug Something isn't working waiting for feedback

Comments

@NavOrange
Copy link

NavOrange commented Mar 27, 2025

Describe the bug

I'm encountering an error in the preview when using nested layouts to handle multiple languages alongside next-themes (include inline script -> error)

repo: https://github.com/NavOrange/nesting-layouts-with-next-themes

Image Image

__name(m3, "m3");

This code issue only appears after the opennextjs-cloudflare build process, and it seems the code has been formatted as well.

@opennextjs/[email protected], inline code is also formatted, but no unexpected code appears.

Steps to reproduce

  1. clone code
  2. cd nesting-layouts-with-next-themes && pnpm install
  3. pnpm preview
  4. open browser
  5. go to http://localhost:8787/en
  6. open console

Expected behavior

No unexpected code

@opennextjs/cloudflare version

^0.6.0

Wrangler version

^4.5.0

next info output

Operating System:
  Platform: darwin
  Arch: x64
  Version: Darwin Kernel Version 24.3.0: Thu Jan  2 20:22:00 PST 2025; root:xnu-11215.81.4~3/RELEASE_X86_64
  Available memory (MB): 16384
  Available CPU cores: 12
Binaries:
  Node: 22.14.0
  npm: 10.9.2
  Yarn: N/A
  pnpm: 10.6.2
Relevant Packages:
  next: 15.2.4 // Latest available version is detected (15.2.4).
  eslint-config-next: N/A
  react: 19.0.0
  react-dom: 19.0.0
  typescript: 5.8.2
Next.js Config:
  output: N/A

Additional context

No response

@NavOrange NavOrange added bug Something isn't working triage labels Mar 27, 2025
@vicb
Copy link
Contributor

vicb commented Mar 27, 2025

I can not reproduce locally (the behavior is similar with next dev)

Image

@NavOrange
Copy link
Author

NavOrange commented Mar 27, 2025

@vicb Sorry, I missed go to http://localhost:8787/en

Additionally, everything works fine if I don't use nested layouts.

@eposha
Copy link

eposha commented Mar 27, 2025

same issue

It happens in production. When deploying to cloudflare.

@vicb You need to go to the page with the error and do a refresh

Image

@vicb
Copy link
Contributor

vicb commented Apr 1, 2025

Note: The __name(...) call is added by the ESBuild pass of wrangler (see cloudflare/workers-sdk#6901).

@vicb vicb removed the triage label Apr 1, 2025
@vicb
Copy link
Contributor

vicb commented Apr 1, 2025

The cause cause of the issue here seems to be script.toString() in next-themes.

Would would be nice is to open an issue on the repo and ask for the value to be inlined at build time.

What happens with the Cloudflare adapter is that we bundle the code into a single JS file for deployment using ESBuild. ESBuild add those __name(...) calls - __name is defined at the top level to preserve the name of functions/classes when bundling and/or minifying.

@NavOrange
Copy link
Author

The cause cause of the issue here seems to be script.toString() in next-themes.

Would would be nice is to open an issue on the repo and ask for the value to be inlined at build time.

What happens with the Cloudflare adapter is that we bundle the code into a single JS file for deployment using ESBuild. ESBuild add those __name(...) calls - __name is defined at the top level to preserve the name of functions/classes when bundling and/or minifying.

Thank you for your work on this! However, it seems like this doesn't explain why the issue only arises when nested layouts are used.

@dario-piotrowicz
Copy link
Contributor

dario-piotrowicz commented Apr 4, 2025

A potential fix for this: pacocoursey/next-themes#349
(let's see what the next-themes folks reply 🙂🤞)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working waiting for feedback
Projects
None yet
Development

No branches or pull requests

4 participants