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

css modules: use a terser selector format that requires less escaping #3437

Merged
merged 1 commit into from Jan 31, 2023

Conversation

wbinnssmith
Copy link
Member

@wbinnssmith wbinnssmith commented Jan 23, 2023

Fixes WEB-447.

Previously, generated classnames would include literal / characters, which need escaping when generating selectors. While users should still escape selectors, this avoids it for this case and makes generated code easier to read. This format is also more aligned with what webpack-based css modules generates.

This also removes the square character as a separator, since it breaks words and makes double-clicking for selection more difficult.

@vercel
Copy link

vercel bot commented Jan 23, 2023

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

Name Status Preview Comments Updated
examples-tailwind-web 🔄 Building (Inspect) Visit Preview Jan 24, 2023 at 5:34PM (UTC)
turbo-site ✅ Ready (Inspect) Visit Preview 💬 Add your feedback Jan 24, 2023 at 5:34PM (UTC)
9 Ignored Deployments
Name Status Preview Comments Updated
examples-basic-web ⬜️ Ignored (Inspect) Jan 24, 2023 at 5:34PM (UTC)
examples-cra-web ⬜️ Ignored (Inspect) Jan 24, 2023 at 5:34PM (UTC)
examples-designsystem-docs ⬜️ Ignored (Inspect) Jan 24, 2023 at 5:34PM (UTC)
examples-kitchensink-blog ⬜️ Ignored (Inspect) Jan 24, 2023 at 5:34PM (UTC)
examples-native-web ⬜️ Ignored (Inspect) Jan 24, 2023 at 5:34PM (UTC)
examples-nonmonorepo ⬜️ Ignored (Inspect) Jan 24, 2023 at 5:34PM (UTC)
examples-svelte-web ⬜️ Ignored (Inspect) Jan 24, 2023 at 5:34PM (UTC)
examples-vite-web ⬜️ Ignored (Inspect) Jan 24, 2023 at 5:34PM (UTC)
turbo-vite-web ⬜️ Ignored (Inspect) Jan 24, 2023 at 5:34PM (UTC)

@github-actions
Copy link
Contributor

Benchmark for 6f304ee

Click to view benchmark
Test Base PR % Significant %
bench_hmr_to_commit/Turbopack CSR/1000 modules 8154.36µs ± 47.85µs 8122.08µs ± 44.07µs -0.40%
bench_hmr_to_commit/Turbopack RCC/1000 modules 8343.25µs ± 65.89µs 8479.75µs ± 87.76µs +1.64%
bench_hmr_to_commit/Turbopack RSC/1000 modules 463.97ms ± 1.80ms 465.05ms ± 2.49ms +0.23%
bench_hmr_to_commit/Turbopack SSR/1000 modules 8217.63µs ± 66.30µs 8335.23µs ± 33.58µs +1.43%
bench_hmr_to_eval/Turbopack CSR/1000 modules 7248.60µs ± 35.77µs 7281.07µs ± 72.81µs +0.45%
bench_hmr_to_eval/Turbopack RCC/1000 modules 7348.06µs ± 54.43µs 7387.08µs ± 61.40µs +0.53%
bench_hmr_to_eval/Turbopack SSR/1000 modules 7477.10µs ± 130.07µs 7337.42µs ± 52.57µs -1.87%
bench_hydration/Turbopack RCC/1000 modules 3431.07ms ± 9.99ms 3435.32ms ± 18.07ms +0.12%
bench_hydration/Turbopack RSC/1000 modules 2860.07ms ± 10.44ms 2874.92ms ± 7.63ms +0.52%
bench_hydration/Turbopack SSR/1000 modules 2677.67ms ± 10.07ms 2683.75ms ± 10.93ms +0.23%
bench_startup/Turbopack CSR/1000 modules 1667.44ms ± 6.81ms 1654.54ms ± 5.55ms -0.77%
bench_startup/Turbopack RCC/1000 modules 2551.83ms ± 7.03ms 2565.05ms ± 11.15ms +0.52%
bench_startup/Turbopack RSC/1000 modules 2434.73ms ± 9.22ms 2445.23ms ± 10.10ms +0.43%
bench_startup/Turbopack SSR/1000 modules 2105.25ms ± 6.65ms 2101.60ms ± 4.95ms -0.17%

