-
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
Core data: useEntityBlockEditor: fix parsed blocks cache #58841
Conversation
Size Change: +27 B (0%) Total Size: 1.71 MB
ℹ️ View Unchanged
|
|
||
if ( ! _blocks ) { | ||
_blocks = parse( content ); | ||
parsedBlocksCache.set( entityRecord, _blocks ); | ||
parsedBlocksCache.set( cackeKey, _blocks ); |
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 might leave in memory two block lists unnecessarily. (one of entity record, one for the latest edits object). So there's a tiny memory impact, probably ok though.
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 that's fine. Parts of this block list will be reused for edited block lists I think?
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
} ); | ||
|
||
// Change content by typing. | ||
await textbox.fill( '' ); |
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 is this necessary?
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.
There's a beforeEach that fills in content
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've tested it and it seems to solve the issue 🙂
Can we rebase and merge this PR? |
8d82c07
to
be998ef
Compare
|
||
if ( ! _blocks ) { | ||
_blocks = parse( content ); | ||
parsedBlocksCache.set( entityRecord, _blocks ); | ||
parsedBlocksCache.set( cackeKey, _blocks ); |
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.
parsedBlocksCache.set( cackeKey, _blocks ); | |
parsedBlocksCache.set( cacheKey, _blocks ); |
What?
In #58146, I didn't account for editing being made without the blocks key. This can happen when you change the content in the code editor, in which case the content needs to be parsed. Currently the cache will return the unedited blocks.
The solution is to change the cache key when edits are made. We can use the unedited record as a cache key when
getEntityRecordEdits
returns undefined or an empty object. I'm not sure why it sometimes returns an empty object. That sounds like a bug that needs to be fixed.Why?
How?
Testing Instructions
Testing Instructions for Keyboard
Screenshots or screencast