From d20fd5e167706f82aba23365c1e679a07785f135 Mon Sep 17 00:00:00 2001 From: sapphi-red <49056869+sapphi-red@users.noreply.github.com> Date: Fri, 19 Apr 2024 01:32:11 +0900 Subject: [PATCH] fix(css): page reload was not happening with .css?raw --- packages/vite/src/node/plugins/importAnalysis.ts | 4 +++- playground/css/__tests__/css.spec.ts | 10 ++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/vite/src/node/plugins/importAnalysis.ts b/packages/vite/src/node/plugins/importAnalysis.ts index db8256ec3d9bbb..e145121d0310fd 100644 --- a/packages/vite/src/node/plugins/importAnalysis.ts +++ b/packages/vite/src/node/plugins/importAnalysis.ts @@ -18,6 +18,7 @@ import { CLIENT_PUBLIC_PATH, DEP_VERSION_RE, FS_PREFIX, + SPECIAL_QUERY_RE, } from '../constants' import { debugHmr, @@ -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 diff --git a/playground/css/__tests__/css.spec.ts b/playground/css/__tests__/css.spec.ts index c0efb130bf00f9..cb7af939bbd152 100644 --- a/playground/css/__tests__/css.spec.ts +++ b/playground/css/__tests__/css.spec.ts @@ -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 () => {