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

Add support for CSS client references #5397

Merged
merged 8 commits into from
Jul 4, 2023

Conversation

alexkirsz
Copy link
Contributor

@alexkirsz alexkirsz commented Jun 27, 2023

Description

This PR changes CSS assets to support the CSS client references use case of Next.js, where .css assets in the RSC graph should be replaced with a client reference assets.

CSS assets are now processed in two steps:

  1. Processing the CSS source asset into either a Global or a Module CSS asset.
  2. Inside of Global/Module assets, processing the CSS source asset into a CSS asset.

By default, (2.) will create a leaf CSS asset. But in Next.js RSC, this step will be replaced with creating a CSS client reference instead. This client reference can then be detected when walking the RSC graph, and a client CSS chunk can be produced from there.

Testing Instructions

N/A

@alexkirsz alexkirsz requested a review from a team as a code owner June 27, 2023 12:05
@vercel
Copy link

vercel bot commented Jun 27, 2023

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

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

@alexkirsz
Copy link
Contributor Author

alexkirsz commented Jun 27, 2023

@github-actions
Copy link
Contributor

github-actions bot commented Jun 27, 2023

✅ This change can build next-swc

@github-actions
Copy link
Contributor

github-actions bot commented Jun 27, 2023

🟢 CI successful 🟢

Thanks

