@@ -17,6 +17,7 @@ const {
17
17
parseServerData,
18
18
populateServerData,
19
19
batch,
20
+ initDone,
20
21
} = privateApis (
21
22
'I acknowledge that using private APIs means my theme or plugin will inevitably break in the next version of WordPress.'
22
23
) ;
@@ -166,27 +167,30 @@ window.addEventListener( 'popstate', async () => {
166
167
}
167
168
} ) ;
168
169
169
- // Initialize the router and cache the initial page using the initial vDOM.
170
- // Once this code is tested and more mature, the head should be updated for
171
- // region based navigation as well.
172
- if ( globalThis . IS_GUTENBERG_PLUGIN ) {
173
- if ( navigationMode === 'fullPage' ) {
174
- // Cache the scripts. Has to be called before fetching the assets.
175
- [ ] . map . call (
176
- document . querySelectorAll ( 'script[type="module"][src]' ) ,
177
- ( script ) => {
178
- headElements . set ( script . getAttribute ( 'src' ) , {
179
- tag : script ,
180
- } ) ;
181
- }
182
- ) ;
183
- await fetchHeadAssets ( document ) ;
170
+ ( async ( ) => {
171
+ await initDone ;
172
+ // Initialize the router and cache the initial page using the initial vDOM.
173
+ // Once this code is tested and more mature, the head should be updated for
174
+ // region based navigation as well.
175
+ if ( globalThis . IS_GUTENBERG_PLUGIN ) {
176
+ if ( navigationMode === 'fullPage' ) {
177
+ // Cache the scripts. Has to be called before fetching the assets.
178
+ [ ] . map . call (
179
+ document . querySelectorAll ( 'script[type="module"][src]' ) ,
180
+ ( script ) => {
181
+ headElements . set ( script . getAttribute ( 'src' ) , {
182
+ tag : script ,
183
+ } ) ;
184
+ }
185
+ ) ;
186
+ await fetchHeadAssets ( document ) ;
187
+ }
184
188
}
185
- }
186
- pages . set (
187
- getPagePath ( window . location . href ) ,
188
- Promise . resolve ( regionsToVdom ( document , { vdom : initialVdom } ) )
189
- ) ;
189
+ pages . set (
190
+ getPagePath ( window . location . href ) ,
191
+ Promise . resolve ( regionsToVdom ( document , { vdom : initialVdom } ) )
192
+ ) ;
193
+ } ) ( ) ;
190
194
191
195
// Check if the link is valid for client-side navigation.
192
196
const isValidLink = ( ref : HTMLAnchorElement ) =>
0 commit comments