Gutenberg Prev Props doesn't get updated
Description
Hello
Here is details about issue:
Consider I have paragraph block with text below ( I have added it as HTML for more clarity ):
Contrary to <strong>popular</strong><strong> belief</strong>, Lorem Ipsum is not simply random text
Now, when this block load, Here how it look:
Contrary to <strong>popular belief</strong>, Lorem Ipsum is not simply random text
Its combine two strong tag into one. But when we check prevProps, the block attribute content isn't updated in prevProps.
so, is it bug ? or this is how Gutenberg suppose to behave. If so, can I get Gutenberg method where its combine two adjacent similar html tag into one.
Thank you for your help in advance.
Step-by-step reproduction instructions
- create paragraph block with some content
- Make two adjacent text to bold format
- then, this two strong tag will become one tag.
- Now if you check block attribute content in prevProps, it contain two different strong tag. Where it should be one strong tag as it have rendered.
Screenshots, screen recording, code snippet
No response
Environment info
- WordPress version 5.8.1
- Chrome browser
- Desktop with window 10
Please confirm that you have searched existing issues in the repo.
Yes
Please confirm that you have tested with all plugins deactivated except Gutenberg.
Yes
In Gutenberg, preProps are the past image of the current version of that element or the attribute. So, yes it is supposed to behave that way. It's not a bug.
My understanding is that two adjacent tags like that will be merged, it's the expected behavior.
What's the use-case for having two separate tags?
yes, it expected behaviour, but it should be also merge in prevPros attribute content. right now, it get merged on render, but if we check same block content in prevProps, it saparated.
@talldan we are developing one tool which used to identify changes that have been made to block. sometimes users add a bold format on a text which will be in the new STRONG tag, even if an adjacent text has a bold format, and we use block PrevProps to find out the changes.
so what exactly happen is ::
When we add bold format on "brlief" text below::
Contrary to <strong>popular</strong>belief
editor will have this::
Contrary to <strong>popular belief</strong>
But when we check PrevProps value in block, it have this ::
Contrary to <strong>popular</strong><strong> belief</strong>
where the editor value and PrevProps value should be the same.
Closing as working as intended: adjacent identical format tags are normalized/merged when the value is rendered — that's rich-text canonicalization, and comparing against pre-normalization props will always show that difference. No changes planned here; if this causes a concrete bug in a block, a report with that repro would be actionable.