Skip to content

Commit

Permalink
remove redundant textContent = '' for HMR since as of solid 0.21.0 it…
Browse files Browse the repository at this point in the history
…'s handled by dom expressions
  • Loading branch information
boogerlad committed Nov 23, 2020
1 parent ca68e35 commit 2dfe316
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 14 deletions.
10 changes: 3 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 :

Expand All @@ -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);
}
```

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
6 changes: 1 addition & 5 deletions src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
`;
}
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2dfe316

Please sign in to comment.