Skip to content

Commit

Permalink
docs(api-hmr): update hot.prune docs (#11047)
Browse files Browse the repository at this point in the history
  • Loading branch information
bluwy committed Nov 23, 2022
1 parent 7d24b5f commit d6b4ee5
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion docs/guide/api-hmr.md
Expand Up @@ -119,9 +119,13 @@ if (import.meta.hot) {
## `hot.prune(cb)`
Register a callback that will call when the module is no longer imported on the page. This can be used to clean up side effects like style injections. Vite already does this for `.css` imports.
Register a callback that will call when the module is no longer imported on the page. Compared to `hot.dispose`, this can be used if the source code cleans up side-effects by itself on updates and you only need to clean-up when it's removed from the page. Vite currently uses this for `.css` imports.
```js
function setupOrReuseSideEffect() {}

setupOrReuseSideEffect()

if (import.meta.hot) {
import.meta.hot.prune((data) => {
// cleanup side effect
Expand Down

0 comments on commit d6b4ee5

Please sign in to comment.