-
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
Try: Custom save serializer, Editable as array tree #4049
Conversation
e1fe602
to
20da270
Compare
Looks good to me at first sight, over #3048. Do you think this will be the way to go? I'll have a closer look in a bit. |
My only concerns currently are:
|
We should also be conscious of the fact that, if implemented, this could be used outside the context of the editor alone, if we plan to use A further concern is the fact that we are drifting more out of alignment with React, which as an abstraction layer is not a critical issues, so long as the changes are well documented. |
I really like this experiment. My main concern right now can be illustrated by this screencast: A dissonance is introduced between what is seen in the editor and what is seen on the front-end. I think that's fine (and desirable) for entities like ampersands and quotes, but—as observed—things get picked up as HTML tags. The following example with a wrapping |
If |
return null; | ||
} | ||
|
||
if ( node.nodeType === 3 ) { |
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.
We should use window.Node
here.
{ value && value.map( ( paragraph, i ) => | ||
<p key={ i }>{ paragraph.children && paragraph.children.props.children }</p> | ||
) } | ||
{ value.map( ( paragraph ) => paragraph.children ) } |
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.
It's unfortunate that this still means that the block author needs to be aware of the editable value structure.
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.
Actually, in this case this is the structure from the block attribute's query
result, necessary because there's no wrapper to separate content from the citation that would allow us to use the children
source directly.
Yeah, this is more or less how the logic works to detect the array as an element vs. an array of elements / strings. In our structure, we'd try to enforce children as an array so more accurately it would be gutenberg/element/serialize.js Lines 195 to 199 in 20da270
gutenberg/element/serialize.js Lines 174 to 182 in 20da270
(I might want to look to see if React elements are plain objects, and if not, whether we can generalize this logic to testing as a plain object, e.g. |
20da270
to
5ba4eae
Compare
Superseded by #5897 |
Closes #3353
Closes #2750
Related: #3048, #2463, #3713
This pull request seeks to explore using a custom element serializer without markup escaping and with built-in support for the "vanilla" element tree described in #2463, enabling us to represent the value of Editable as a simple object type, not a React element tree (enabling better collaborative editing via serializable values, server-side block templating of editable attributes).
React doesn't expose hooks for its server serialization, so I instead resorted to a custom implementation, a modified version of a library which implemented a simplified server renderer.