@wbinnssmith wbinnssmith force-pushed the wbinnssmith/css-modules-simplify-classname branch from b18df50 to 81a23e4 Compare January 23, 2023 21:33
@github-actions
Copy link
Contributor

github-actions bot commented Jan 23, 2023

🟢 CI successful 🟢

Thanks

@@ -31,3 +31,8 @@ turbopack-env = { path = "../turbopack-env" }

[build-dependencies]
turbo-tasks-build = { path = "../turbo-tasks-build" }

[features]
Copy link
Member Author

Choose a reason for hiding this comment

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

Added this section so cargo test -p turbopack-tests is possible. cc @kwonoj

@github-actions
Copy link
Contributor

Benchmark for ba33241

Click to view benchmark
Test Base PR % Significant %
bench_hmr_to_commit/Turbopack CSR/1000 modules 8026.82µs ± 97.89µs 8076.45µs ± 50.61µs +0.62%
bench_hmr_to_commit/Turbopack RCC/1000 modules 8214.68µs ± 57.68µs 8226.19µs ± 56.00µs +0.14%
bench_hmr_to_commit/Turbopack RSC/1000 modules 444.49ms ± 1.99ms 446.22ms ± 2.27ms +0.39%
bench_hmr_to_commit/Turbopack SSR/1000 modules 8139.99µs ± 56.31µs 8108.03µs ± 41.74µs -0.39%
bench_hmr_to_eval/Turbopack CSR/1000 modules 7067.90µs ± 65.80µs 7046.76µs ± 42.27µs -0.30%
bench_hmr_to_eval/Turbopack RCC/1000 modules 7171.97µs ± 59.95µs 7142.50µs ± 53.36µs -0.41%
bench_hmr_to_eval/Turbopack SSR/1000 modules 7150.48µs ± 66.00µs 7181.87µs ± 91.80µs +0.44%
bench_hydration/Turbopack RCC/1000 modules 3318.93ms ± 10.50ms 3296.15ms ± 12.48ms -0.69%
bench_hydration/Turbopack RSC/1000 modules 2769.65ms ± 5.87ms 2770.79ms ± 11.42ms +0.04%
bench_hydration/Turbopack SSR/1000 modules 2565.64ms ± 7.32ms 2575.18ms ± 4.74ms +0.37%
bench_startup/Turbopack CSR/1000 modules 1621.99ms ± 5.42ms 1606.56ms ± 6.84ms -0.95%
bench_startup/Turbopack RCC/1000 modules 2454.92ms ± 9.81ms 2452.85ms ± 7.77ms -0.08%
bench_startup/Turbopack RSC/1000 modules 2333.30ms ± 8.56ms 2351.28ms ± 8.32ms +0.77%
bench_startup/Turbopack SSR/1000 modules 2026.85ms ± 3.82ms 2027.99ms ± 5.74ms +0.06%

@wbinnssmith wbinnssmith force-pushed the wbinnssmith/css-modules-simplify-classname branch from 075a54c to 0a13e5c Compare January 24, 2023 01:14
@github-actions
Copy link
Contributor

Benchmark for 81c90e8

