Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(css): page reload was not happening with .css?raw #16455

Merged
merged 2 commits into from May 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/vite/src/node/plugins/importAnalysis.ts
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
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