diff --git a/packages/ui-next/src/registry/index.tsx b/packages/ui-next/src/registry/index.tsx index d280f3b39..3e45e9fab 100644 --- a/packages/ui-next/src/registry/index.tsx +++ b/packages/ui-next/src/registry/index.tsx @@ -15,14 +15,25 @@ interface PatchEntry { cb: (props: any) => any; } -const registry = { - components: {} as Record>, - before: {} as Record, - after: {} as Record, - patch: {} as Record, -}; +function createRegistry() { + return { + components: {} as Record>, + before: {} as Record, + after: {} as Record, + patch: {} as Record, + }; +} -let idCounter = 0; +const registry: ReturnType = import.meta.hot?.data?.registry ?? createRegistry(); +if (import.meta.hot) import.meta.hot.data.registry = registry; + +let idCounter = import.meta.hot?.data?.idCounter ?? 0; +if (import.meta.hot) { + Object.defineProperty(import.meta.hot.data, 'idCounter', { + get: () => idCounter, + set: (v: number) => { idCounter = v; }, + }); +} function genId() { return `__auto_${++idCounter}`; } function upsert(list: T[], entry: T) {