-
-
Notifications
You must be signed in to change notification settings - Fork 7.2k
Labels
Description
Describe the bug
For HMR, Vite removes styles using prune event, but this is currently triggered only when an import is removed from a module which has import.meta.hot
.
vite/packages/vite/src/node/plugins/importAnalysis.ts
Lines 458 to 462 in bb29b04
// check import.meta usage | |
if (rawUrl === 'import.meta') { | |
const prop = source.slice(end, end + 4) | |
if (prop === '.hot') { | |
hasHMR = true |
vite/packages/vite/src/node/plugins/importAnalysis.ts
Lines 829 to 840 in 84079a8
const prunedImports = await moduleGraph.updateModuleInfo( | |
importerModule, | |
importedUrls, | |
importedBindings, | |
normalizedAcceptedUrls, | |
isPartiallySelfAccepting ? acceptedExports : null, | |
isSelfAccepting, | |
staticImportedUrls, | |
) | |
if (hasHMR && prunedImports) { | |
handlePrunedModules(prunedImports, environment) | |
} |
This can causes an issue where style removal doesn't happen when modifying non-self-accepting module, for example:
app.jsx -> dep2.js -> test.css
app.jsx : self accepting
dep2.js : not self accepting <- modifying this file to remove test.css import doesn't prune style
Reproduction
https://stackblitz.com/github/hi-ogawa/reproductions/tree/main/vite-prune-css?file=src%2Fdep2.js
Steps to reproduce
- open stackblitz
- observe orange text
- comment out
import "./test.css"
fromsrc/dep2.js
- still text is orange
- reload window
- now text is black
System Info
System:
OS: Linux 5.0 undefined
CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
Memory: 0 Bytes / 0 Bytes
Shell: 1.0 - /bin/jsh
Binaries:
Node: 20.19.1 - /usr/local/bin/node
Yarn: 1.22.19 - /usr/local/bin/yarn
npm: 10.8.2 - /usr/local/bin/npm
pnpm: 8.15.6 - /usr/local/bin/pnpm
npmPackages:
@vitejs/plugin-react: ^5.0.0 => 5.0.2
vite: ^7.1.2 => 7.1.5
Used Package Manager
pnpm
Logs
No response
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to vuejs/core instead.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.