From cd009f6be0d2f0115b4dc54680e71f07c48a9b12 Mon Sep 17 00:00:00 2001 From: Philipp Spiess Date: Tue, 12 Nov 2024 18:28:23 +0100 Subject: [PATCH 1/4] Vite: Don't track candidate changes for Svelte ` `, - 'src/components.css': css` - .foo { + 'src/other.css': css` + .local { @apply text-red-500; + animation: 2s ease-in-out 0s infinite localKeyframes; + } + + :global(.global) { + @apply text-green-500; + animation: 2s ease-in-out 0s infinite globalKeyframes; + } + + @keyframes -global-globalKeyframes { + 0% { + opacity: 0; + } + 100% { + opacity: 100%; + } + } + + @keyframes localKeyframes { + 0% { + opacity: 0; + } + 100% { + opacity: 100%; + } } `, }, @@ -74,7 +102,13 @@ test( let files = await fs.glob('dist/**/*.css') expect(files).toHaveLength(1) - await fs.expectFileToContain(files[0][0], [candidate`underline`, candidate`foo`]) + await fs.expectFileToContain(files[0][0], [ + candidate`underline`, + '.global{color:var(--color-green-500);animation:2s ease-in-out 0s infinite globalKeyframes}', + /\.local.svelte-.*\{color:var\(--color-red-500\);animation:2s ease-in-out 0s infinite svelte-.*-localKeyframes\}/, + /@keyframes globalKeyframes\{/, + /@keyframes svelte-.*-localKeyframes\{/, + ]) }, ) @@ -127,20 +161,48 @@ test( `, 'src/App.svelte': html` -

Hello {name}!

+

Hello {name}!

- `, - 'src/components.css': css` - .foo { + 'src/index.css': css` + @import 'tailwindcss/theme' theme(reference); + @import 'tailwindcss/utilities'; + `, + 'src/other.css': css` + .local { @apply text-red-500; + animation: 2s ease-in-out 0s infinite localKeyframes; + } + + :global(.global) { + @apply text-green-500; + animation: 2s ease-in-out 0s infinite globalKeyframes; + } + + @keyframes -global-globalKeyframes { + 0% { + opacity: 0; + } + 100% { + opacity: 100%; + } + } + + @keyframes localKeyframes { + 0% { + opacity: 0; + } + 100% { + opacity: 100%; + } } `, }, @@ -148,30 +210,45 @@ test( async ({ fs, spawn }) => { await spawn(`pnpm vite build --watch`) - let filename = '' await retryAssertion(async () => { let files = await fs.glob('dist/**/*.css') expect(files).toHaveLength(1) - filename = files[0][0] + let [, css] = files[0] + expect(css).toContain(candidate`underline`) + expect(css).toContain( + '.global{color:var(--color-green-500);animation:2s ease-in-out 0s infinite globalKeyframes}', + ) + expect(css).toMatch( + /\.local.svelte-.*\{color:var\(--color-red-500\);animation:2s ease-in-out 0s infinite svelte-.*-localKeyframes\}/, + ) + expect(css).toMatch(/@keyframes globalKeyframes\{/) + expect(css).toMatch(/@keyframes svelte-.*-localKeyframes\{/) }) - await fs.expectFileToContain(filename, [candidate`foo`, candidate`underline`]) + await fs.write( + 'src/App.svelte', + (await fs.read('src/App.svelte')).replace('underline', 'font-bold bar'), + ) await fs.write( - 'src/components.css', - css` - .bar { - @apply text-green-500; - } - `, + 'src/other.css', + `${await fs.read('src/other.css')}\n.bar { @apply text-pink-500; }`, ) + await retryAssertion(async () => { let files = await fs.glob('dist/**/*.css') expect(files).toHaveLength(1) let [, css] = files[0] - expect(css).toContain(candidate`underline`) - expect(css).toContain(candidate`bar`) - expect(css).not.toContain(candidate`foo`) + expect(css).toContain(candidate`font-bold`) + expect(css).toContain( + '.global{color:var(--color-green-500);animation:2s ease-in-out 0s infinite globalKeyframes}', + ) + expect(css).toMatch( + /\.local.svelte-.*\{color:var\(--color-red-500\);animation:2s ease-in-out 0s infinite svelte-.*-localKeyframes\}/, + ) + expect(css).toMatch(/@keyframes globalKeyframes\{/) + expect(css).toMatch(/@keyframes svelte-.*-localKeyframes\{/) + expect(css).toMatch(/\.bar.svelte-.*\{color:var\(--color-pink-500\)\}/) }) }, ) From 7b4f59c58a4d2c11bb81b4b12ef1956b3fc12bde Mon Sep 17 00:00:00 2001 From: Philipp Spiess Date: Wed, 13 Nov 2024 14:58:42 +0100 Subject: [PATCH 3/4] Add changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 52cc9042cc3c..f8f8fb83ecf1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Support opacity values in increments of `0.25` by default ([#14980](https://github.com/tailwindlabs/tailwindcss/pull/14980)) +### Fixed + +- Ensure that CSS inside Svelte `