RichText: Ensure HTML can be created from serialized object#10351
RichText: Ensure HTML can be created from serialized object#10351
Conversation
| onEndIndex, | ||
| } = settings; | ||
| const { formats, text, start, end } = value; | ||
| const { formats, text, start, end } = normaliseFormats( value ); |
There was a problem hiding this comment.
I know normaliseFormats is performant at the moment but this is the kind of function that can hurt the editor's performance pretty quickly if we made a not-good-enough change. How can we ensure it doesn't happen? Any ideas.
(don't require an immediate answer)
There was a problem hiding this comment.
That's an interesting question, but it's valid for any change within this package.
| expect( result.formats[ 1 ][ 0 ] ).toBe( result.formats[ 3 ][ 0 ] ); | ||
| expect( result.formats[ 2 ][ 1 ] ).toBe( result.formats[ 3 ][ 1 ] ); | ||
| // Should be serializable. | ||
| expect( JSON.stringify( record ) ).toBe( JSON.stringify( result ) ); |
youknowriad
left a comment
There was a problem hiding this comment.
Thanks for the updates Ella. Seems fine to me, I'll try to do some tests to approve.
What do you think about adding docs for the format and some higher level docs on how these toTree, toDom, create... fit together.
If we’re to support it for a long term, just make it explicit.
Yes I definitely plan to write some documentation on this and the format in general, just haven't been able to prioritise it so far. |
|
While testing, I noticed this being saved in the HTML <!-- wp:test/test {"content":{"formats":[null,null,null,null,null,[{"type":"strong"}],[{"type":"strong"}],[{"type":"strong"}],[{"type":"strong"}],null,null,null,null,null,null,null,null,null,null],"text":"test test test test"}} /-->It feels a bit weird to have a format for each character (all these nulls) It also produces this error: |
|
@youknowriad I fixed the problem. Explanation: When a value object is created, the formats are put into a sparse array, meaning that any space where there are no formats is just empty (not
When the serialised object comes back in, the empty places are I hope this makes sense!
Yes, so that's because of |
a39c179 to
24a1195
Compare
24a1195 to
a776108
Compare
|
Superseded by #10439. |

Description
We should make sure the format references are created before converting to HTML so it works correctly. This makes it possible to use the value in the HTML comments.
How has this been tested?
This blocks should work correctly:
Screenshots
Types of changes
Checklist: