Skip to content

Commit 8041846

Browse files
authored
fix(css): page reload was not happening with .css?raw (#16455)
1 parent abf766e commit 8041846

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

packages/vite/src/node/plugins/importAnalysis.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
CLIENT_PUBLIC_PATH,
1919
DEP_VERSION_RE,
2020
FS_PREFIX,
21+
SPECIAL_QUERY_RE,
2122
} from '../constants'
2223
import {
2324
debugHmr,
@@ -743,7 +744,8 @@ export function importAnalysisPlugin(config: ResolvedConfig): Plugin {
743744
// update the module graph for HMR analysis.
744745
// node CSS imports does its own graph update in the css-analysis plugin so we
745746
// only handle js graph updates here.
746-
if (!isCSSRequest(importer)) {
747+
// note that we want to handle .css?raw and .css?url here
748+
if (!isCSSRequest(importer) || SPECIAL_QUERY_RE.test(importer)) {
747749
// attached by pluginContainer.addWatchFile
748750
const pluginImports = (this as any)._addedImports as
749751
| Set<string>

playground/css/__tests__/css.spec.ts

+10
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,16 @@ test('?raw', async () => {
448448
expect(await rawImportCss.textContent()).toBe(
449449
readFileSync(require.resolve('../raw-imported.css'), 'utf-8'),
450450
)
451+
452+
if (!isBuild) {
453+
editFile('raw-imported.css', (code) =>
454+
code.replace('color: yellow', 'color: blue'),
455+
)
456+
await untilUpdated(
457+
() => page.textContent('.raw-imported-css'),
458+
'color: blue',
459+
)
460+
}
451461
})
452462

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

0 commit comments

Comments
 (0)