From d6b4ee58d63b5e8d04386964451b45cf808a3963 Mon Sep 17 00:00:00 2001 From: Bjorn Lu Date: Thu, 24 Nov 2022 07:00:35 +0800 Subject: [PATCH] docs(api-hmr): update hot.prune docs (#11047) --- docs/guide/api-hmr.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/guide/api-hmr.md b/docs/guide/api-hmr.md index cfca9780e61d61..59a689c6ca2223 100644 --- a/docs/guide/api-hmr.md +++ b/docs/guide/api-hmr.md @@ -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