这是indexloc提供的服务,不要输入任何密码
Skip to content

Add support for dynamic import()s on the server-side #3193

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

alexkirsz
Copy link
Contributor

@alexkirsz alexkirsz commented Jan 6, 2023

This PR separates Turbopack's runtime.js into two:

  • the Browser/DOM implementation, which uses <script> and <link> tags for dynamically loading chunks;
  • the Node.js/CommonJS implementation, which uses require instead.

The two runtimes share a lot of code, but I'm not sure what's the best approach for sharing this logic, or even if we should, so for now they are two separate entities.

The shared code between the two runtimes is now in a separate file to avoid duplication.

@vercel
Copy link

vercel bot commented Jan 6, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated
turbo-vite-web 🔄 Building (Inspect) Jan 12, 2023 at 3:27PM (UTC)
9 Ignored Deployments
Name Status Preview Comments Updated
examples-basic-web ⬜️ Ignored (Inspect) Visit Preview Jan 12, 2023 at 3:27PM (UTC)
examples-cra-web ⬜️ Ignored (Inspect) Jan 12, 2023 at 3:27PM (UTC)
examples-designsystem-docs ⬜️ Ignored (Inspect) Jan 12, 2023 at 3:27PM (UTC)
examples-kitchensink-blog ⬜️ Ignored (Inspect) Jan 12, 2023 at 3:27PM (UTC)
examples-native-web ⬜️ Ignored (Inspect) Jan 12, 2023 at 3:27PM (UTC)
examples-nonmonorepo ⬜️ Ignored (Inspect) Jan 12, 2023 at 3:27PM (UTC)
examples-svelte-web ⬜️ Ignored (Inspect) Jan 12, 2023 at 3:27PM (UTC)
examples-tailwind-web ⬜️ Ignored (Inspect) Jan 12, 2023 at 3:27PM (UTC)
turbo-site ⬜️ Ignored (Inspect) Visit Preview Jan 12, 2023 at 3:27PM (UTC)

@alexkirsz
Copy link
Contributor Author

alexkirsz commented Jan 6, 2023

@alexkirsz alexkirsz force-pushed the alexkirsz/web-375-apply-the-nextdynamic-swc-transform branch from a661cdd to 468260f Compare January 6, 2023 09:14
@alexkirsz alexkirsz force-pushed the alexkirsz/web-378-add-support-for-dynamic-imports-on-the branch from 0dd4f91 to 35aabb8 Compare January 6, 2023 09:14
@alexkirsz alexkirsz force-pushed the alexkirsz/web-375-apply-the-nextdynamic-swc-transform branch from 468260f to a4c98cd Compare January 9, 2023 12:36
@alexkirsz alexkirsz force-pushed the alexkirsz/web-378-add-support-for-dynamic-imports-on-the branch from 35aabb8 to 5731215 Compare January 9, 2023 12:36
@alexkirsz alexkirsz force-pushed the alexkirsz/web-375-apply-the-nextdynamic-swc-transform branch from a4c98cd to 44ca034 Compare January 9, 2023 13:12
@alexkirsz alexkirsz force-pushed the alexkirsz/web-378-add-support-for-dynamic-imports-on-the branch from 5731215 to 99850bb Compare January 9, 2023 13:12
@alexkirsz alexkirsz changed the base branch from alexkirsz/web-375-apply-the-nextdynamic-swc-transform to main January 10, 2023 16:16
@alexkirsz alexkirsz force-pushed the alexkirsz/web-378-add-support-for-dynamic-imports-on-the branch from 99850bb to c045d4f Compare January 10, 2023 16:16
@alexkirsz alexkirsz force-pushed the alexkirsz/web-378-add-support-for-dynamic-imports-on-the branch from c045d4f to 52a467e Compare January 11, 2023 12:59
@github-actions
Copy link
Contributor

github-actions bot commented Jan 11, 2023

⚠️ CI failed ⚠️

The following steps have failed in CI:

  • Rust tests

See workflow summary for details

@alexkirsz alexkirsz marked this pull request as ready for review January 11, 2023 13:07
@alexkirsz alexkirsz requested a review from a team as a code owner January 11, 2023 13:07
@alexkirsz alexkirsz requested a review from sokra January 12, 2023 11:20
@alexkirsz alexkirsz requested a review from a team as a code owner January 12, 2023 11:28
@github-actions
Copy link
Contributor

Benchmark for d516115

