Skip to content

Commit 34d925b

Browse files
committed
Attempt 5
1 parent b7f5dff commit 34d925b

File tree

1 file changed

+9
-10
lines changed
  • src/js/packages/@reactpy/client/src

1 file changed

+9
-10
lines changed

src/js/packages/@reactpy/client/src/bind.tsx

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,31 +30,30 @@ function local_preact_bind(node: HTMLElement) {
3030
};
3131
}
3232

33+
const roots = new WeakMap<HTMLElement, any>();
34+
3335
function reactjs_bind(node: HTMLElement, React: any, ReactDOM: any) {
3436
let root: any = null;
3537
return {
3638
create: (type: any, props: any, children?: any[]) =>
3739
React.createElement(type, props, ...(children || [])),
3840
render: (element: any) => {
3941
if (!root) {
40-
// @ts-ignore
41-
if (node._reactPyRoot) {
42-
// @ts-ignore
43-
node._reactPyRoot.unmount();
42+
const existingRoot = roots.get(node);
43+
if (existingRoot) {
44+
existingRoot.unmount();
45+
roots.delete(node);
4446
}
4547
root = ReactDOM.createRoot(node);
46-
// @ts-ignore
47-
node._reactPyRoot = root;
48+
roots.set(node, root);
4849
}
4950
root.render(element);
5051
},
5152
unmount: () => {
5253
if (root) {
5354
root.unmount();
54-
// @ts-ignore
55-
if (node._reactPyRoot === root) {
56-
// @ts-ignore
57-
node._reactPyRoot = null;
55+
if (roots.get(node) === root) {
56+
roots.delete(node);
5857
}
5958
root = null;
6059
}

0 commit comments

Comments
 (0)