File tree Expand file tree Collapse file tree 2 files changed +25
-0
lines changed
Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -140,6 +140,9 @@ export function getOffsetPosition(
140140// eslint-disable-next-line @typescript-eslint/ban-types
141141export async function runOnce ( key : string , func : Function ) : Promise < any >
142142
143+ // eslint-disable-next-line @typescript-eslint/ban-types
144+ export function runWhenRootExists ( func : Function ) : void
145+
143146// eslint-disable-next-line @typescript-eslint/ban-types
144147export function runWhenHeadExists ( func : Function ) : void
145148
Original file line number Diff line number Diff line change @@ -372,6 +372,7 @@ export const parseInt10 = (number, defaultValue) => {
372372 return Number . isNaN ( result ) ? defaultValue : result
373373}
374374
375+ const rootFuncArray = [ ]
375376const headFuncArray = [ ]
376377const bodyFuncArray = [ ]
377378let headBodyObserver
@@ -386,6 +387,14 @@ const startObserveHeadBodyExists = () => {
386387 headBodyObserver . disconnect ( )
387388 }
388389
390+ if ( doc . documentElement && rootFuncArray . length > 0 ) {
391+ for ( const func of rootFuncArray ) {
392+ func ( )
393+ }
394+
395+ rootFuncArray . length = 0
396+ }
397+
389398 if ( doc . head && headFuncArray . length > 0 ) {
390399 for ( const func of headFuncArray ) {
391400 func ( )
@@ -409,6 +418,19 @@ const startObserveHeadBodyExists = () => {
409418 } )
410419}
411420
421+ /**
422+ * Run function when document.documentElement exsits.
423+ */
424+ export const runWhenRootExists = ( func ) => {
425+ if ( ! doc . documentElement ) {
426+ rootFuncArray . push ( func )
427+ startObserveHeadBodyExists ( )
428+ return
429+ }
430+
431+ func ( )
432+ }
433+
412434/**
413435 * Run function when document.head exsits.
414436 */
You can’t perform that action at this time.
0 commit comments