Skip to content

Commit d6782c3

Browse files
committed
fix: $destroy and createRoot are no more
1 parent 178b2de commit d6782c3

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/pure.js

+8-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ import {
33
getQueriesForElement,
44
prettyDOM,
55
} from '@testing-library/dom'
6+
import { VERSION as SVELTE_VERSION } from 'svelte/compiler'
67
import * as Svelte from 'svelte'
78

8-
const IS_SVELTE_5 = typeof Svelte.createRoot === 'function'
9+
const IS_SVELTE_5 = /^5\./.test(SVELTE_VERSION)
910
const targetCache = new Set()
1011
const componentCache = new Set()
1112

@@ -55,7 +56,7 @@ const render = (
5556
options = { target, ...checkProps(options) }
5657

5758
const component = IS_SVELTE_5
58-
? Svelte.createRoot(ComponentConstructor, options)
59+
? Svelte.mount(ComponentConstructor, options)
5960
: new ComponentConstructor(options)
6061

6162
componentCache.add(component)
@@ -98,7 +99,11 @@ const cleanupComponent = (component) => {
9899
const inCache = componentCache.delete(component)
99100

100101
if (inCache) {
101-
component.$destroy()
102+
if (IS_SVELTE_5) {
103+
Svelte.unmount(component)
104+
} else {
105+
component.$destroy()
106+
}
102107
}
103108
}
104109

0 commit comments

Comments
 (0)