11import React from "react" ;
22import ReactDOM from "react-dom/client" ;
3+ import { getComponentTree } from "./utils" ;
34
45function getAttributeJson ( el , attributeName ) {
56 const data = el . getAttribute ( attributeName ) ;
@@ -23,7 +24,6 @@ function getChildren(hook) {
2324function getProps ( hook ) {
2425 return {
2526 ...getAttributeJson ( hook . el , "data-props" ) ,
26- // pass the hook callbacks to the component
2727 pushEvent : hook . pushEvent . bind ( hook ) ,
2828 pushEventTo : hook . pushEventTo . bind ( hook ) ,
2929 handleEvent : hook . handleEvent . bind ( hook ) ,
@@ -36,13 +36,12 @@ function getProps(hook) {
3636export function getHooks ( components ) {
3737 const ReactHook = {
3838 _render ( ) {
39- this . _root . render (
40- React . createElement (
41- this . _Component ,
42- getProps ( this ) ,
43- ...getChildren ( this ) ,
44- ) ,
39+ const tree = getComponentTree (
40+ this . _Component ,
41+ getProps ( this ) ,
42+ getChildren ( this ) ,
4543 ) ;
44+ this . _root . render ( tree ) ;
4645 } ,
4746 mounted ( ) {
4847 const componentName = this . el . getAttribute ( "data-name" ) ;
@@ -55,14 +54,12 @@ export function getHooks(components) {
5554 const isSSR = this . el . hasAttribute ( "data-ssr" ) ;
5655
5756 if ( isSSR ) {
58- this . _root = ReactDOM . hydrateRoot (
59- this . el ,
60- React . createElement (
61- this . _Component ,
62- getProps ( this ) ,
63- ...getChildren ( this ) ,
64- ) ,
57+ const tree = getComponentTree (
58+ this . _Component ,
59+ getProps ( this ) ,
60+ getChildren ( this ) ,
6561 ) ;
62+ this . _root = ReactDOM . hydrateRoot ( this . el , tree ) ;
6663 } else {
6764 this . _root = ReactDOM . createRoot ( this . el ) ;
6865 this . _render ( ) ;
0 commit comments