Skip to content

Commit

Permalink
Merge pull request #53 from nksaraf/css-hmr
Browse files Browse the repository at this point in the history
(fix): css hmr happens in vinxi/client for all css assets, not only for lazyRoutes
  • Loading branch information
nksaraf authored Dec 27, 2023
2 parents 3459f3e + a0974f0 commit b619909
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
6 changes: 6 additions & 0 deletions .changeset/fresh-peas-protect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"vinxi": patch
"solid-spa-basic": patch
---

(fix): css hmr happens in vinxi/client for all css assets, not only for lazyRoutes
10 changes: 10 additions & 0 deletions packages/vinxi/runtime/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,14 @@ if (import.meta.env.DEVTOOLS && import.meta.env.DEV) {
};
}

if (typeof window !== "undefined" && import.meta.hot) {
import.meta.hot.on("css-update", (data) => {
for (const el of document.querySelectorAll(
`style[data-vite-dev-id="${data.file}"]`,
)) {
el.innerHTML = data.contents;
}
});
}

globalThis.MANIFEST = manifest;
12 changes: 3 additions & 9 deletions packages/vinxi/runtime/style.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
*
* @param {*} styles
* @param {*} data
*
* @param {*} styles
* @param {*} data
*/
export function updateStyles(styles, data) {
let styleAsset = styles.find(
Expand All @@ -10,12 +10,6 @@ export function updateStyles(styles, data) {
if (styleAsset) {
styleAsset.children = data.contents;
}

for (const el of document.querySelectorAll(
`style[data-vite-dev-id="${data.file}"]`,
)) {
el.innerHTML = data.contents;
}
}

export function appendStyles(styles) {
Expand Down

0 comments on commit b619909

Please sign in to comment.