Improves documentation of `@fresh/plugin-vite` related to public API, and exports missing symbols/types that are part of public API (`FreshViteConfig`). - Adds `@module` JSDoc for the `@fresh/plugin-vite/client` entrypoint - Internal only, used for browser HMR - Exports types `ImportCheck` & `ImportCheckDiagnostic`, as they are part of the public API via `FreshViteConfig` - Should make [`ImportCheck` link to correct type](https://jsr.io/@fresh/plugin-vite/doc/~/FreshViteConfig#property_checkimports): <img width="1053" height="285" alt="image" src="https://github.com/user-attachments/assets/766c29f7-7f39-429e-bd81-234fed6b0820" /> - Adds JSDoc descriptions for all public exports; `fresh`, `FreshViteConfig`, `ImportCheck` & `ImportCheckDiagnostic` - Adds description for `FreshViteConfig.checkImports` Part of #3597 & #3596
30 lines
686 B
TypeScript
30 lines
686 B
TypeScript
/**
|
|
* Used internally by the `@fresh/plugin-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();
|
|
}
|
|
});
|
|
});
|
|
}
|