Files
Niklas MischkulnigandGitHub 0f27308051 Turbopack: support module workers (#72614)
- Also process `new Worker()` if there are options
- Then remove the `type: module` from the options at runtime (as Webpack
also does apparently). The alternative would be to keep the `type:
module` and ESM imports instead in the worker.
2024-12-11 12:29:41 +01:00

25 lines
557 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), {
type: 'module',
})
worker.addEventListener('message', (event) => {
setState(event.data)
})
}}
>
Get web worker data
</button>
<p>Worker state: </p>
<p id="worker-state">{state}</p>
</div>
)
}