Test Base PR % Significant %
bench_hydration/Turbopack RSC/1000 modules 2811.89ms ± 11.08ms 2884.03ms ± 11.91ms +2.57% +0.92%
bench_hydration/Turbopack SSR/1000 modules 2667.73ms ± 19.10ms 2600.19ms ± 11.16ms -2.53% -0.27%
bench_startup/Turbopack CSR/1000 modules 1628.15ms ± 7.36ms 1598.38ms ± 4.70ms -1.83% -0.35%
Click to view full benchmark
Test Base PR % Significant %
bench_hmr_to_commit/Turbopack CSR/1000 modules 8193.63µs ± 75.87µs 8192.99µs ± 72.84µs -0.01%
bench_hmr_to_commit/Turbopack RCC/1000 modules 7945.39µs ± 73.07µs 8009.06µs ± 69.82µs +0.80%
bench_hmr_to_commit/Turbopack RSC/1000 modules 443.36ms ± 3.76ms 443.06ms ± 2.12ms -0.07%
bench_hmr_to_commit/Turbopack SSR/1000 modules 8305.03µs ± 71.70µs 8332.48µs ± 130.70µs +0.33%
bench_hmr_to_eval/Turbopack CSR/1000 modules 6981.71µs ± 94.76µs 6898.61µs ± 136.97µs -1.19%
bench_hmr_to_eval/Turbopack RCC/1000 modules 7327.87µs ± 63.16µs 7277.62µs ± 38.61µs -0.69%
bench_hmr_to_eval/Turbopack SSR/1000 modules 7272.88µs ± 93.46µs 7451.73µs ± 63.68µs +2.46%
bench_hydration/Turbopack RCC/1000 modules 3308.96ms ± 9.37ms 3354.34ms ± 16.39ms +1.37%
bench_hydration/Turbopack RSC/1000 modules 2811.89ms ± 11.08ms 2884.03ms ± 11.91ms +2.57% +0.92%
bench_hydration/Turbopack SSR/1000 modules 2667.73ms ± 19.10ms 2600.19ms ± 11.16ms -2.53% -0.27%
bench_startup/Turbopack CSR/1000 modules 1628.15ms ± 7.36ms 1598.38ms ± 4.70ms -1.83% -0.35%
bench_startup/Turbopack RCC/1000 modules 2500.01ms ± 16.59ms 2510.83ms ± 17.93ms +0.43%
bench_startup/Turbopack RSC/1000 modules 2357.07ms ± 10.04ms 2368.46ms ± 4.25ms +0.48%
bench_startup/Turbopack SSR/1000 modules 2047.77ms ± 5.52ms 2078.58ms ± 14.72ms +1.50%

@github-actions
Copy link
Contributor

Benchmark for 42ba4a0

Click to view benchmark
Test Base PR % Significant %
bench_hmr_to_commit/Turbopack CSR/1000 modules 7042.05µs ± 62.13µs 7056.12µs ± 45.44µs +0.20%
bench_hmr_to_commit/Turbopack RCC/1000 modules 7456.58µs ± 65.65µs 7467.99µs ± 111.91µs +0.15%
bench_hmr_to_commit/Turbopack RSC/1000 modules 419.52ms ± 2.12ms 422.39ms ± 1.38ms +0.68%
bench_hmr_to_commit/Turbopack SSR/1000 modules 7311.72µs ± 50.89µs 7468.92µs ± 78.98µs +2.15%
bench_hmr_to_eval/Turbopack CSR/1000 modules 6428.77µs ± 56.06µs 6378.89µs ± 26.93µs -0.78%
bench_hmr_to_eval/Turbopack RCC/1000 modules 6527.65µs ± 52.99µs 6579.69µs ± 76.86µs +0.80%
bench_hmr_to_eval/Turbopack SSR/1000 modules 6490.63µs ± 66.73µs 6522.36µs ± 99.83µs +0.49%
bench_hydration/Turbopack RCC/1000 modules 3218.25ms ± 9.73ms 3204.48ms ± 8.22ms -0.43%
bench_hydration/Turbopack RSC/1000 modules 2691.03ms ± 5.32ms 2694.92ms ± 9.25ms +0.14%
bench_hydration/Turbopack SSR/1000 modules 2496.75ms ± 8.60ms 2514.76ms ± 10.10ms +0.72%
bench_startup/Turbopack CSR/1000 modules 1595.57ms ± 4.13ms 1583.91ms ± 11.85ms -0.73%
bench_startup/Turbopack RCC/1000 modules 2090.70ms ± 3.41ms 2093.05ms ± 6.06ms +0.11%
bench_startup/Turbopack RSC/1000 modules 1986.18ms ± 5.06ms 1994.44ms ± 9.66ms +0.42%
bench_startup/Turbopack SSR/1000 modules 1703.06ms ± 4.50ms 1710.53ms ± 4.99ms +0.44%

