Skip to content

Conversation

hi-ogawa
Copy link
Contributor

@hi-ogawa hi-ogawa commented Sep 14, 2025

Description

This is a one liner fix to trigger prune event in the case when import.meta.hot doesn't exist in parent module (in which case hasHMR is false). As commented in the test case, this is only a partial fix since it still misses this code path when there are no imports in the parent module. I'll create a separate issue for this and plan to tackle later.

additional context

@vitejs/plugin-rsc checks css import on rsc environment and injects corresponding <link rel="stylesheet" href="(resolved-url)"/>. For rsc environment, import.meta.hot doesn't exist most of the time and I found that prune event is not triggered, which makes it difficult to do auto link removal for vitejs/vite-plugin-react#849.

Copy link

pkg-pr-new bot commented Sep 14, 2025

Open in StackBlitz

npm i https://pkg.pr.new/vite@20768

commit: 7264b09

@hi-ogawa hi-ogawa marked this pull request as ready for review September 16, 2025 02:53
sapphi-red
sapphi-red previously approved these changes Sep 16, 2025
bluwy
bluwy previously approved these changes Sep 17, 2025
Copy link
Member

@bluwy bluwy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm. IIRC dispose also have this issue unless it's in a self-accepted module, or the parent is accepted, but that might be a different fix/issue.

@hi-ogawa
Copy link
Contributor Author

lgtm. IIRC dispose also have this issue unless it's in a self-accepted module, or the parent is accepted, but that might be a different fix/issue.

Good point. I think dispose before prune is fixed now as they are called together in prunePaths. But, dispose before ancestor's accept might be missing in some situation. For the former, I added a test case to verify the behavior.


Also, now I realized the issue still exists when import is removed from modules further up, for example:

index.js : self-accept
index.js ---> dep1.js ---> dep2.js
         ^^^^          
        removing this import triggers "dep1.js" prune but not "dep2.js"

Nonetheless, I think we can proceed with this PR as it extends the ability of prune usage.

@sapphi-red sapphi-red merged commit 9f32b1d into vitejs:main Sep 22, 2025
17 checks passed
renovate bot added a commit to andrei-picus-tink/auto-renovate that referenced this pull request Sep 22, 2025
| datasource | package | from  | to    |
| ---------- | ------- | ----- | ----- |
| npm        | vite    | 7.1.4 | 7.1.7 |


## [v7.1.7](https://github.com/vitejs/vite/blob/HEAD/packages/vite/CHANGELOG.md#small-717-2025-09-22-small)

##### Bug Fixes

