Skip to content

Commit 099a42a

Browse files
authored
Merge branch 'canary' into huozhi/04-10-separate_rsc_basic_tests
2 parents e1642cb + 72af683 commit 099a42a

13 files changed

+65
-27
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
'use client'
2+
import { useState } from 'react'
3+
4+
export default function Home() {
5+
const [state, setState] = useState('default')
6+
return (
7+
<div>
8+
<button
9+
onClick={() => {
10+
const worker = new Worker('/unbundled-worker.js')
11+
worker.addEventListener('message', (event) => {
12+
setState(event.data)
13+
})
14+
}}
15+
>
16+
Get web worker data
17+
</button>
18+
<p>Worker state: </p>
19+
<p id="worker-state">{state}</p>
20+
</div>
21+
)
22+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
self.postMessage('unbundled-worker')

test/e2e/app-dir/worker/worker.test.ts

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { nextTestSetup } from 'e2e-utils'
2-
import { check } from 'next-test-utils'
2+
import { retry } from 'next-test-utils'
33

44
describe('app dir - workers', () => {
55
const { next, skipped } = nextTestSetup({
@@ -17,9 +17,10 @@ describe('app dir - workers', () => {
1717

1818
await browser.elementByCss('button').click()
1919

20-
await check(
21-
async () => browser.elementByCss('#worker-state').text(),
22-
'worker.ts:worker-dep'
20+
await retry(async () =>
21+
expect(await browser.elementByCss('#worker-state').text()).toBe(
22+
'worker.ts:worker-dep'
23+
)
2324
)
2425
})
2526

@@ -29,9 +30,23 @@ describe('app dir - workers', () => {
2930

3031
await browser.elementByCss('button').click()
3132

32-
await check(
33-
async () => browser.elementByCss('#worker-state').text(),
34-
'worker.ts:worker-dep'
33+
await retry(async () =>
34+
expect(await browser.elementByCss('#worker-state').text()).toBe(
35+
'worker.ts:worker-dep'
36+
)
37+
)
38+
})
39+
40+
it('should not bundle web workers with string specifiers', async () => {
41+
const browser = await next.browser('/string')
42+
expect(await browser.elementByCss('#worker-state').text()).toBe('default')
43+
44+
await browser.elementByCss('button').click()
45+
46+
await retry(async () =>
47+
expect(await browser.elementByCss('#worker-state').text()).toBe(
48+
'unbundled-worker'
49+
)
3550
)
3651
})
3752
})

turbopack/crates/turbopack-ecmascript/src/references/mod.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1641,14 +1641,7 @@ async fn handle_call<G: Fn(Vec<Effect>) + Send + Sync>(
16411641

16421642
return Ok(());
16431643
}
1644-
let (args, hints) = explain_args(&args);
1645-
handler.span_warn_with_code(
1646-
span,
1647-
&format!("new Worker({args}) is not statically analyse-able{hints}",),
1648-
DiagnosticId::Error(
1649-
errors::failed_to_analyse::ecmascript::DYNAMIC_IMPORT.to_string(),
1650-
),
1651-
);
1644+
// Ignore (e.g. dynamic parameter or string literal), just as Webpack does
16521645
return Ok(());
16531646
}
16541647
_ => {}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Shouldn't cause a worker to be created, but will still be pulled in by `new URL()`
2+
module.exports = 123

turbopack/crates/turbopack-tests/tests/snapshot/imports/ignore-comments/input/index.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@ import(/* turbopackIgnore: true */ "./ignore.mjs");
1111
require(/* webpackIgnore: true */ "./ignore.cjs");
1212
require(/* turbopackIgnore: true */ "./ignore.cjs");
1313

14-
// and for workers
15-
new Worker(/* webpackIgnore: true */ "./ignore.mjs");
16-
new Worker(/* turbopackIgnore: true */ "./ignore.cjs");
14+
new Worker(/* turbopackIgnore: true */ new URL("./ignore-worker.cjs", import.meta.url))
15+
new Worker(/* webpackIgnore: true */ new URL("./ignore-worker.cjs", import.meta.url))
1716

1817
export function foo(plugin) {
1918
return require(/* turbopackIgnore: true */ plugin)

turbopack/crates/turbopack-tests/tests/snapshot/imports/ignore-comments/output/4c35f_tests_snapshot_imports_ignore-comments_input_vercel_mjs_f0a767e9._.js renamed to turbopack/crates/turbopack-tests/tests/snapshot/imports/ignore-comments/output/4c35f_tests_snapshot_imports_ignore-comments_input_vercel_mjs_0dd84fce._.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
(globalThis.TURBOPACK = globalThis.TURBOPACK || []).push(["output/4c35f_tests_snapshot_imports_ignore-comments_input_vercel_mjs_f0a767e9._.js", {
1+
(globalThis.TURBOPACK = globalThis.TURBOPACK || []).push(["output/4c35f_tests_snapshot_imports_ignore-comments_input_vercel_mjs_0dd84fce._.js", {
22

33
"[project]/turbopack/crates/turbopack-tests/tests/snapshot/imports/ignore-comments/input/vercel.mjs [test] (ecmascript, async loader)": ((__turbopack_context__) => {
44

turbopack/crates/turbopack-tests/tests/snapshot/imports/ignore-comments/output/4c35f_tests_snapshot_imports_ignore-comments_input_vercel_mjs_f0a767e9._.js.map renamed to turbopack/crates/turbopack-tests/tests/snapshot/imports/ignore-comments/output/4c35f_tests_snapshot_imports_ignore-comments_input_vercel_mjs_0dd84fce._.js.map

File renamed without changes.

turbopack/crates/turbopack-tests/tests/snapshot/imports/ignore-comments/output/4e721_crates_turbopack-tests_tests_snapshot_imports_ignore-comments_input_e1849155._.js renamed to turbopack/crates/turbopack-tests/tests/snapshot/imports/ignore-comments/output/4e721_crates_turbopack-tests_tests_snapshot_imports_ignore-comments_input_7f940ff3._.js

Lines changed: 9 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

turbopack/crates/turbopack-tests/tests/snapshot/imports/ignore-comments/output/4e721_crates_turbopack-tests_tests_snapshot_imports_ignore-comments_input_e1849155._.js.map renamed to turbopack/crates/turbopack-tests/tests/snapshot/imports/ignore-comments/output/4e721_crates_turbopack-tests_tests_snapshot_imports_ignore-comments_input_7f940ff3._.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)