Skip to content

Commit 2834d5a

Browse files
authored
make createRoot / hydrateRoot compatible with React spec (preactjs#3560)
1 parent 1dc4f56 commit 2834d5a

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

compat/client.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
1-
const { render, hydrate } = require('preact/compat');
1+
const { render, hydrate, unmountComponentAtNode } = require('preact/compat');
22

3-
exports.createRoot = function(container) {
3+
function createRoot(container) {
44
return {
55
render(children) {
6-
return render(children, container);
6+
render(children, container);
7+
},
8+
unmount() {
9+
unmountComponentAtNode(container);
710
}
811
};
9-
};
12+
}
13+
14+
exports.createRoot = createRoot;
1015

1116
exports.hydrateRoot = function(container, children) {
12-
return hydrate(children, container);
17+
hydrate(children, container);
18+
return createRoot(container);
1319
};

compat/client.mjs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1-
import { render, hydrate } from 'preact/compat'
1+
import { render, hydrate, unmountComponentAtNode } from 'preact/compat'
22

33
export function createRoot(container) {
44
return {
55
render(children) {
6-
return render(children, container)
6+
render(children, container)
7+
},
8+
unmount() {
9+
unmountComponentAtNode(container)
710
}
811
}
912
}
1013

1114
export function hydrateRoot(container, children) {
12-
return hydrate(children, container);
15+
hydrate(children, container)
16+
return createRoot(container)
1317
}

0 commit comments

Comments
 (0)