Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove redundant textContent = '' for HMR since as of solid 0.21.0 it's handled by dom expressions #1

Merged
merged 1 commit into from
Nov 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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