Skip to content
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

improve dynamic reexporting #5452

Merged
merged 7 commits into from
Jul 4, 2023
Merged

improve dynamic reexporting #5452

merged 7 commits into from
Jul 4, 2023

Conversation

sokra
Copy link
Member

@sokra sokra commented Jul 4, 2023

Description

This fixes some problems when export * from "client component", as "use client" creates a non-enumerable Proxy object, so we need to really redirect property access.

  • __turbopack_export_namespace__ counts as dynamic
  • use Proxy to correctly reexport non-enumerable or changing objects

`__turbopack_export_namespace__` counts as dynamic
use Proxy to correctly reexport non-enumerable or changing objects
@sokra sokra requested a review from a team as a code owner July 4, 2023 06:22
@sokra sokra requested a review from alexkirsz July 4, 2023 06:22
@vercel
Copy link

vercel bot commented Jul 4, 2023

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

Name Status Preview Comments Updated (UTC)
examples-gatsby-web 🔄 Building (Inspect) Visit Preview 💬 Add feedback Jul 4, 2023 9:12am
10 Ignored Deployments
Name Status Preview Comments Updated (UTC)
examples-basic-web ⬜️ Ignored (Inspect) Visit Preview Jul 4, 2023 9:12am
examples-cra-web ⬜️ Ignored (Inspect) Visit Preview Jul 4, 2023 9:12am
examples-designsystem-docs ⬜️ Ignored (Inspect) Visit Preview Jul 4, 2023 9:12am
examples-kitchensink-blog ⬜️ Ignored (Inspect) Visit Preview Jul 4, 2023 9:12am
examples-native-web ⬜️ Ignored (Inspect) Visit Preview Jul 4, 2023 9:12am
examples-nonmonorepo ⬜️ Ignored (Inspect) Visit Preview Jul 4, 2023 9:12am
examples-svelte-web ⬜️ Ignored (Inspect) Visit Preview Jul 4, 2023 9:12am
examples-tailwind-web ⬜️ Ignored (Inspect) Visit Preview Jul 4, 2023 9:12am
examples-vite-web ⬜️ Ignored (Inspect) Visit Preview Jul 4, 2023 9:12am
turbo-site ⬜️ Ignored (Inspect) Visit Preview Jul 4, 2023 9:12am

@github-actions
Copy link
Contributor

github-actions bot commented Jul 4, 2023

⚠️ CI failed ⚠️

The following steps have failed in CI:

  • Determining jobs

See workflow summary for details

@github-actions
Copy link
Contributor

github-actions bot commented Jul 4, 2023

✅ This change can build next-swc

@github-actions
Copy link
Contributor

github-actions bot commented Jul 4, 2023

Linux Benchmark for 53242ec

Click to view benchmark
Test Base PR % Significant %
bench_hmr_to_commit/Turbopack CSR/1000 modules 10.72ms ± 0.06ms 10.66ms ± 0.05ms -0.57%
bench_hmr_to_eval/Turbopack CSR/1000 modules 9880.33µs ± 67.86µs 9916.72µs ± 83.87µs +0.37%
bench_startup/Turbopack CSR/1000 modules 1107.62ms ± 2.85ms 1103.24ms ± 7.92ms -0.40%

@github-actions
Copy link
Contributor

github-actions bot commented Jul 4, 2023

Linux Benchmark for 63badc6

Click to view benchmark
Test Base PR % Significant %
bench_hmr_to_commit/Turbopack CSR/1000 modules 11.90ms ± 0.05ms 11.84ms ± 0.10ms -0.49%
bench_hmr_to_eval/Turbopack CSR/1000 modules 10.82ms ± 0.09ms 11.11ms ± 0.10ms +2.74%
bench_startup/Turbopack CSR/1000 modules 1162.75ms ± 3.61ms 1164.49ms ± 6.14ms +0.15%

@github-actions
Copy link
Contributor

github-actions bot commented Jul 4, 2023

Windows Benchmark for 63badc6

Test Base PR % Significant %
bench_startup/Turbopack CSR/1000 modules 4059.86ms ± 44.12ms 4537.13ms ± 77.50ms +11.76% +5.64%
Click to view full benchmark
Test Base PR % Significant %
bench_hmr_to_commit/Turbopack CSR/1000 modules 15.66ms ± 0.02ms 15.74ms ± 0.03ms +0.52%
bench_hmr_to_eval/Turbopack CSR/1000 modules 15.63ms ± 0.03ms 15.66ms ± 0.02ms +0.16%
bench_startup/Turbopack CSR/1000 modules 4059.86ms ± 44.12ms 4537.13ms ± 77.50ms +11.76% +5.64%