Test Base PR % Significant %
bench_hmr_to_commit/Turbopack RSC/1000 modules 451.03ms ± 2.80ms 459.07ms ± 1.03ms +1.78% +0.08%
bench_hmr_to_eval/Turbopack CSR/1000 modules 7124.65µs ± 84.52µs 6813.41µs ± 25.88µs -4.37% -1.30%
Click to view full benchmark
Test Base PR % Significant %
bench_hmr_to_commit/Turbopack CSR/1000 modules 7952.71µs ± 55.39µs 7878.39µs ± 37.85µs -0.93%
bench_hmr_to_commit/Turbopack RCC/1000 modules 8299.83µs ± 111.02µs 8212.80µs ± 72.26µs -1.05%
bench_hmr_to_commit/Turbopack RSC/1000 modules 451.03ms ± 2.80ms 459.07ms ± 1.03ms +1.78% +0.08%
bench_hmr_to_commit/Turbopack SSR/1000 modules 8000.67µs ± 51.48µs 8030.68µs ± 88.19µs +0.38%
bench_hmr_to_eval/Turbopack CSR/1000 modules 7124.65µs ± 84.52µs 6813.41µs ± 25.88µs -4.37% -1.30%
bench_hmr_to_eval/Turbopack RCC/1000 modules 7082.96µs ± 30.37µs 7210.79µs ± 52.18µs +1.80%
bench_hmr_to_eval/Turbopack SSR/1000 modules 7336.14µs ± 48.65µs 7185.42µs ± 37.05µs -2.05%
bench_hydration/Turbopack RCC/1000 modules 3243.50ms ± 11.21ms 3242.58ms ± 6.61ms -0.03%
bench_hydration/Turbopack RSC/1000 modules 2751.98ms ± 5.65ms 2739.73ms ± 5.77ms -0.45%
bench_hydration/Turbopack SSR/1000 modules 2550.14ms ± 9.92ms 2552.93ms ± 10.48ms +0.11%
bench_startup/Turbopack CSR/1000 modules 1606.66ms ± 4.36ms 1593.82ms ± 6.26ms -0.80%
bench_startup/Turbopack RCC/1000 modules 2410.45ms ± 6.85ms 2409.66ms ± 7.58ms -0.03%
bench_startup/Turbopack RSC/1000 modules 2307.61ms ± 11.08ms 2311.69ms ± 6.30ms +0.18%
bench_startup/Turbopack SSR/1000 modules 1980.99ms ± 5.99ms 1986.63ms ± 3.74ms +0.29%

@alexkirsz alexkirsz force-pushed the alexkirsz/web-378-add-support-for-dynamic-imports-on-the branch from 300fa15 to 005f61a Compare January 12, 2023 13:33
@alexkirsz alexkirsz removed the pr: automerge Kodiak will merge these automatically after checks pass label Jan 12, 2023
@alexkirsz
Copy link
Contributor Author

I'm going to merge this directly as our CI is too slow to handle the amount of merges currently happening.

@alexkirsz alexkirsz merged commit 84e30f4 into main Jan 12, 2023
@alexkirsz alexkirsz deleted the alexkirsz/web-378-add-support-for-dynamic-imports-on-the branch January 12, 2023 15:37
@github-actions
Copy link
Contributor

Benchmark for 9a4dba0

Click to view benchmark
Test Base PR % Significant %
bench_hmr_to_commit/Turbopack CSR/1000 modules 8842.97µs ± 63.26µs 8935.56µs ± 55.16µs +1.05%
bench_hmr_to_commit/Turbopack RCC/1000 modules 9129.93µs ± 49.76µs 9178.47µs ± 55.66µs +0.53%
bench_hmr_to_commit/Turbopack RSC/1000 modules 485.54ms ± 1.91ms 479.99ms ± 3.77ms -1.14%
bench_hmr_to_commit/Turbopack SSR/1000 modules 8883.32µs ± 42.49µs 8927.41µs ± 103.35µs +0.50%
bench_hmr_to_eval/Turbopack CSR/1000 modules 7859.97µs ± 59.97µs 7871.28µs ± 50.26µs +0.14%
bench_hmr_to_eval/Turbopack RCC/1000 modules 8033.06µs ± 65.09µs 7982.34µs ± 55.62µs -0.63%
bench_hmr_to_eval/Turbopack SSR/1000 modules 7922.66µs ± 48.10µs 7949.35µs ± 71.55µs +0.34%
bench_hydration/Turbopack RCC/1000 modules 3446.60ms ± 8.65ms 3482.53ms ± 16.46ms +1.04%
bench_hydration/Turbopack RSC/1000 modules 2957.73ms ± 7.07ms 2949.65ms ± 13.47ms -0.27%
bench_hydration/Turbopack SSR/1000 modules 2721.35ms ± 12.50ms 2733.07ms ± 12.90ms +0.43%
bench_startup/Turbopack CSR/1000 modules 1700.79ms ± 6.06ms 1699.50ms ± 6.49ms -0.08%
bench_startup/Turbopack RCC/1000 modules 2584.02ms ± 10.91ms 2598.31ms ± 8.59ms +0.55%
bench_startup/Turbopack RSC/1000 modules 2483.35ms ± 8.58ms 2509.10ms ± 17.58ms +1.04%
bench_startup/Turbopack SSR/1000 modules 2108.76ms ± 5.02ms 2112.46ms ± 7.61ms +0.18%

