From 2dfe316f26930e99a9c3dcdc2b48c4e1f73b93e1 Mon Sep 17 00:00:00 2001 From: kevin Date: Mon, 23 Nov 2020 12:03:56 -0500 Subject: [PATCH] remove redundant textContent = '' for HMR since as of solid 0.21.0 it's handled by dom expressions --- README.md | 10 +++------- package.json | 2 +- src/plugin.ts | 6 +----- yarn.lock | 2 +- 4 files changed, 6 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 5c641f0..77d54de 100644 --- a/README.md +++ b/README.md @@ -82,9 +82,8 @@ export default config; Finally you have to add a bit of code to your entry point to activate HMR. This might be handled automatically at some point by the plugin but for now it's manual. ```ts -// Those two variables are mandatory if you want automatic HMR -export const rootEl = document.getElementById("app"); -export const dispose = render(() => App, rootEl); +// This variable is mandatory if you want automatic HMR +export const dispose = render(() => App, rootElement); // The plugin will automatically inject the following snippet : @@ -93,10 +92,7 @@ export const dispose = render(() => App, rootEl); // if you want to avoid type errors here if (import.meta.hot) { import.meta.hot.accept(); - import.meta.hot.dispose(() => { - dispose(); - rootEl.textContent = ""; - }); + import.meta.hot.dispose(dispose); } ``` diff --git a/package.json b/package.json index 2fb824f..d6b16da 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,7 @@ }, "homepage": "https://github.com/amoutonbrady/vite-plugin-solid#readme", "peerDependencies": { - "solid-js": "^0.20.0 || ^1.0.0", + "solid-js": "^0.21.0 || ^1.0.0", "vite": "^1.0.0-rc.4 || ^1.0.0" }, "dependencies": { diff --git a/src/plugin.ts b/src/plugin.ts index 15a007b..ae5ce85 100644 --- a/src/plugin.ts +++ b/src/plugin.ts @@ -69,17 +69,13 @@ export function solidPlugin(options?: SolidPluginOptions): Plugin { function addHMR(code: string) { if (!code.includes(`const dispose`)) return code; - if (!code.includes(`const rootEl`)) return code; return dd` ${code} if (import.meta.hot) { import.meta.hot.accept(); - import.meta.hot.dispose(() => { - dispose(); - rootEl.textContent = ""; - }); + import.meta.hot.dispose(dispose); } `; } diff --git a/yarn.lock b/yarn.lock index 05ca483..147e812 100644 --- a/yarn.lock +++ b/yarn.lock @@ -24,7 +24,7 @@ __metadata: typescript: ^4.0.5 vite: ^1.0.0-rc.9 peerDependencies: - solid-js: ^0.20.0 || ^1.0.0 + solid-js: ^0.21.0 || ^1.0.0 vite: ^1.0.0-rc.4 || ^1.0.0 languageName: unknown linkType: soft