asserts.props.iter().any(|assert| {
assert
.as_prop()
.and_then(|prop| prop.as_key_value())
.and_then(|kv| kv.key.as_ident())
.map_or(true, |ident| &*ident.sym != TURBOPACK_HELPER)
.map_or(false, |ident| &*ident.sym == TURBOPACK_HELPER)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this broken before, or was it used some other way?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was broken before

|| &*i.sym == "exports"
|| &*i.sym == "__turbopack_export_value__"
{
if &*i.sym == "module" || &*i.sym == "exports" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this only work if the ident is unresolved? e.g. will it false positive const module = {}?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes that's broken in that case. It's only a difference between no exports and commonjs exports, and doesn't matter at runtime. It generates a bit less code for "no exports", but nevermind...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a comment explaining this, so we know that this is broken but it doesn't actually matter?

Co-authored-by: Alex Kirszenberg <alex.kirszenberg@vercel.com>
@sokra sokra requested a review from alexkirsz July 4, 2023 08:22
@github-actions
Copy link
Contributor

github-actions bot commented Jul 4, 2023

Linux Benchmark for b1a8180

Click to view benchmark
Test Base PR % Significant %
bench_hmr_to_commit/Turbopack CSR/1000 modules 5869.17µs ± 33.84µs 5858.17µs ± 45.19µs -0.19%
bench_hmr_to_eval/Turbopack CSR/1000 modules 5556.99µs ± 30.43µs 5766.59µs ± 242.28µs +3.77%
bench_startup/Turbopack CSR/1000 modules 908.94ms ± 1.70ms 907.18ms ± 3.64ms -0.19%

@@ -99,15 +99,15 @@ function dynamicExport(module: Module, object: Record<string, any>) {
) {
return Reflect.get(target, prop);
}
for (const obj of reexportedObjects) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't think you'd need this with reexportedObjects being clearly set to a defined value above.

@github-actions
Copy link
Contributor

github-actions bot commented Jul 4, 2023

Linux Benchmark for 89ed02b

Click to view benchmark
Test Base PR % Significant %
bench_hmr_to_commit/Turbopack CSR/1000 modules 6110.68µs ± 44.66µs 5974.76µs ± 29.34µs -2.22%
bench_hmr_to_eval/Turbopack CSR/1000 modules 5628.10µs ± 30.48µs 5744.99µs ± 69.40µs +2.08%
bench_startup/Turbopack CSR/1000 modules 923.26ms ± 0.57ms 928.45ms ± 2.50ms +0.56%

@sokra sokra merged commit 4f22144 into main Jul 4, 2023
@sokra sokra deleted the sokra/reexport-custom-namespace branch July 4, 2023 09:12
kodiakhq bot pushed a commit to vercel/next.js that referenced this pull request Jul 4, 2023
Comment on lines +608 to +609
DetectedDynamicExportType::Namespace => EcmascriptExports::DynamicNamespace,
DetectedDynamicExportType::Value => EcmascriptExports::Value,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, I think this unfortunately breaks my async module implementation 🙃

shuding pushed a commit to vercel/next.js that referenced this pull request Jul 8, 2023
ForsakenHarmony pushed a commit to vercel/next.js that referenced this pull request Jul 25, 2024
### Description

This fixes some problems when `export * from "client component"`, as
`"use client"` creates a non-enumerable Proxy object, so we need to
really redirect property access.

* `__turbopack_export_namespace__` counts as dynamic
* use Proxy to correctly reexport non-enumerable or changing objects

---------

Co-authored-by: Alex Kirszenberg <alex.kirszenberg@vercel.com>
ForsakenHarmony pushed a commit to vercel/next.js that referenced this pull request Jul 29, 2024
### Description

This fixes some problems when `export * from "client component"`, as
`"use client"` creates a non-enumerable Proxy object, so we need to
really redirect property access.

* `__turbopack_export_namespace__` counts as dynamic
* use Proxy to correctly reexport non-enumerable or changing objects

---------

Co-authored-by: Alex Kirszenberg <alex.kirszenberg@vercel.com>
ForsakenHarmony pushed a commit to vercel/next.js that referenced this pull request Aug 1, 2024
### Description

This fixes some problems when `export * from "client component"`, as
`"use client"` creates a non-enumerable Proxy object, so we need to
really redirect property access.

* `__turbopack_export_namespace__` counts as dynamic
* use Proxy to correctly reexport non-enumerable or changing objects

---------

Co-authored-by: Alex Kirszenberg <alex.kirszenberg@vercel.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.

3 participants