Copy link
Member

@ForsakenHarmony ForsakenHarmony left a comment

Choose a reason for hiding this comment

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

next uses filename_class__hash, haven't checked node_modules

Copy link
Member

@sokra sokra left a comment

Choose a reason for hiding this comment

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

I don't like this change. Before it was obvious from a class name from which source file it comes from. Now this is no longer the case.

I don't see the benefit of reading generated code, since the user will never read it anyway. It's source mapped and links to the source will point to the original css. Instead they might read the html or Dom where escaping is not required.

But I see the escaping problem on front. How about using the current content but converting it to a escape free format e.g. by using underscores, or using our magic identifier encoding

@ForsakenHarmony
Copy link
Member

ForsakenHarmony commented Jan 25, 2023

@sokra readability of the classes in the HTML tree is terrible when there are multiple classes applied to one element

maybe we can add some configuration

@jridgewell
Copy link
Contributor

I agree with making the change to a smaller classname.

Before it was obvious from a class name from which source file it comes from. Now this is no longer the case.

I don't see the benefit of reading generated code, since the user will never read it anyway. It's source mapped and links to the source will point to the original css. Instead they might read the html or Dom where escaping is not required.

The users see generated code in the DOM tree. Having such long classnames is overwhelming. And the ability to associate a classname with the file is still there, you just need to click the classname int the style panel to open up the defining file.

@mehulkar mehulkar removed their request for review January 31, 2023 01:05
@wbinnssmith wbinnssmith merged commit b808695 into main Jan 31, 2023
@wbinnssmith wbinnssmith deleted the wbinnssmith/css-modules-simplify-classname branch January 31, 2023 18:13
wbinnssmith added a commit that referenced this pull request Feb 1, 2023
#3437 wasn't up to date with main when it was merged.

Test Plan: CI
mehulkar pushed a commit that referenced this pull request Feb 1, 2023
#3437 wasn't up to date with main when it was merged.

Test Plan: CI
wbinnssmith added a commit to vercel/next.js that referenced this pull request Mar 1, 2023
Turbopack uses a different format for its css module classnames [0]. This adds and uses a helper function to the next-font tests to assert against these classnames when testing with Turbopack. Ideally these tests could be more behavioral (e.g. asserting on rendered dimensions), but these can't capture things like fallback fonts.

[0] vercel/turbo#3437
timneutkens pushed a commit to vercel/next.js that referenced this pull request Mar 6, 2023
Turbopack uses a different format for its css module classnames [0].
This adds and uses a helper function to the next-font tests to assert
against these classnames when testing with Turbopack. Ideally these
tests could be more behavioral (e.g. asserting on rendered dimensions),
but these can't capture things like fallback fonts.

[0] vercel/turbo#3437
jridgewell pushed a commit to vercel/next.js that referenced this pull request Mar 10, 2023
…vercel/turbo#3437)

Fixes WEB-447.

Previously, generated classnames would include literal `/` characters,
which need escaping when generating selectors. While users should still
escape selectors, this avoids it for this case and makes generated code
easier to read. This format is also more aligned with what webpack-based
css modules generates.

This also removes the square character as a separator, since it breaks
words and makes double-clicking for selection more difficult.
sokra pushed a commit to vercel/next.js that referenced this pull request Mar 13, 2023
…vercel/turbo#3437)

Fixes WEB-447.

Previously, generated classnames would include literal `/` characters,
which need escaping when generating selectors. While users should still
escape selectors, this avoids it for this case and makes generated code
easier to read. This format is also more aligned with what webpack-based
css modules generates.

This also removes the square character as a separator, since it breaks
words and makes double-clicking for selection more difficult.
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.

None yet

4 participants