Files
Jiachi LiuandGitHub cfedc529c7 Fix extra swc optimizer applied to node_modules in browser layer (#62051)
### What

Disable swc transform optimizer for node_modules in browser layer of app
router bundles

Fixes #61858
Fixes #60644 
Fixes #60920
Fixes #61740
Closes NEXT-2418

### Why

In browser there could be not only one runtime, it could have both js
worker and browser. In js worker the `typeof window` is not as same as
in browser, so disabling the swc optimizer which will replace the code.
Leave the condition as it as.
2024-02-14 21:58:39 +01:00

23 lines
513 B
JavaScript

'use client'
import { useState } from 'react'
export default function Home() {
const [state, setState] = useState('default')
return (
<div>
<button
onClick={() => {
const worker = new Worker(new URL('./worker', import.meta.url))
worker.addEventListener('message', (event) => {
setState(event.data)
})
}}
>
Get web worker data
</button>
<p>Worker state: </p>
<p id="worker-state">{state}</p>
</div>
)
}