@alexkirsz alexkirsz force-pushed the alexkirsz/web-866-css-client-references branch from c8daa18 to ed15812 Compare June 27, 2023 12:31
crates/turbopack-css/src/module_asset.rs Outdated Show resolved Hide resolved
crates/turbopack-css/src/module_asset.rs Outdated Show resolved Hide resolved
crates/turbopack-css/src/module_asset.rs Outdated Show resolved Hide resolved
#[turbo_tasks::value]
#[derive(Hash, Debug)]
pub struct InternalCssAssetReference {
asset: AssetVc,
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
asset: AssetVc,
source: AssetVc,
context: AssetContextVc,

This should lazily process the source asset

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The asset will already have been processed at that point, as we need to process it to compute other references.

crates/turbopack/src/module_options/mod.rs Outdated Show resolved Hide resolved
CssModule(CssInputTransformsVc),
CssGlobal,
CssModule,
Css {
Copy link
Member

Choose a reason for hiding this comment

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

Should we rename to CssInner

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think CssGlobal and CssModule are explicit enough that Css on its own is OK.

@alexkirsz alexkirsz force-pushed the alexkirsz/web-866-fix-rebase-error branch from 512d3f1 to 12903ee Compare June 27, 2023 13:58
@alexkirsz alexkirsz force-pushed the alexkirsz/web-866-css-client-references branch from ed15812 to 81d7fbf Compare June 27, 2023 13:58
Base automatically changed from alexkirsz/web-866-fix-rebase-error to alexkirsz/web-866-fspath-extensions June 28, 2023 17:46
@alexkirsz alexkirsz force-pushed the alexkirsz/web-866-fspath-extensions branch from e195ea7 to f5b8530 Compare July 3, 2023 11:27
@alexkirsz alexkirsz force-pushed the alexkirsz/web-866-css-client-references branch from 81d7fbf to c433a30 Compare July 3, 2023 11:27
@github-actions
Copy link
Contributor

github-actions bot commented Jul 3, 2023

Linux Benchmark for 05be8df

Click to view benchmark
Test Base PR % Significant %
bench_hmr_to_commit/Turbopack CSR/1000 modules 5854.54µs ± 16.26µs 5835.99µs ± 23.04µs -0.32%
bench_hmr_to_eval/Turbopack CSR/1000 modules 5469.70µs ± 34.70µs 5667.78µs ± 233.63µs +3.62%
bench_startup/Turbopack CSR/1000 modules 911.97ms ± 0.75ms 914.85ms ± 4.51ms +0.32%

@github-actions
Copy link
Contributor

github-actions bot commented Jul 3, 2023

MacOS Benchmark for 05be8df

Test Base PR % Significant %
bench_hmr_to_commit/Turbopack CSR/1000 modules 28.74ms ± 0.08ms 29.23ms ± 0.12ms +1.73% +0.34%
bench_hmr_to_eval/Turbopack CSR/1000 modules 28.40ms ± 0.09ms 27.85ms ± 0.12ms -1.96% -0.48%
Click to view full benchmark
Test Base PR % Significant %
bench_hmr_to_commit/Turbopack CSR/1000 modules 28.74ms ± 0.08ms 29.23ms ± 0.12ms +1.73% +0.34%
bench_hmr_to_eval/Turbopack CSR/1000 modules 28.40ms ± 0.09ms 27.85ms ± 0.12ms -1.96% -0.48%
bench_startup/Turbopack CSR/1000 modules 3749.56ms ± 151.51ms 3768.38ms ± 121.13ms +0.50%

@alexkirsz alexkirsz force-pushed the alexkirsz/web-866-css-client-references branch from f7625f3 to 4f392bd Compare July 3, 2023 12:52
@alexkirsz alexkirsz force-pushed the alexkirsz/web-866-fspath-extensions branch from 74ada12 to fcbb760 Compare July 3, 2023 13:25
@alexkirsz alexkirsz force-pushed the alexkirsz/web-866-css-client-references branch from 4f392bd to 9487de0 Compare July 3, 2023 13:25
Base automatically changed from alexkirsz/web-866-fspath-extensions to main July 3, 2023 13:38
@github-actions
Copy link
Contributor

github-actions bot commented Jul 3, 2023

Linux Benchmark for b0429e1

Click to view benchmark
Test Base PR % Significant %
bench_hmr_to_commit/Turbopack CSR/1000 modules 5829.93µs ± 39.80µs 5867.48µs ± 24.34µs +0.64%
bench_hmr_to_eval/Turbopack CSR/1000 modules 5477.53µs ± 41.49µs 5561.46µs ± 83.39µs +1.53%
bench_startup/Turbopack CSR/1000 modules 908.65ms ± 2.42ms 917.91ms ± 6.36ms +1.02%

@alexkirsz alexkirsz force-pushed the alexkirsz/web-866-css-client-references branch from 9487de0 to 6419597 Compare July 3, 2023 13:43
@github-actions
Copy link
Contributor

github-actions bot commented Jul 3, 2023

Linux Benchmark for fe4e6b3

Click to view benchmark
Test Base PR % Significant %
bench_hmr_to_commit/Turbopack CSR/1000 modules 5870.39µs ± 43.11µs 5814.50µs ± 27.49µs -0.95%
bench_hmr_to_eval/Turbopack CSR/1000 modules 5504.27µs ± 20.15µs 5606.45µs ± 67.49µs +1.86%
bench_startup/Turbopack CSR/1000 modules 914.30ms ± 2.34ms 914.99ms ± 2.37ms +0.08%

@github-actions
Copy link
Contributor

github-actions bot commented Jul 3, 2023

MacOS Benchmark for fe4e6b3

Test Base PR % Significant %
bench_hmr_to_commit/Turbopack CSR/1000 modules 28.87ms ± 0.12ms 28.30ms ± 0.11ms -1.98% -0.38%
bench_startup/Turbopack CSR/1000 modules 9152.22ms ± 1973.53ms 3687.48ms ± 83.35ms -59.71% -25.95%
Click to view full benchmark
Test Base PR % Significant %
bench_hmr_to_commit/Turbopack CSR/1000 modules 28.87ms ± 0.12ms 28.30ms ± 0.11ms -1.98% -0.38%
bench_hmr_to_eval/Turbopack CSR/1000 modules 27.79ms ± 0.13ms 27.85ms ± 0.20ms +0.22%
bench_startup/Turbopack CSR/1000 modules 9152.22ms ± 1973.53ms 3687.48ms ± 83.35ms -59.71% -25.95%

@github-actions
Copy link
Contributor

github-actions bot commented Jul 4, 2023

Linux Benchmark for 320cc3f

Click to view benchmark
Test Base PR % Significant %
bench_hmr_to_commit/Turbopack CSR/1000 modules 10.75ms ± 0.06ms 10.84ms ± 0.07ms +0.82%
bench_hmr_to_eval/Turbopack CSR/1000 modules 10.10ms ± 0.06ms 10.16ms ± 0.20ms +0.60%
bench_startup/Turbopack CSR/1000 modules 1113.94ms ± 1.92ms 1122.26ms ± 5.78ms +0.75%

@github-actions
Copy link
Contributor

github-actions bot commented Jul 4, 2023

MacOS Benchmark for 320cc3f

Test Base PR % Significant %
bench_startup/Turbopack CSR/1000 modules 4115.76ms ± 299.49ms 9388.35ms ± 2009.04ms +128.11% +13.90%
Click to view full benchmark
Test Base PR % Significant %
bench_hmr_to_commit/Turbopack CSR/1000 modules 28.51ms ± 0.18ms 28.57ms ± 0.09ms +0.20%
bench_hmr_to_eval/Turbopack CSR/1000 modules 27.70ms ± 0.11ms 26.89ms ± 0.45ms -2.93%
bench_startup/Turbopack CSR/1000 modules 4115.76ms ± 299.49ms 9388.35ms ± 2009.04ms +128.11% +13.90%

@alexkirsz alexkirsz merged commit c26e60b into main Jul 4, 2023
@alexkirsz alexkirsz deleted the alexkirsz/web-866-css-client-references branch July 4, 2023 12:07
@github-actions
Copy link
Contributor

github-actions bot commented Jul 4, 2023

Linux Benchmark for 1fa6952

Click to view benchmark
Test Base PR % Significant %
bench_hmr_to_commit/Turbopack CSR/1000 modules 11.76ms ± 0.10ms 11.70ms ± 0.09ms -0.50%
bench_hmr_to_eval/Turbopack CSR/1000 modules 10.91ms ± 0.06ms 10.95ms ± 0.21ms +0.34%
bench_startup/Turbopack CSR/1000 modules 1202.45ms ± 3.46ms 1194.06ms ± 7.47ms -0.70%

kodiakhq bot pushed a commit to vercel/next.js that referenced this pull request Jul 4, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Jul 4, 2023

MacOS Benchmark for 1fa6952

Test Base PR % Significant %
bench_hmr_to_eval/Turbopack CSR/1000 modules 28.33ms ± 0.12ms 27.47ms ± 0.29ms -3.05% -0.17%
Click to view full benchmark
Test Base PR % Significant %
bench_hmr_to_commit/Turbopack CSR/1000 modules 28.66ms ± 0.24ms 29.02ms ± 0.10ms +1.26%
bench_hmr_to_eval/Turbopack CSR/1000 modules 28.33ms ± 0.12ms 27.47ms ± 0.29ms -3.05% -0.17%
bench_startup/Turbopack CSR/1000 modules 4016.51ms ± 18.55ms 4138.20ms ± 122.53ms +3.03%

sokra pushed a commit that referenced this pull request Jul 4, 2023
### Description

My recent change in #5397 added a way to create rules that only apply to
internal references. In the process, I also made it so the default rules
don't apply to internal references as well. However, we still need them
to apply to TS and JS files, as we use that with ReferenceType::Internal
in Next.js.

### Testing Instructions

Next.js CI
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 PR changes CSS assets to support the CSS client references use case
of Next.js, where .css assets in the RSC graph should be replaced with a
client reference assets.

CSS assets are now processed in two steps:
1. Processing the CSS source asset into either a Global or a Module CSS
asset.
2. Inside of Global/Module assets, processing the CSS source asset into
a CSS asset.

By default, (2.) will create a leaf CSS asset. But in Next.js RSC, this
step will be replaced with creating a CSS client reference instead. This
client reference can then be detected when walking the RSC graph, and a
client CSS chunk can be produced from there.

### Testing Instructions

N/A
ForsakenHarmony pushed a commit to vercel/next.js that referenced this pull request Jul 25, 2024
)

### Description

My recent change in vercel/turborepo#5397 added a way to create rules that only apply to
internal references. In the process, I also made it so the default rules
don't apply to internal references as well. However, we still need them
to apply to TS and JS files, as we use that with ReferenceType::Internal
in Next.js.

### Testing Instructions

Next.js CI
ForsakenHarmony pushed a commit to vercel/next.js that referenced this pull request Jul 29, 2024
### Description

This PR changes CSS assets to support the CSS client references use case
of Next.js, where .css assets in the RSC graph should be replaced with a
client reference assets.

CSS assets are now processed in two steps:
1. Processing the CSS source asset into either a Global or a Module CSS
asset.
2. Inside of Global/Module assets, processing the CSS source asset into
a CSS asset.

By default, (2.) will create a leaf CSS asset. But in Next.js RSC, this
step will be replaced with creating a CSS client reference instead. This
client reference can then be detected when walking the RSC graph, and a
client CSS chunk can be produced from there.

### Testing Instructions

N/A
ForsakenHarmony pushed a commit to vercel/next.js that referenced this pull request Jul 29, 2024
)

