-
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
RichText: Ensure HTML can be created from serialized object #10351
Conversation
@@ -34,7 +35,7 @@ export function toTree( value, multilineTag, settings ) { | |||
onStartIndex, | |||
onEndIndex, | |||
} = settings; | |||
const { formats, text, start, end } = value; | |||
const { formats, text, start, end } = normaliseFormats( value ); |
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 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's an interesting question, but it's valid for any change within this package.
@@ -27,5 +27,7 @@ describe( 'normaliseFormats', () => { | |||
expect( result.formats[ 1 ][ 0 ] ).toBe( result.formats[ 2 ][ 0 ] ); | |||
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 ) ); |
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 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.
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: