Skip to content

Commit 4c74ea4

Browse files
authored
Turbopack: Change eager import to lazy import for loader_tree (#83115)
## What? Switch to matching webpack behavior where module in the loader_tree are initialized later.
1 parent 80563bf commit 4c74ea4

File tree

5 files changed

+6
-22
lines changed

5 files changed

+6
-22
lines changed

crates/next-core/src/base_loader_tree.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ impl BaseLoaderTreeBuilder {
9999
self.imports.push(
100100
formatdoc!(
101101
r#"
102-
import * as {} from "MODULE_{}";
102+
const {} = () => require("MODULE_{}");
103103
"#,
104104
identifier,
105105
i
@@ -118,7 +118,7 @@ impl BaseLoaderTreeBuilder {
118118
let module_path = module.ident().path().to_string().await?;
119119

120120
Ok(format!(
121-
"[() => {identifier}, {path}]",
121+
"[{identifier}, {path}]",
122122
path = StringifyJs(&module_path),
123123
))
124124
}

packages/next/src/server/next-server.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -387,13 +387,6 @@ export default class NextNodeServer extends BaseServer<
387387
// otherwise if the fetch is patched by user code, we will be patching it
388388
// too late and there won't be any caching behaviors
389389
ComponentMod.patchFetch()
390-
391-
const webpackRequire = ComponentMod.__next_app__.require
392-
if (webpackRequire?.m) {
393-
for (const id of Object.keys(webpackRequire.m)) {
394-
await webpackRequire(id)
395-
}
396-
}
397390
} catch (_err) {
398391
// Intentionally ignored because this is a preload step.
399392
}

test/development/acceptance-app/hydration-error.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,6 @@ describe('Error overlay for hydration errors in App router', () => {
228228
<SegmentTrieNode>
229229
<script>
230230
<script>
231-
<script>
232231
<ClientSegmentRoot Component={function Root} slots={{...}} params={{}}>
233232
<Root params={Promise}>
234233
<html

test/e2e/app-dir/cache-components-errors/cache-components-errors.test.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2698,7 +2698,6 @@ describe('Cache Components Errors', () => {
26982698
"stack": [
26992699
"{module evaluation} app/use-cache-private-in-unstable-cache/page.tsx (21:38)",
27002700
"<FIXME-next-dist-dir>",
2701-
"<FIXME-next-dist-dir>",
27022701
],
27032702
}
27042703
`)
@@ -2754,7 +2753,6 @@ describe('Cache Components Errors', () => {
27542753
"Error: "use cache: private" must not be used within \`unstable_cache()\`.
27552754
at __TURBOPACK__module__evaluation__ (bundler:///app/use-cache-private-in-unstable-cache/page.tsx:21:38)
27562755
at a (<next-dist-dir>)
2757-
at b (<next-dist-dir>)
27582756
19 | }
27592757
20 |
27602758
> 21 | const getCachedData = unstable_cache(async () => {
@@ -2772,7 +2770,6 @@ describe('Cache Components Errors', () => {
27722770
expect(output).toMatchInlineSnapshot(`
27732771
"Error: "use cache: private" must not be used within \`unstable_cache()\`.
27742772
at __TURBOPACK__module__evaluation__ (bundler:///app/use-cache-private-in-unstable-cache/page.tsx:21:38)
2775-
at a (<next-dist-dir>)
27762773
19 | }
27772774
20 |
27782775
> 21 | const getCachedData = unstable_cache(async () => {
@@ -2841,7 +2838,6 @@ describe('Cache Components Errors', () => {
28412838
"stack": [
28422839
"{module evaluation} app/use-cache-private-in-use-cache/page.tsx (15:1)",
28432840
"<FIXME-next-dist-dir>",
2844-
"<FIXME-next-dist-dir>",
28452841
],
28462842
}
28472843
`)
@@ -2898,7 +2894,6 @@ describe('Cache Components Errors', () => {
28982894
"Error: "use cache: private" must not be used within "use cache". It can only be nested inside of another "use cache: private".
28992895
at __TURBOPACK__module__evaluation__ (bundler:///app/use-cache-private-in-use-cache/page.tsx:15:1)
29002896
at a (<next-dist-dir>)
2901-
at b (<next-dist-dir>)
29022897
13 | }
29032898
14 |
29042899
> 15 | async function Private() {
@@ -2908,8 +2903,7 @@ describe('Cache Components Errors', () => {
29082903
18 | return <p>Private</p>
29092904
Error: "use cache: private" must not be used within "use cache". It can only be nested inside of another "use cache: private".
29102905
at __TURBOPACK__module__evaluation__ (bundler:///app/use-cache-private-in-use-cache/page.tsx:15:1)
2911-
at c (<next-dist-dir>)
2912-
at d (<next-dist-dir>)
2906+
at b (<next-dist-dir>)
29132907
13 | }
29142908
14 |
29152909
> 15 | async function Private() {
@@ -2927,7 +2921,6 @@ describe('Cache Components Errors', () => {
29272921
expect(output).toMatchInlineSnapshot(`
29282922
"Error: "use cache: private" must not be used within "use cache". It can only be nested inside of another "use cache: private".
29292923
at __TURBOPACK__module__evaluation__ (bundler:///app/use-cache-private-in-use-cache/page.tsx:15:1)
2930-
at a (<next-dist-dir>)
29312924
13 | }
29322925
14 |
29332926
> 15 | async function Private() {
@@ -2937,7 +2930,6 @@ describe('Cache Components Errors', () => {
29372930
18 | return <p>Private</p>
29382931
Error: "use cache: private" must not be used within "use cache". It can only be nested inside of another "use cache: private".
29392932
at __TURBOPACK__module__evaluation__ (bundler:///app/use-cache-private-in-use-cache/page.tsx:15:1)
2940-
at b (<next-dist-dir>)
29412933
13 | }
29422934
14 |
29432935
> 15 | async function Private() {

test/e2e/app-dir/server-source-maps/server-source-maps.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,8 @@ describe('app-dir - server source maps', () => {
484484
"{module evaluation} app/module-evaluation/module.js (1:22)",
485485
"{module evaluation} app/module-evaluation/page.js (1:1)",
486486
"{module evaluation} app/module-evaluation/page.js (6:1)",
487-
"<FIXME-next-dist-dir>",
487+
"Array.map <anonymous>",
488+
"Function.all <anonymous>",
488489
"Page <anonymous>",
489490
],
490491
}
@@ -515,9 +516,8 @@ describe('app-dir - server source maps', () => {
515516
expect(normalizeCliOutput(next.cliOutput)).toContain(
516517
'' +
517518
'\nError: module-evaluation' +
518-
'\n at __TURBOPACK__module__evaluation__ (bundler:///app/module-evaluation/module.js:1:22)' +
519519
// TODO(veil): Turbopack internals. Feel free to update. Tracked in https://linear.app/vercel/issue/NEXT-4362
520-
'\n at Object.<anonymous>'
520+
'\n at __TURBOPACK__module__evaluation__ (bundler:///app/module-evaluation/module.js:1:22)'
521521
)
522522
expect(normalizeCliOutput(next.cliOutput)).toContain(
523523
'' +

0 commit comments

Comments
 (0)