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(hmr): html registered as a PostCSS dependency, fix #3716 #4127

Merged
merged 1 commit into from Jul 6, 2021
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
2 changes: 1 addition & 1 deletion packages/vite/src/node/plugins/css.ts
Expand Up @@ -81,7 +81,7 @@ export interface CSSModulesOptions {
}

const cssLangs = `\\.(css|less|sass|scss|styl|stylus|pcss|postcss)($|\\?)`
const cssLangRE = new RegExp(cssLangs)
export const cssLangRE = new RegExp(cssLangs)
const cssModuleRE = new RegExp(`\\.module${cssLangs}`)
const directRequestRE = /(\?|&)direct\b/
const commonjsProxyRE = /\?commonjs-proxy/
Expand Down
10 changes: 5 additions & 5 deletions packages/vite/src/node/server/hmr.ts
Expand Up @@ -10,7 +10,7 @@ import { RollupError } from 'rollup'
import { prepareError } from './middlewares/error'
import match from 'minimatch'
import { Server } from 'http'
import { isCSSRequest } from '../plugins/css'
import { cssLangRE } from '../plugins/css'

export const debugHmr = createDebugger('vite:hmr')

Expand Down Expand Up @@ -227,7 +227,7 @@ function propagateUpdate(
// additionally check for CSS importers, since a PostCSS plugin like
// Tailwind JIT may register any file as a dependency to a CSS file.
for (const importer of node.importers) {
if (isCSSRequest(importer.url) && !currentChain.includes(importer)) {
if (cssLangRE.test(importer.url) && !currentChain.includes(importer)) {
propagateUpdate(
importer,
timestamp,
Expand All @@ -243,13 +243,13 @@ function propagateUpdate(
if (!node.importers.size) {
return true
}

// #3716, #3913
// For a non-CSS file, if all of its importers are CSS files (registered via
// PostCSS plugins) it should be considered a dead end and force full reload.
if (
!isCSSRequest(node.url) &&
[...node.importers].every((i) => isCSSRequest(i.url))
!cssLangRE.test(node.url) &&
[...node.importers].every((i) => cssLangRE.test(i.url))
) {
return true
}
Expand Down