diff --git a/packages/core/src/morfeo.ts b/packages/core/src/morfeo.ts index 3c733a26..e7e2d3a1 100644 --- a/packages/core/src/morfeo.ts +++ b/packages/core/src/morfeo.ts @@ -126,7 +126,7 @@ function createMorfeo() { theme.reset(); } - return Object.freeze({ + const instance = Object.freeze({ resolve, useTheme, setTheme, @@ -135,6 +135,10 @@ function createMorfeo() { getCurrent, __dangerousReset, }); + + globalThis.__MORFEO_INSTANCE = instance; + + return instance; } export type Morfeo = ReturnType; @@ -158,4 +162,15 @@ export type Morfeo = ReturnType; * * const currentTheme = morfeo.getTheme(); */ -export const morfeo: Morfeo = createMorfeo(); +export const morfeo: Morfeo = globalThis.__MORFEO_INSTANCE || createMorfeo(); + +declare global { + interface Window { + __MORFEO_INSTANCE: Morfeo; + } + module NodeJS { + interface Global { + __MORFEO_INSTANCE: Morfeo; + } + } +} diff --git a/packages/core/src/types.ts b/packages/core/src/types.ts index d65d7d22..48110f94 100644 --- a/packages/core/src/types.ts +++ b/packages/core/src/types.ts @@ -35,14 +35,3 @@ export interface Themes { } export type ThemeName = keyof Themes; - -declare global { - interface Window { - __MORFEO_THEMES: Themes; - } - module NodeJS { - interface Global { - __MORFEO_THEMES: Themes; - } - } -}