-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Template Part & Query: avoid server requests on mount #57987
Conversation
Size Change: +255 B (0%) Total Size: 1.7 MB
ℹ️ View Unchanged
|
Flaky tests detected in b20a114. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/7582395152
|
@@ -70,12 +68,16 @@ export const withEditBlockControls = createHigherOrderComponent( | |||
const { attributes, name } = props; | |||
const isDisplayed = name === 'core/template-part' && attributes.slug; | |||
|
|||
if ( ! isDisplayed ) { | |||
return <BlockEdit { ...props } />; |
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.
Should we use key
here and below to avoid accidental remounting?
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.
When does it remount? Block names cannot change. I guess the slug can change. Maybe we should just remove that from the condition.
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.
Mainly to safeguard and the best practice. Remounting can have unexpected side effects - #50292.
Maybe we should just remove that from the condition.
The editor cannot display the template part in focus mode without slug, so we need this condition.
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.
In that case I think we need to make sure it remains the same component instance and within the same fragment. A key won't help with that I think? I changed it so it's the same instance for both conditions, and I added the key just to be sure.
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.
It does help when the component's position changes after the initial render. If the key is provided, React will use it as a part of the position instead of the order in the parent component.
This example won't retain the state between toggles without the key
- https://codesandbox.io/p/sandbox/funny-herschel-slys5c?file=%2Fsrc%2FApp.js%3A33%2C29
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.
The changes are straightforward, and I cannot spot regressions. The controls are displayed as before.
What?
Easier to review without whitespace.
Both the these blocks fetch stuff from the server for the inspector controls, even when the inspector controls are not visible.
Why?
Note that this happens after first blocks load, so this won't necessarily improve the "first block" metric, but it's of course still good to avoid all these.
Avoided:
How?
Testing Instructions
Testing Instructions for Keyboard
Screenshots or screencast