-
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
Site editor: avoid double post content parse (alternative) #58146
Conversation
Size Change: +43 B (0%) Total Size: 1.7 MB
ℹ️ View Unchanged
|
I think this is addressing the same issue as #57500 |
To be clear, I don't have full 100% confidence in my PR but I do believe that it's probably something that should be absorbed by the framework and not solved at the component level. |
@youknowriad Would this be ok as a temporary solution to avoid the double parse? |
} else { | ||
editedBlocks = EMPTY_ARRAY; | ||
} | ||
} |
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.
Why did you decide to move this code inside useSelect calls. I'm worried about parse within useSelect, can we move it to the previous useMemo instead? I think it might be clearer as well.
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.
Sure, I guess I can pass the entity record to the component
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.
Fixed
0dc3143
to
c6877eb
Compare
const editedRecord = getEditedEntityRecord( kind, name, id ); | ||
return { | ||
editedBlocks: editedRecord.blocks, | ||
content: editedRecord.content, | ||
meta: editedRecord.meta, | ||
entityRecord: getEntityRecord( kind, name, id ), |
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 we don't really need the entityRecord
to trigger a pre-render, we should just use getEntityRecord
within the blocks computation.
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.
You mean like this? b332cf9
I think it doesn't matter much because the entityRecord will never change, unlike the edited entity record, which is why we use it as a cache key.
What?
Similar to #57863, but without changes to existing selectors.
Why?
In the Site Editor,
useEntityBlockEditor
is called twice (top level and inside the post content block) with the same record ID, so the content gets parsed twice because it only memos by hook instance.Improves the site editor load metric by at least 2%.
How?
We can cache the parsed result with a weak map.
Testing Instructions
Testing Instructions for Keyboard
Screenshots or screencast