### Description

My recent change in vercel/turborepo#5397 added a way to create rules that only apply to
internal references. In the process, I also made it so the default rules
don't apply to internal references as well. However, we still need them
to apply to TS and JS files, as we use that with ReferenceType::Internal
in Next.js.

### Testing Instructions

Next.js CI
ForsakenHarmony pushed a commit to vercel/next.js that referenced this pull request Aug 1, 2024
### Description

This PR changes CSS assets to support the CSS client references use case
of Next.js, where .css assets in the RSC graph should be replaced with a
client reference assets.

CSS assets are now processed in two steps:
1. Processing the CSS source asset into either a Global or a Module CSS
asset.
2. Inside of Global/Module assets, processing the CSS source asset into
a CSS asset.

By default, (2.) will create a leaf CSS asset. But in Next.js RSC, this
step will be replaced with creating a CSS client reference instead. This
client reference can then be detected when walking the RSC graph, and a
client CSS chunk can be produced from there.

### Testing Instructions

N/A
ForsakenHarmony pushed a commit to vercel/next.js that referenced this pull request Aug 1, 2024
)

### Description

My recent change in vercel/turborepo#5397 added a way to create rules that only apply to
internal references. In the process, I also made it so the default rules
don't apply to internal references as well. However, we still need them
to apply to TS and JS files, as we use that with ReferenceType::Internal
in Next.js.

### Testing Instructions

Next.js CI
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