Repository navigation
Interactivity API: Break up long hydration task in interactivity init #58227
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,15 +21,26 @@ export const getRegionRootFragment = ( region ) => { | |
| return regionRootFragments.get( region ); | ||
| }; | ||
|
|
||
| function yieldToMain() { | ||
| return new Promise( ( resolve ) => { | ||
| // TODO: Use scheduler.yield() when available. | ||
| setTimeout( resolve, 0 ); | ||
| } ); | ||
| } | ||
|
|
||
| // Initialize the router with the initial DOM. | ||
| export const init = async () => { | ||
| document | ||
| .querySelectorAll( `[data-${ directivePrefix }-interactive]` ) | ||
| .forEach( ( node ) => { | ||
| if ( ! hydratedIslands.has( node ) ) { | ||
| const fragment = getRegionRootFragment( node ); | ||
| const vdom = toVdom( node ); | ||
| hydrate( vdom, fragment ); | ||
| } | ||
| } ); | ||
| const nodes = document.querySelectorAll( | ||
| `[data-${ directivePrefix }-interactive]` | ||
| ); | ||
|
|
||
| for ( const node of nodes ) { | ||
| if ( ! hydratedIslands.has( node ) ) { | ||
| await yieldToMain(); | ||
| const fragment = getRegionRootFragment( node ); | ||
| const vdom = toVdom( node ); | ||
| await yieldToMain(); | ||
|
Comment on lines
+38
to
+42
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @luisherranz Actually, what is the purpose of
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Islands that are inside other islands belong to the same Preact application so they can share context and such. When an island is already hydrated as part of a parent, we skip its own hydration.
I actually spotted a bug yesterday due to the fact that the router store was calling As |
||
| hydrate( vdom, fragment ); | ||
| } | ||
| } | ||
| }; | ||
Uh oh!
There was an error while loading. Please reload this page.