-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
RichText/Footnotes: make getRichTextValues work with InnerBlocks.Content #52241
Conversation
Size Change: +2.08 kB (0%) Total Size: 1.43 MB
ℹ️ View Unchanged
|
Flaky tests detected in 8f9041a. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/5506558379
|
ab7ac1b
to
630a191
Compare
ab2c3a3
to
28551f6
Compare
28551f6
to
a440616
Compare
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 testing nicely for me, thanks for the explanation as to the similarity with renderToString
. I'm not too familiar with this part of how rich text works, but the reasoning all sounds good to me, and this fixes up the issue nicely!
Before: adding the footnote in the List block does not update the Footnotes block to correctly reflect the newly added footnote. After: the Footnotes block is updated to reflect the newly added footnote:
Before | After |
---|---|
LGTM! ✨
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 looking pretty good, thanks for the quick turnaround!
I do worry about the performance implications of running getRichTextValues
on all blocks on every keystroke when all we need is to detect a change in the order of the footnotes. It seems to me we can easily improve things by breaking down the problem as follows:
BEFORE:
- On any change to blocks, run:
content := getRichTextValues( blocks )
- Search content for footnote anchors
newOrder := anchors.map( ( { id } ) => id )
- Compare new order with old
AFTER:
- Add cache to getRichTextValues, perhaps with a WeakMap
- On any change to blocks, run:
contentPieces = blocks.map( getRichTextValues )
(i.e. split the work and leverage the cache)
- Potentially add caching to the next stage (findAnchors) too:
newOrder = contentPieces.flatMap( findAnchors )
- Compare new order with old
We can investigate this in a follow-up PR, though.
const values = []; | ||
addValuesForBlocks( values, blocks ); | ||
getBlockProps.skipFilters = false; | ||
return values; |
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.
Since values is a const []
this code reads as if we always return []
?
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.
addValuesForBlocks
and subsequent calls all mutate that single array. Personally, I find it clear enough in the context of those four lines (otherwise values
would be totally inert), and it's consistent with other performance-minded functions in rich text.
…ent (#52241) * RichText/Footnotes: make getRichTextValues work with InnerBlocks.Content --------- Co-authored-by: Miguel Fonseca <[email protected]>
Cherry-picked into the |
…ent (#52241) * RichText/Footnotes: make getRichTextValues work with InnerBlocks.Content --------- Co-authored-by: Miguel Fonseca <[email protected]>
* Post and Comment Template blocks: Change render_block_context priority to 1 (#52364) * Footnotes: fix lingering format boundary attr (#52439) * Footnotes: Fix incorrect anchor position in Firefox (#52425) * Scope CSS rules for the wp admin reset to js support only. (#52376) * Fix: Patterns & template parts: remove "apply globally" option from block settings (#52160) * Advanced styles panel: add an early return * Update index.js * Minor styling changes * Use array of features --------- Co-authored-by: George Mamadashvili <[email protected]> * make the body of the editor minimmum viewport height so that smaller contents maintain clickability (#52406) * Patterns: Add renaming, duplication, and deletion options (#52270) * Patterns: Update manage pattern links to go to site editor if available (#52403) * [Patterns] Separate sync status into a filter control (#52303) Co-authored-by: Saxon Fletcher <[email protected]> Co-authored-by: Glen Davies <[email protected]> * Patterns: Add missing decoding entities processing in Patterns and Template/Parts pages (#52449) * Fix document title icon appearance (#52424) * Quote block: Add transform to paragraph (#51809) * Add ungroup transform as transform to p * Lint * Update test and snapshot. --------- Co-authored-by: Juan Aldasoro <[email protected]> * remove sidebar group descriptions (#52453) * Patterns: alternative grid layout to improve keyboard accessibility (#52357) * add sync tooltip (#52458) * Patterns: Update section heading levels (#52273) * Ensure that the unsaved title is not persisted when reopening the modal (#52473) * Iframe: avoid asset parsing & fix script localisation (#52405) * Iframe: avoid asset parsing & fix script localisation * Add e2e test for script localisation * Update descriptions (#52468) * Footnotes: show in inserter and placehold (#52445) * Footnotes: show in inserter and placehold * Fix placeholder block membrane; fix copy; add icon, label --------- Co-authored-by: Miguel Fonseca <[email protected]> * Fix: Focus loss on navigation link label editing on Firefox. (#52428) * Update tooltip (#52465) * Refactor, document, and fix image block deprecations (#52081) * Refactor, document, and fix image block deprecations * Fix v5 attributes & supports * Fix v1 & v2 deprecation tests * Rename deprecated test descriptions * Respect custom aspect ratio (#52286) * add image width and height via css inline style, update width and height attrs to be string * keep width and height as attributes too, keep the attributes as numbers * updates image fixtures * RichText/Footnotes: make getRichTextValues work with InnerBlocks.Content (#52241) * RichText/Footnotes: make getRichTextValues work with InnerBlocks.Content --------- Co-authored-by: Miguel Fonseca <[email protected]> * Footnotes: save numbering through the entity provider (#52423) * Footnotes: save numbering through the entity provider * Add sup so no styling is needed at all * Migrate old format * Restore old styles, fix nested attribute queries * Fix anchor selection * Migrate markup in entity provider instead * Fix tests * Fix typo * Fix comment --------- Co-authored-by: Miguel Fonseca <[email protected]> * Revert "Post editor: Require confirmation before removing Footnotes (#52277)" (#52486) This reverts commit e6426ea. * List block: Fix selected type option (#52472) * Library - make pattern title clickable (#51898) * Use button inside title * Remove href * Preserve roving tab index * Fix link colors to match trunk $gray-600 * Remove redundant var * Amend colors as per review * remove old files again --------- Co-authored-by: scruffian <[email protected]> * remove status icon (#52457) * Rename block theme activation nonce variable. (#52398) --------- Co-authored-by: Bernie Reiter <[email protected]> Co-authored-by: Ella <[email protected]> Co-authored-by: Aki Hamano <[email protected]> Co-authored-by: Andrea Fercia <[email protected]> Co-authored-by: Carolina Nymark <[email protected]> Co-authored-by: George Mamadashvili <[email protected]> Co-authored-by: Andrei Draganescu <[email protected]> Co-authored-by: Aaron Robertshaw <[email protected]> Co-authored-by: Kai Hao <[email protected]> Co-authored-by: Saxon Fletcher <[email protected]> Co-authored-by: Glen Davies <[email protected]> Co-authored-by: James Koster <[email protected]> Co-authored-by: Rich Tabor <[email protected]> Co-authored-by: Juan Aldasoro <[email protected]> Co-authored-by: Miguel Fonseca <[email protected]> Co-authored-by: Jorge Costa <[email protected]> Co-authored-by: Alex Lende <[email protected]> Co-authored-by: Héctor <[email protected]> Co-authored-by: Petter Walbø Johnsgård <[email protected]> Co-authored-by: Dave Smith <[email protected]> Co-authored-by: scruffian <[email protected]> Co-authored-by: Peter Wilson <[email protected]>
Opened #52577 |
What?
Fixes #52084.
getRichTextValues
currently does not work withInnerBlocks.Content
because this wrapsuseInnerBlocksProps.save
in a function that is not called when the tree is constructed. This PR will now "render" all the components in the save function, meaning it will just call all the functions to get the nested element trees and check for rich text props in there. It's similar torenderToString
in the@wordpress/element
package, but without creating a string. We just need to find rich text values and can skip all the rest.Why?
Footnotes is broken for blocks using
InnerBlocks.Content
;How?
See above.
Testing Instructions
Create a list blocks and add a footnote. It should add an entry in the footnotes block.
Testing Instructions for Keyboard
Screenshots or screencast