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

window is injected as an object in webworker scripts instead of undefined #62256

Open
njarraud opened this issue Feb 19, 2024 · 1 comment
Open
Labels
bug Issue was opened via the bug report template. SWC Related to minification/transpilation in Next.js.

Comments

@njarraud
Copy link

Link to the code that reproduces this issue

https://codesandbox.io/p/devbox/boring-hill-2w8x38?file=%2Fapp%2Fworker.ts%3A5%2C44

To Reproduce

  1. Start the application in dev
  2. Click the "Send to worker" button
  3. Inspect the console

Current vs. Expected behavior

Until next@14.0.5-canary.20, typeof window returned undefined inside a webworker as expected. However since next@14.0.5-canary.20, typeof window returns object but this object cannot be accessed. Therefore, as it stands, third party libraries making use of window via an undefined test cannot work anymore in webworkers in Nextjs.

The most notable example if Three.js which includes this snippet at the end of the library -

if ( typeof window !== 'undefined' ) {

	if ( window.__THREE__ ) {

		console.warn( 'WARNING: Multiple instances of Three.js being imported.' );

	} else {

		window.__THREE__ = REVISION;

	}

}

Provide environment information

All

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

SWC transpilation

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

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

Additional context

This bug was first introduced in next@14.0.5-canary.20

@njarraud njarraud added the bug Issue was opened via the bug report template. label Feb 19, 2024
@github-actions github-actions bot added the SWC Related to minification/transpilation in Next.js. label Feb 19, 2024
@mikayelvertex

This comment has been minimized.

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. SWC Related to minification/transpilation in Next.js.
Projects
None yet
Development

No branches or pull requests

2 participants