Skip to content

Commit

Permalink
fix(hmr): html registered as a PostCSS dependency, fix vitejs#3716 (v…
Browse files Browse the repository at this point in the history
  • Loading branch information
y1d7ng authored and aleclarson committed Nov 8, 2021
1 parent 420dae3 commit 50f976b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
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

0 comments on commit 50f976b

Please sign in to comment.