fix HMR support
This commit is contained in:
parent
50054b014f
commit
e14821c699
|
|
@ -9,6 +9,9 @@ export function clearStyles() {
|
|||
for (const key in themes) delete themes[key]
|
||||
}
|
||||
|
||||
// HMR support - clear styles when module is replaced
|
||||
import.meta.hot?.dispose(() => clearStyles())
|
||||
|
||||
export function createTheme<const T extends Record<string, string | number>>(name: string, values: T): T {
|
||||
themes[name] = values as Record<string, string | number>
|
||||
return values
|
||||
|
|
@ -279,11 +282,7 @@ export function define(nameOrDef: string | TagDef, defIfNamed?: TagDef) {
|
|||
const def = defIfNamed ?? nameOrDef as TagDef
|
||||
const name = defIfNamed ? (nameOrDef as string) : anonName(def)
|
||||
|
||||
// Clear any existing styles for this component (supports HMR/hot reload)
|
||||
for (const key in styles) {
|
||||
if (key === name || key.startsWith(`${name}_`) || key.startsWith(`${name}.`) || key.startsWith(`${name}:`))
|
||||
delete styles[key]
|
||||
}
|
||||
if (styles[name]) throw `${name} is already defined! Must use unique names.`
|
||||
registerStyles(name, def)
|
||||
|
||||
return (props: Record<string, any>) => {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user