-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Interactivity API: Break up long hydration task in interactivity init #58227
Conversation
Size Change: +208 B (0%) Total Size: 1.7 MB
ℹ️ View Unchanged
|
Flaky tests detected in 645c945. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/7648182936
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fantastic 👏 👏
I didn't know breaking down tasks like this was so simple.
Could you please add an entry in the package Changelog?
Co-authored-by: Luis Herranz <luisherranz@gmail.com>
Done in cffdb4d! |
if ( ! hydratedIslands.has( node ) ) { | ||
await yieldToMain(); | ||
const fragment = getRegionRootFragment( node ); | ||
const vdom = toVdom( node ); | ||
await yieldToMain(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@luisherranz Actually, what is the purpose of hydratedIslands
here? Could it be that the check for ! hydratedIslands.has( node )
could be done so that the condition is entered, but then yielding occurs so that it's possible that the island could be hydrated by another task? Could it be that toVdom()
accidentally gets called on a hydrated island?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is the purpose of hydratedIslands here?
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.
that it's possible that the island could be hydrated by another task?
I actually spotted a bug yesterday due to the fact that the router store was calling toVdom
before the init
. It's a rare edge case, but I'll fix it.
As toVdom
is going to be a private, core-only API in WP 6.5, there should no be more problems. But in the future, if toVdom
is exposed publicly, we can add a second argument to toVdom( node, isHydrating = false )
to know if it should add the nodes to the hydratedIslands
map or not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is an easy win and I wouldn't mind including it for WP 6.5.
Feel free to merge.
…zy-hydration * origin/trunk: (47 commits) Interactivity API: Break up long hydration task in interactivity init (#58227) Add supports.interactivity to Query block (#58316) Font Library: Make notices more consistent (#58180) Fix Global styles text settings bleeding into placeholder component (#58303) Fix the position and size of the Options menu, (#57515) DataViews: Fix safari grid row height issue (#58302) Try a fix (#58282) Navigation Submenu Block: Make block name affect list view (#58296) Apply custom scroll style to fixed header block toolbar (#57444) Add support for transform and letter spacing controls in Global Styles > Typography > Elements (#58142) DataViews: Fix table view cell wrapper and BlockPreviews (#58062) Workflows: Add 'Technical Prototype' to the type-related labels list (#58163) Block Editor: Optimize the 'useBlockDisplayTitle' hook (#58250) Remove noahtallen from .wp-env codeowners (#58283) Global styles revisions: fix is-selected rules from affecting other areas of the editor (#58228) Try: Disable text selection for post content placeholder block. (#58169) Remove `template-only` mode from editor and edit-post packages (#57700) Refactored download/upload logic to support font faces with multiple src assets (#58216) Components: Expand theming support in COLORS (#58097) Implementing new UX for invoking rich text Link UI (#57986) ...
Fixes #58225.
What?
Avoid long task during interactivity initialization
Why?
Long tasks create a poor user experience and can negatively impact Largest Contentful Paint (LCP), Total Blocking Time (TBT), First Input Delay (FID), and Interaction to Next Paint (INP).
How?
As outlined in Optimize Long Tasks, this breaks up the long task in the
init()
by yielding to main after each node is hydrated.Testing Instructions
Screenshots or screencast
Without CPU Throttling
With 6x CPU Throttling
Lighthouse Performance Audit