- **build:** fix ssr environment `emitAssets: true` when `sharedConfigBuild: true` ([#20787](vitejs/vite#20787)) ([4c4583c](vitejs/vite@4c4583c))
- **client:** use CSP nonce when rendering error overlay ([#20791](vitejs/vite#20791)) ([9bc9d12](vitejs/vite@9bc9d12))
- **deps:** update all non-major dependencies ([#20811](vitejs/vite#20811)) ([9f2247c](vitejs/vite@9f2247c))
- **glob:** handle glob imports from folders starting with dot ([#20800](vitejs/vite#20800)) ([105abe8](vitejs/vite@105abe8))
- **hmr:** trigger prune event when import is removed from non hmr module ([#20768](vitejs/vite#20768)) ([9f32b1d](vitejs/vite@9f32b1d))
- **hmr:** wait for `import.meta.hot.prune` callbacks to complete before running other HMRs ([#20698](vitejs/vite#20698)) ([98a3484](vitejs/vite@98a3484))


## [v7.1.6](https://github.com/vitejs/vite/blob/HEAD/packages/vite/CHANGELOG.md#small-716-2025-09-18-small)

##### Bug Fixes

- **deps:** update all non-major dependencies ([#20773](vitejs/vite#20773)) ([88af2ae](vitejs/vite@88af2ae))
- **esbuild:** inject esbuild helper functions with minified `$` variables correctly ([#20761](vitejs/vite#20761)) ([7e8e004](vitejs/vite@7e8e004))
- fallback terser to main thread when nameCache is provided ([#20750](vitejs/vite#20750)) ([a679a64](vitejs/vite@a679a64))
- **types:** strict env typings fail when `skipLibCheck` is `false` ([#20755](vitejs/vite#20755)) ([cc54e29](vitejs/vite@cc54e29))

##### Miscellaneous Chores

- **deps:** update rolldown-related dependencies ([#20675](vitejs/vite#20675)) ([a67bb5f](vitejs/vite@a67bb5f))
- **deps:** update rolldown-related dependencies ([#20772](vitejs/vite#20772)) ([d785e72](vitejs/vite@d785e72))


## [v7.1.5](https://github.com/vitejs/vite/blob/HEAD/packages/vite/CHANGELOG.md#small-715-2025-09-08-small)

##### Bug Fixes

- apply `fs.strict` check to HTML files ([#20736](vitejs/vite#20736)) ([14015d7](vitejs/vite@14015d7))
- **deps:** update all non-major dependencies ([#20732](vitejs/vite#20732)) ([122bfba](vitejs/vite@122bfba))
- upgrade sirv to 3.0.2 ([#20735](vitejs/vite#20735)) ([09f2b52](vitejs/vite@09f2b52))
renovate bot added a commit to andrei-picus-tink/auto-renovate that referenced this pull request Sep 23, 2025
| datasource | package | from  | to    |
| ---------- | ------- | ----- | ----- |
| npm        | vite    | 7.1.4 | 7.1.7 |


## [v7.1.7](https://github.com/vitejs/vite/blob/HEAD/packages/vite/CHANGELOG.md#small-717-2025-09-22-small)

##### Bug Fixes

- **build:** fix ssr environment `emitAssets: true` when `sharedConfigBuild: true` ([#20787](vitejs/vite#20787)) ([4c4583c](vitejs/vite@4c4583c))
- **client:** use CSP nonce when rendering error overlay ([#20791](vitejs/vite#20791)) ([9bc9d12](vitejs/vite@9bc9d12))
- **deps:** update all non-major dependencies ([#20811](vitejs/vite#20811)) ([9f2247c](vitejs/vite@9f2247c))
- **glob:** handle glob imports from folders starting with dot ([#20800](vitejs/vite#20800)) ([105abe8](vitejs/vite@105abe8))
- **hmr:** trigger prune event when import is removed from non hmr module ([#20768](vitejs/vite#20768)) ([9f32b1d](vitejs/vite@9f32b1d))
- **hmr:** wait for `import.meta.hot.prune` callbacks to complete before running other HMRs ([#20698](vitejs/vite#20698)) ([98a3484](vitejs/vite@98a3484))


## [v7.1.6](https://github.com/vitejs/vite/blob/HEAD/packages/vite/CHANGELOG.md#small-716-2025-09-18-small)

##### Bug Fixes

- **deps:** update all non-major dependencies ([#20773](vitejs/vite#20773)) ([88af2ae](vitejs/vite@88af2ae))
- **esbuild:** inject esbuild helper functions with minified `$` variables correctly ([#20761](vitejs/vite#20761)) ([7e8e004](vitejs/vite@7e8e004))
- fallback terser to main thread when nameCache is provided ([#20750](vitejs/vite#20750)) ([a679a64](vitejs/vite@a679a64))
- **types:** strict env typings fail when `skipLibCheck` is `false` ([#20755](vitejs/vite#20755)) ([cc54e29](vitejs/vite@cc54e29))

##### Miscellaneous Chores

- **deps:** update rolldown-related dependencies ([#20675](vitejs/vite#20675)) ([a67bb5f](vitejs/vite@a67bb5f))
- **deps:** update rolldown-related dependencies ([#20772](vitejs/vite#20772)) ([d785e72](vitejs/vite@d785e72))


## [v7.1.5](https://github.com/vitejs/vite/blob/HEAD/packages/vite/CHANGELOG.md#small-715-2025-09-08-small)

##### Bug Fixes

- apply `fs.strict` check to HTML files ([#20736](vitejs/vite#20736)) ([14015d7](vitejs/vite@14015d7))
- **deps:** update all non-major dependencies ([#20732](vitejs/vite#20732)) ([122bfba](vitejs/vite@122bfba))
- upgrade sirv to 3.0.2 ([#20735](vitejs/vite#20735)) ([09f2b52](vitejs/vite@09f2b52))
renovate bot added a commit to andrei-picus-tink/auto-renovate that referenced this pull request Sep 25, 2025
| datasource | package | from  | to    |
| ---------- | ------- | ----- | ----- |
| npm        | vite    | 7.1.4 | 7.1.7 |


## [v7.1.7](https://github.com/vitejs/vite/blob/HEAD/packages/vite/CHANGELOG.md#small-717-2025-09-22-small)

##### Bug Fixes

- **build:** fix ssr environment `emitAssets: true` when `sharedConfigBuild: true` ([#20787](vitejs/vite#20787)) ([4c4583c](vitejs/vite@4c4583c))
- **client:** use CSP nonce when rendering error overlay ([#20791](vitejs/vite#20791)) ([9bc9d12](vitejs/vite@9bc9d12))
- **deps:** update all non-major dependencies ([#20811](vitejs/vite#20811)) ([9f2247c](vitejs/vite@9f2247c))
- **glob:** handle glob imports from folders starting with dot ([#20800](vitejs/vite#20800)) ([105abe8](vitejs/vite@105abe8))
- **hmr:** trigger prune event when import is removed from non hmr module ([#20768](vitejs/vite#20768)) ([9f32b1d](vitejs/vite@9f32b1d))
- **hmr:** wait for `import.meta.hot.prune` callbacks to complete before running other HMRs ([#20698](vitejs/vite#20698)) ([98a3484](vitejs/vite@98a3484))


## [v7.1.6](https://github.com/vitejs/vite/blob/HEAD/packages/vite/CHANGELOG.md#small-716-2025-09-18-small)

##### Bug Fixes

- **deps:** update all non-major dependencies ([#20773](vitejs/vite#20773)) ([88af2ae](vitejs/vite@88af2ae))
- **esbuild:** inject esbuild helper functions with minified `$` variables correctly ([#20761](vitejs/vite#20761)) ([7e8e004](vitejs/vite@7e8e004))
- fallback terser to main thread when nameCache is provided ([#20750](vitejs/vite#20750)) ([a679a64](vitejs/vite@a679a64))
- **types:** strict env typings fail when `skipLibCheck` is `false` ([#20755](vitejs/vite#20755)) ([cc54e29](vitejs/vite@cc54e29))

##### Miscellaneous Chores

- **deps:** update rolldown-related dependencies ([#20675](vitejs/vite#20675)) ([a67bb5f](vitejs/vite@a67bb5f))
- **deps:** update rolldown-related dependencies ([#20772](vitejs/vite#20772)) ([d785e72](vitejs/vite@d785e72))


## [v7.1.5](https://github.com/vitejs/vite/blob/HEAD/packages/vite/CHANGELOG.md#small-715-2025-09-08-small)

##### Bug Fixes

- apply `fs.strict` check to HTML files ([#20736](vitejs/vite#20736)) ([14015d7](vitejs/vite@14015d7))
- **deps:** update all non-major dependencies ([#20732](vitejs/vite#20732)) ([122bfba](vitejs/vite@122bfba))
- upgrade sirv to 3.0.2 ([#20735](vitejs/vite#20735)) ([09f2b52](vitejs/vite@09f2b52))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

styles is not removed when css import is removed from non hmr module

3 participants