-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Core Data: Improve blocks cache in useEntityBlockEditor #75400
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
base: trunk
Are you sure you want to change the base?
Conversation
Replace WeakMap-based parsed blocks cache with a Map keyed by a stable string (kind:name:id) that validates content before reuse. This avoids re-parsing the same content when navigating away from an entity and back, since the cache key no longer relies on object identity. The new cache stores both content and blocks, validating that the cached content matches the current content before returning cached blocks. This preserves block clientIds across navigation, which is critical for selection restoration. Add tests validating cache preservation across unmount/remount and cache invalidation on content changes. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
|
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. |
|
Size Change: -11 B (0%) Total Size: 3 MB
ℹ️ View Unchanged
|
Extracted from #75371
What?
Replace WeakMap-based parsed blocks cache with a Map keyed by stable entity identity (kind:name:id). This improves cache behavior when navigating between entities. There's no big visible impact, maybe it's a small performance improvement but it's mandatory to be able to restore selection properly after entity navigation (see linked PR)
Why?
The previous WeakMap approach relied on object identity for cache keys. When navigating away from an entity and back, the entity record object reference could differ, causing a cache miss and unnecessary re-parsing of identical content. This prevented proper selection restoration after navigation.
How?
WeakMaptoMapwith string keykind:name:idTesting Instructions
Run the test suite:
npx wp-scripts test-unit-js --config test/unit/jest.config.js --testPathPattern="packages/core-data/src/test/entity-provider"All 4 tests in useEntityBlockEditor should pass: