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

Code imported inside instrumentation.ts can't mutate imported modules #69544

Open
shkreios opened this issue Sep 1, 2024 · 0 comments
Open
Labels
bug Issue was opened via the bug report template. Instrumentation Related to Next.js Instrumentation. Runtime Related to Node.js or Edge Runtime with Next.js.

Comments

@shkreios
Copy link

shkreios commented Sep 1, 2024

Link to the code that reproduces this issue

https://github.com/shkreios/next-js-instrumentation-bug-reproduction

To Reproduce

  1. Open the codesandbox
  2. Start the next dev server
  3. Open the app on http://localhost:3000
  4. Click the request button
  5. Inspect the logs see that the mutating of the store object inside instrumentation.ts has no effect to the imported store object inside api/update-store

Current vs. Expected behavior

I would expect the code inside instrumentation.ts to be able to mutate the store object.
Console output


// log from inside instrumentation.ts successfully setting the onUpdate prop on the store object
Store listener is ready { update: [Function: update], onUpdate: [Function (anonymous)] } 

log from inside the api/update-store/route.ts showing a different object which does not have the change 
{ update: [Function: update] } 

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 23.6.0: Mon Jul 29 21:14:30 PDT 2024; root:xnu-10063.141.2~1/RELEASE_ARM64_T6000
  Available memory (MB): 32768
  Available CPU cores: 8
Binaries:
  Node: 20.17.0
  npm: 10.8.2
  Yarn: 1.22.19
  pnpm: 9.9.0
Relevant Packages:
  next: 15.0.0-canary.137 // Latest available version is detected (15.0.0-canary.137).
  eslint-config-next: N/A
  react: 19.0.0-rc-7771d3a7-20240827
  react-dom: 19.0.0-rc-7771d3a7-20240827
  typescript: 5.3.3
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Instrumentation, Runtime

Which stage(s) are affected? (Select all that apply)

next dev (local), next start (local), Vercel (Deployed), Other (Deployed)

Additional context

My main use case for this approach, as demonstrated in the example, is to attach listeners to the data layer once. A more complex scenario would involve attempting to share an EventEmitter object. However, it would be less obvious that the objects within instrumentation.ts and the API route are not identical.

@shkreios shkreios added the bug Issue was opened via the bug report template. label Sep 1, 2024
@github-actions github-actions bot added Instrumentation Related to Next.js Instrumentation. Runtime Related to Node.js or Edge Runtime with Next.js. labels Sep 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue was opened via the bug report template. Instrumentation Related to Next.js Instrumentation. Runtime Related to Node.js or Edge Runtime with Next.js.
Projects
None yet
Development

No branches or pull requests

1 participant