Skip to content

Commit 4a37334

Browse files
committed
fix: unmounting of devtools
1 parent 650b8f5 commit 4a37334

1 file changed

Lines changed: 19 additions & 4 deletions

File tree

packages/devtools-utils/src/solid/class.tsx

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,16 @@ import type { JSX } from 'solid-js'
1414
export function constructCoreClass(Component: () => JSX.Element) {
1515
class DevtoolsCore {
1616
#isMounted = false
17+
#isMounting = false;
18+
#mountCb: (() => void) | null = null;
1719
#dispose?: () => void
1820
#Component: any
1921
#ThemeProvider: any
2022

21-
constructor() {}
23+
constructor() { }
2224

2325
async mount<T extends HTMLElement>(el: T, theme: 'light' | 'dark') {
26+
this.#isMounting = true;
2427
const { lazy } = await import('solid-js')
2528
const { render, Portal } = await import('solid-js/web')
2629
if (this.#isMounted) {
@@ -49,13 +52,25 @@ export function constructCoreClass(Component: () => JSX.Element) {
4952
)
5053
}, mountTo)
5154
this.#isMounted = true
55+
this.#isMounting = false;
5256
this.#dispose = dispose
57+
if (this.#mountCb) {
58+
this.#mountCb();
59+
this.#mountCb = null;
60+
}
5361
}
5462

5563
unmount() {
56-
if (!this.#isMounted) {
64+
if (!this.#isMounted && !this.#isMounting) {
5765
throw new Error('Devtools is not mounted')
5866
}
67+
if (this.#isMounting) {
68+
this.#mountCb = () => {
69+
this.#dispose?.()
70+
this.#isMounted = false
71+
}
72+
return;
73+
}
5974
this.#dispose?.()
6075
this.#isMounted = false
6176
}
@@ -64,8 +79,8 @@ export function constructCoreClass(Component: () => JSX.Element) {
6479
constructor() {
6580
super()
6681
}
67-
async mount<T extends HTMLElement>(_el: T, _theme: 'light' | 'dark') {}
68-
unmount() {}
82+
async mount<T extends HTMLElement>(_el: T, _theme: 'light' | 'dark') { }
83+
unmount() { }
6984
}
7085
return [DevtoolsCore, NoOpDevtoolsCore] as const
7186
}

0 commit comments

Comments
 (0)