@@ -52,8 +52,6 @@ export async function newSpecPage(opts: d.NewSpecPageOptions): Promise<d.SpecPag
5252 win : win ,
5353 doc : doc ,
5454 body : doc . body as any ,
55- root : null as any ,
56- rootInstance : null as any ,
5755 build : bc . BUILD as d . Build ,
5856 styles : platform . styles as Map < string , string > ,
5957 setContent : ( html : string ) => {
@@ -163,19 +161,32 @@ export async function newSpecPage(opts: d.NewSpecPageOptions): Promise<d.SpecPag
163161 await page . waitForChanges ( ) ;
164162 }
165163
166- page . root = findRootComponent ( cmpTags , page . body ) ;
167- if ( page . root != null ) {
168- const hostRef = platform . getHostRef ( page . root ) ;
169- if ( hostRef != null ) {
170- page . rootInstance = hostRef . $lazyInstance$ ;
164+ let rootComponent : any = null ;
165+ Object . defineProperty ( page , 'root' , {
166+ get ( ) {
167+ if ( rootComponent == null ) {
168+ rootComponent = findRootComponent ( cmpTags , page . body ) ;
169+ if ( rootComponent != null ) {
170+ return rootComponent ;
171+ }
172+ }
173+ const firstElementChild = page . body . firstElementChild ;
174+ if ( firstElementChild != null ) {
175+ return firstElementChild as any ;
176+ }
177+ return null ;
171178 }
179+ } ) ;
172180
173- } else {
174- const firstElementChild = page . body . firstElementChild ;
175- if ( firstElementChild != null ) {
176- page . root = firstElementChild as any ;
181+ Object . defineProperty ( page , 'rootInstance' , {
182+ get ( ) {
183+ const hostRef = platform . getHostRef ( page . root ) ;
184+ if ( hostRef != null ) {
185+ return hostRef . $lazyInstance$ ;
186+ }
187+ return null ;
177188 }
178- }
189+ } ) ;
179190
180191 if ( opts . hydrateServerSide ) {
181192 platform . insertVdomAnnotations ( doc ) ;
0 commit comments