-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow vite to refer to inlined CSS (#8351)
* fix(client build): keep inlined stylesheets * add changesets * appease linter * eslint: allow variables beginning with an underscore to be unused * remove eslint-ignore that's no longer needed * ready for review
- Loading branch information
Showing
16 changed files
with
118 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'astro': patch | ||
--- | ||
|
||
Fixed a case where dynamic imports tried to preload inlined stylesheets. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@astrojs/svelte': patch | ||
--- | ||
|
||
Removed vite warnings. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { expect } from 'chai'; | ||
import { loadFixture } from './test-utils.js'; | ||
|
||
const cssAssetReferenceRegExp = /_astro\/[A-Za-z0-9\-]+\.[a0-9a-f]{8}\.css/g | ||
|
||
describe("When Vite's preloadModule polyfill is used", async () => { | ||
|
||
let fixture; | ||
|
||
before(async () => { | ||
fixture = await loadFixture({ | ||
root: './fixtures/css-dangling-references/' | ||
}); | ||
await fixture.build(); | ||
}); | ||
|
||
it('there are no references to deleted CSS chunks', async () => { | ||
|
||
const fileNames = await fixture.readdir('/_astro/') | ||
const filePaths = fileNames.map(filename => '_astro/' + filename) | ||
|
||
const expectations = | ||
filePaths | ||
.filter(filePath => filePath.endsWith('js')) | ||
.map(async filePath => { | ||
const contents = await fixture.readFile(filePath) | ||
const cssReferences = contents.match(cssAssetReferenceRegExp) | ||
|
||
if (cssReferences === null) return | ||
|
||
expect(filePaths).to.contain.members(cssReferences, filePath + ' contains a reference to a deleted css asset: ' + cssReferences) | ||
}) | ||
|
||
await Promise.all(expectations) | ||
}) | ||
}) |
8 changes: 8 additions & 0 deletions
8
packages/astro/test/fixtures/css-dangling-references/astro.config.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { defineConfig } from 'astro/config'; | ||
import svelte from '@astrojs/svelte'; | ||
|
||
// https://astro.build/config | ||
export default defineConfig({ | ||
integrations: [svelte()], | ||
}); | ||
|
11 changes: 11 additions & 0 deletions
11
packages/astro/test/fixtures/css-dangling-references/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"name": "@test/css-dangling-references", | ||
"version": "0.0.0", | ||
"private": true, | ||
"dependencies": { | ||
"astro": "workspace:*", | ||
"@astrojs/svelte": "workspace:*", | ||
"svelte": "4" | ||
} | ||
} | ||
|
6 changes: 6 additions & 0 deletions
6
...test/fixtures/css-dangling-references/src/components/DynamicallyImportedComponent1.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<style> | ||
h1 { | ||
background-color: gold; | ||
} | ||
</style> | ||
<h1>This sentence should have a gold background.</h1> |
6 changes: 6 additions & 0 deletions
6
...test/fixtures/css-dangling-references/src/components/DynamicallyImportedComponent2.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<style> | ||
p { | ||
background-color: lavender; | ||
} | ||
</style> | ||
<p>This sentence should have a lavender background color.</p> |
15 changes: 15 additions & 0 deletions
15
packages/astro/test/fixtures/css-dangling-references/src/components/Wrapper.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<script> | ||
export let path | ||
const allAppModules = import.meta.glob('./*.svelte') | ||
const AppModule = Object.entries(allAppModules).find( | ||
([key]) => key.includes(path) | ||
)[1] | ||
</script> | ||
|
||
{#await AppModule() then Mod} | ||
<Mod.default /> | ||
{/await} |
4 changes: 4 additions & 0 deletions
4
packages/astro/test/fixtures/css-dangling-references/src/pages/glob-import-1.astro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
import Wrapper from "../components/Wrapper.svelte" | ||
--- | ||
<Wrapper path="1" client:load/> |
5 changes: 5 additions & 0 deletions
5
packages/astro/test/fixtures/css-dangling-references/src/pages/glob-import-2.astro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
import Wrapper from "../components/Wrapper.svelte" | ||
--- | ||
<Wrapper path="2" client:load/> | ||
|
2 changes: 1 addition & 1 deletion
2
packages/astro/test/fixtures/css-inline-stylesheets/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.