File tree Expand file tree Collapse file tree 1 file changed +9
-10
lines changed
src/js/packages/@reactpy/client/src Expand file tree Collapse file tree 1 file changed +9
-10
lines changed Original file line number Diff line number Diff line change @@ -30,31 +30,30 @@ function local_preact_bind(node: HTMLElement) {
3030 } ;
3131}
3232
33+ const roots = new WeakMap < HTMLElement , any > ( ) ;
34+
3335function 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 }
You can’t perform that action at this time.
0 commit comments