@@ -21,35 +21,37 @@ if (!window.$RC) {
21
21
window . $RM = new Map ( ) ;
22
22
}
23
23
24
- if ( document . readyState === 'loading' ) {
25
- if ( document . body != null ) {
24
+ if ( document . body != null ) {
25
+ if ( document . readyState === 'loading' ) {
26
26
installFizzInstrObserver ( document . body ) ;
27
- } else {
28
- // body may not exist yet if the fizz runtime is sent in <head>
29
- // (e.g. as a preinit resource)
30
- // $FlowFixMe[recursive-definition]
31
- const domBodyObserver = new MutationObserver ( ( ) => {
32
- // We expect the body node to be stable once parsed / created
33
- if ( document . body ) {
34
- if ( document . readyState === 'loading' ) {
35
- installFizzInstrObserver ( document . body ) ;
36
- }
37
- handleExistingNodes ( ) ;
38
- // We can call disconnect without takeRecord here,
39
- // since we only expect a single document.body
40
- domBodyObserver . disconnect ( ) ;
41
- }
42
- } ) ;
43
- // documentElement must already exist at this point
44
- // $FlowFixMe[incompatible-call]
45
- domBodyObserver . observe ( document . documentElement , { childList : true } ) ;
46
27
}
47
- }
28
+ // $FlowFixMe[incompatible-cast]
29
+ handleExistingNodes ( ( document . body /*: HTMLElement */ ) ) ;
30
+ } else {
31
+ // Document must be loading -- body may not exist yet if the fizz external
32
+ // runtime is sent in <head> (e.g. as a preinit resource)
33
+ // $FlowFixMe[recursive-definition]
34
+ const domBodyObserver = new MutationObserver ( ( ) => {
35
+ // We expect the body node to be stable once parsed / created
36
+ if ( document . body != null ) {
37
+ if ( document . readyState === 'loading' ) {
38
+ installFizzInstrObserver ( document . body ) ;
39
+ }
40
+ // $FlowFixMe[incompatible-cast]
41
+ handleExistingNodes ( ( document . body /*: HTMLElement */ ) ) ;
48
42
49
- handleExistingNodes ( ) ;
43
+ // We can call disconnect without takeRecord here,
44
+ // since we only expect a single document.body
45
+ domBodyObserver . disconnect ( ) ;
46
+ }
47
+ } ) ;
48
+ // documentElement must already exist at this point
49
+ // $FlowFixMe[incompatible-call]
50
+ domBodyObserver . observe ( document . documentElement , { childList : true } ) ;
51
+ }
50
52
51
- function handleExistingNodes ( ) {
52
- const existingNodes = document . getElementsByTagName ( 'template' ) ;
53
+ function handleExistingNodes ( target /*: HTMLElement */ ) {
54
+ const existingNodes = Array . from ( target . children ) ;
53
55
for ( let i = 0 ; i < existingNodes . length ; i ++ ) {
54
56
handleNode ( existingNodes [ i ] ) ;
55
57
}
0 commit comments