Skip to content

Commit

Permalink
fix(css): page reload was not happening with .css?raw (#16455)
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red committed May 18, 2024
1 parent abf766e commit 8041846
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/vite/src/node/plugins/importAnalysis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
CLIENT_PUBLIC_PATH,
DEP_VERSION_RE,
FS_PREFIX,
SPECIAL_QUERY_RE,
} from '../constants'
import {
debugHmr,
Expand Down Expand Up @@ -743,7 +744,8 @@ export function importAnalysisPlugin(config: ResolvedConfig): Plugin {
// update the module graph for HMR analysis.
// node CSS imports does its own graph update in the css-analysis plugin so we
// only handle js graph updates here.
if (!isCSSRequest(importer)) {
// note that we want to handle .css?raw and .css?url here
if (!isCSSRequest(importer) || SPECIAL_QUERY_RE.test(importer)) {
// attached by pluginContainer.addWatchFile
const pluginImports = (this as any)._addedImports as
| Set<string>
Expand Down
10 changes: 10 additions & 0 deletions playground/css/__tests__/css.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,16 @@ test('?raw', async () => {
expect(await rawImportCss.textContent()).toBe(
readFileSync(require.resolve('../raw-imported.css'), 'utf-8'),
)

if (!isBuild) {
editFile('raw-imported.css', (code) =>
code.replace('color: yellow', 'color: blue'),
)
await untilUpdated(
() => page.textContent('.raw-imported-css'),
'color: blue',
)
}
})

test('import css in less', async () => {
Expand Down

0 comments on commit 8041846

Please sign in to comment.