-
-
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.
Prevent accidental CSS inclusion in dev (#7381)
* Prevent accidental CSS inclusion in dev * Use ssrTransformResult.deps instead * Fix types * Get dynamic deps too * Handle virtual module deps * Fix test on windows
- Loading branch information
Showing
4 changed files
with
90 additions
and
1 deletion.
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 | ||
--- | ||
|
||
Prevent accidental inclusion of page CSS in dev mode |
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,63 @@ | ||
import { expect } from 'chai'; | ||
import { fileURLToPath } from 'url'; | ||
|
||
import { | ||
getStylesForURL | ||
} from '../../../dist/core/render/dev/css.js'; | ||
import { viteID } from '../../../dist/core/util.js'; | ||
|
||
const root = new URL('../../fixtures/alias/', import.meta.url); | ||
|
||
class TestLoader { | ||
constructor(modules) { | ||
this.modules = new Map(modules.map(m => [m.id, m])) | ||
} | ||
getModuleById(id) { | ||
return this.modules.get(id); | ||
} | ||
getModulesByFile(id) { | ||
return this.modules.has(id) ? [this.modules.get(id)] : []; | ||
} | ||
} | ||
|
||
describe('Crawling graph for CSS', () => { | ||
let loader; | ||
before(() => { | ||
const indexId = viteID(new URL('./src/pages/index.astro', root)); | ||
const aboutId = viteID(new URL('./src/pages/about.astro', root)); | ||
loader = new TestLoader([ | ||
{ | ||
id: indexId, | ||
importedModules: [{ | ||
id: aboutId, | ||
url: aboutId, | ||
}, { | ||
id: indexId + '?astro&style.css', | ||
url: indexId + '?astro&style.css', | ||
ssrModule: {} | ||
}], | ||
ssrTransformResult: { | ||
deps: [indexId + '?astro&style.css'] | ||
} | ||
}, | ||
{ | ||
id: aboutId, | ||
importedModules: [{ | ||
id: aboutId + '?astro&style.css', | ||
url: aboutId + '?astro&style.css', | ||
ssrModule: {} | ||
}], | ||
ssrTransformResult: { | ||
deps: [aboutId + '?astro&style.css'] | ||
} | ||
} | ||
]); | ||
}) | ||
|
||
it('importedModules is checked against the child\'s importers', async () => { | ||
// In dev mode, HMR modules tracked are added to importedModules. We use `importers` | ||
// to verify that they are true importers. | ||
const res = await getStylesForURL(new URL('./src/pages/index.astro', root), loader, 'development') | ||
expect(res.urls.size).to.equal(1); | ||
}) | ||
}) |