Skip to content

Commit 5b5d9b1

Browse files
authored
Turbopack: fix test case and update project_update to turbo_tasks::run too (#83978)
### What? Changing an env var that is used in an RSC doesn't lead to HMR updates. It only refetches the RSC stream and no compilation happens at all since the env var is consumed only at runtime. This test did pass before as the `run_once` created a task for the `project_update` and we counted that as computation. Changing this to `turbo_tasks::run` removes the once task and no computation happens at all.
1 parent af9298c commit 5b5d9b1

File tree

3 files changed

+6
-47
lines changed

3 files changed

+6
-47
lines changed

crates/napi/src/next_api/project.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -455,13 +455,13 @@ pub fn project_new(
455455

456456
let options: ProjectOptions = options.into();
457457
let container = turbo_tasks
458-
.run_once(async move {
458+
.run(async move {
459459
let project = ProjectContainer::new(rcstr!("next.js"), options.dev);
460460
let project = project.to_resolved().await?;
461461
project.initialize(options).await?;
462462
Ok(project)
463463
})
464-
.or_else(|e| turbopack_ctx.throw_turbopack_internal_result(&e))
464+
.or_else(|e| turbopack_ctx.throw_turbopack_internal_result(&e.into()))
465465
.await?;
466466

467467
turbo_tasks.start_once_process({
@@ -580,11 +580,11 @@ pub async fn project_update(
580580
let options = options.into();
581581
let container = project.container;
582582
ctx.turbo_tasks()
583-
.run_once(async move {
583+
.run(async move {
584584
container.update(options).await?;
585585
Ok(())
586586
})
587-
.or_else(|e| ctx.throw_turbopack_internal_result(&e))
587+
.or_else(|e| ctx.throw_turbopack_internal_result(&e.into()))
588588
.await
589589
}
590590

test/development/app-hmr/hmr-env.test.ts

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,32 +17,9 @@ describe(`app-dir hmr-env`, () => {
1717
expect(await browser.elementByCss('p').text()).toBe('mac')
1818

1919
await next.patchFile(envFile, 'MY_DEVICE="ipad"', async () => {
20-
let logs
21-
22-
await retry(async () => {
23-
logs = await browser.log()
24-
expect(logs).toEqual(
25-
expect.arrayContaining([
26-
expect.objectContaining({
27-
message: expect.stringContaining('[Fast Refresh] done'),
28-
source: 'log',
29-
}),
30-
])
31-
)
32-
})
33-
3420
await retry(async () => {
3521
expect(await browser.elementByCss('p').text()).toBe('ipad')
3622
})
37-
38-
expect(logs).toEqual(
39-
expect.arrayContaining([
40-
expect.objectContaining({
41-
message: expect.stringContaining('[Fast Refresh] done in'),
42-
source: 'log',
43-
}),
44-
])
45-
)
4623
})
4724

4825
// ensure it's restored back to "mac" before the next test

test/development/app-hmr/hmr.test.ts

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -76,26 +76,8 @@ describe(`app-dir-hmr`, () => {
7676
expect(await browser.elementByCss('p').text()).toBe('ipad')
7777
}, 5000 /* ms */)
7878

79-
expect(
80-
await browser.eval('window.__TEST_NO_RELOAD === undefined')
81-
).toBe(false)
82-
83-
const logs = await browser.log()
84-
const fastRefreshLogs = logs.filter((log) => {
85-
return log.message.startsWith('[Fast Refresh]')
86-
})
87-
88-
// The exact ordering and number of these messages is implementation
89-
// dependent and subject to race conditions, just check that we have at
90-
// least one "rebuilding" and "done in" message in the logs, the exact
91-
// details are unimportant.
92-
expect(fastRefreshLogs).toEqual(
93-
expect.arrayContaining([
94-
{
95-
source: 'log',
96-
message: expect.stringContaining('[Fast Refresh] done in '),
97-
},
98-
])
79+
expect(await browser.eval('window.__TEST_NO_RELOAD === true')).toBe(
80+
true
9981
)
10082
})
10183

0 commit comments

Comments
 (0)