jridgewell added a commit that referenced this pull request Jan 12, 2023
The `processed_assets` `IndexSet` was performing deduplication on the `AssetVc`, which is the same between static (`import ... from "foo"`) and dynamic (`import("foo")`) imports of the same specifier. But, the _reference_ to those assets is different, and generates different chunking semantics. In order for both to succeed, we need to process both assets.

Coupled with #3193's ability to load chunks on the server side, this fixes fixes WEB-381.
kodiakhq bot pushed a commit that referenced this pull request Jan 13, 2023
…3297)

The `processed_assets` `IndexSet` was performing deduplication on the `AssetVc`, which is the same between static (`import ... from "foo"`) and dynamic (`import("foo")`) imports of the same specifier. But, the _reference_ to those assets is different, and generates different chunking semantics. In order for both to succeed, we need to process both assets.

Coupled with #3193's ability to load chunks on the server side, this fixes fixes WEB-381.
jridgewell pushed a commit to vercel/next.js that referenced this pull request Mar 10, 2023
…epo#3193)

This PR separates Turbopack's `runtime.js` into two:

- the Browser/DOM implementation, which uses `<script>` and `<link>`
tags for dynamically loading chunks;
- the Node.js/CommonJS implementation, which uses `require` instead.

~~The two runtimes share a lot of code, but I'm not sure what's the best
approach for sharing this logic, or even if we should, so for now they
are two separate entities.~~

The shared code between the two runtimes is now in a separate file to
avoid duplication.

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
jridgewell added a commit to vercel/next.js that referenced this pull request Mar 10, 2023
…ercel/turborepo#3297)

The `processed_assets` `IndexSet` was performing deduplication on the `AssetVc`, which is the same between static (`import ... from "foo"`) and dynamic (`import("foo")`) imports of the same specifier. But, the _reference_ to those assets is different, and generates different chunking semantics. In order for both to succeed, we need to process both assets.

Coupled with vercel/turborepo#3193's ability to load chunks on the server side, this fixes fixes WEB-381.
sokra pushed a commit to vercel/next.js that referenced this pull request Mar 13, 2023
…epo#3193)

This PR separates Turbopack's `runtime.js` into two:

- the Browser/DOM implementation, which uses `<script>` and `<link>`
tags for dynamically loading chunks;
- the Node.js/CommonJS implementation, which uses `require` instead.

~~The two runtimes share a lot of code, but I'm not sure what's the best
approach for sharing this logic, or even if we should, so for now they
are two separate entities.~~

The shared code between the two runtimes is now in a separate file to
avoid duplication.

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
sokra pushed a commit to vercel/next.js that referenced this pull request Mar 13, 2023
…ercel/turborepo#3297)

The `processed_assets` `IndexSet` was performing deduplication on the `AssetVc`, which is the same between static (`import ... from "foo"`) and dynamic (`import("foo")`) imports of the same specifier. But, the _reference_ to those assets is different, and generates different chunking semantics. In order for both to succeed, we need to process both assets.

Coupled with vercel/turborepo#3193's ability to load chunks on the server side, this fixes fixes WEB-381.
ForsakenHarmony pushed a commit to vercel/next.js that referenced this pull request Jul 25, 2024
…epo#3193)

This PR separates Turbopack's `runtime.js` into two:

- the Browser/DOM implementation, which uses `<script>` and `<link>`
tags for dynamically loading chunks;
- the Node.js/CommonJS implementation, which uses `require` instead.

~~The two runtimes share a lot of code, but I'm not sure what's the best
approach for sharing this logic, or even if we should, so for now they
are two separate entities.~~

The shared code between the two runtimes is now in a separate file to
avoid duplication.

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
ForsakenHarmony pushed a commit to vercel/next.js that referenced this pull request Jul 29, 2024
…epo#3193)

This PR separates Turbopack's `runtime.js` into two:

- the Browser/DOM implementation, which uses `<script>` and `<link>`
tags for dynamically loading chunks;
- the Node.js/CommonJS implementation, which uses `require` instead.

~~The two runtimes share a lot of code, but I'm not sure what's the best
approach for sharing this logic, or even if we should, so for now they
are two separate entities.~~

The shared code between the two runtimes is now in a separate file to
avoid duplication.

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
ForsakenHarmony pushed a commit to vercel/next.js that referenced this pull request Aug 1, 2024
…epo#3193)

This PR separates Turbopack's `runtime.js` into two:

- the Browser/DOM implementation, which uses `<script>` and `<link>`
tags for dynamically loading chunks;
- the Node.js/CommonJS implementation, which uses `require` instead.

~~The two runtimes share a lot of code, but I'm not sure what's the best
approach for sharing this logic, or even if we should, so for now they
are two separate entities.~~

The shared code between the two runtimes is now in a separate file to
avoid duplication.

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants