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] The nodejs and edge runtime global scopes are not isolated (as they are in standard Next.js self hosted applications) #408

Open
dario-piotrowicz opened this issue Feb 24, 2025 · 2 comments

Comments

@dario-piotrowicz
Copy link
Contributor

Describe the bug

In a standard Next.js self hosted app the global scopes of the edge and nodejs runtimes are isolated, meaning that for example if your code mutates the global scope inside a runtime (e.g. edge), such mutation won't be reflected in the global scope of the other runtime (e.g. nodejs)

However that is not the case in open-next Cloudflare apps, where there is only a single shared global scope

Steps to reproduce

Save some value in the global scope of a runtime and try to retrieve it from another runtime1

Minimal Reproduction: https://github.com/dario-piotrowicz/open-next-cloudflare-shared-global-issue-repro

Expected behavior

Open-next Cloudflare apps should behave as closely as possible to standard Next.js self hosted apps

@opennextjs/cloudflare version

0.5.3

Wrangler version

3.109.3

next info output

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 24.3.0: Thu Jan  2 20:24:16 PST 2025; root:xnu-11215.81.4~3/RELEASE_ARM64_T6000
  Available memory (MB): 32768
  Available CPU cores: 10
Binaries:
  Node: 20.11.0
  npm: 10.2.4
  Yarn: 1.22.19
  pnpm: 9.12.1
Relevant Packages:
  next: 15.1.7 // Latest available version is detected (15.1.7).
  eslint-config-next: 15.0.4
  react: 19.0.0
  react-dom: 19.0.0
  typescript: 5.7.3
Next.js Config:
  output: N/A

Additional context

No response

Footnotes

  1. currently the only way to run edge runtime code in the adapter is via a middleware

@dario-piotrowicz dario-piotrowicz added bug Something isn't working triage labels Feb 24, 2025
@dario-piotrowicz
Copy link
Contributor Author

I don't know how serious this issue is, my gut feeling is that it's pretty unimportant, but anyways I think that anything that makes our apps diverge from standard Next.js apps is bad and should ideally be solved/looked into, or at least documented in some way (even having this issue open is better than nothing?).

Also I think that solving this issue might not be trivial since we'd have to create some sort of artificial global scope wrappers for the different runtimes... it might not be worth the extra complexity to be honest...

@vicb
Copy link
Contributor

vicb commented Feb 25, 2025

I think allowing multiple workers (middleware/Node runtime/Edge runtime) will solve this.

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

No branches or pull requests

2 participants