Files
sweet/packages/plugin-vite/src/client.ts
T
2026-11-11 11:45:20 -03:00

30 lines
689 B
TypeScript

/**
* Used internally by the `@paulaboks/sweet-vite` to add HMR support
* for Fresh running in the browser.
*
* **Do not** import this module directly.
*
* @module
* @private
*/
import type { UpdatePayload } from "vite";
import { hashCode } from "./shared.ts";
if (import.meta.hot) {
import.meta.hot.on("fresh:reload", () => {
window.location.reload();
});
import.meta.hot.on("vite:beforeUpdate", (module: UpdatePayload) => {
module.updates.forEach((update) => {
const moduleStyle = document.querySelector(
`[vite-module-id="${hashCode(update.acceptedPath)}"]`,
);
if (moduleStyle) {
moduleStyle.remove();
}
});
});
}