Include an example of blocks.getSaveElement use#8470
Include an example of blocks.getSaveElement use#8470danielbachhuber wants to merge 2 commits intomasterfrom
blocks.getSaveElement use#8470Conversation
aduth
left a comment
There was a problem hiding this comment.
This sort of usage (and in fact, the filter itself) may be something to discourage, as if the plugin is ever to later to be deactivated, the user will be presented with the "Modified Externally" warning, since the attribute would be destroyed on subsequent re-saves.
At minimum, we should be very clear about this caution, or avoid documenting getSaveElement altogether.
Related #6878 (comment)
Updated in f2f1c56 |
| if ( ! attributes.myCustomAttribute.length ) { | ||
| return element; | ||
| } | ||
| // Modifying nested JavaScript objects is pretty awful. |
There was a problem hiding this comment.
- This should probably be using
cloneElementto override props - Deep object assignment can be improved by using
_.mergeinstead
There was a problem hiding this comment.
Can you provide an example?
There was a problem hiding this comment.
// Bad:
return _.assign( {}, element, { myprop: 'foo' } );
// Good:
return wp.element.cloneElement( element, { myprop: 'foo' } );| element = lodash.assign( {}, element, { | ||
| props: lodash.assign( {}, element.props, { | ||
| children: [ | ||
| lodash.assign( {}, element.props.children[0], { |
There was a problem hiding this comment.
This will not assign data-custom-attribute when the image is assigned a URL. The deep override should be a signal of its fragility.
There was a problem hiding this comment.
I don't follow this either. Can you explain further?
There was a problem hiding this comment.
The markup shape changes depending on whether the image block has a url attribute assigned.
Aside: It's maybe telling that this is an easy thing to overlook.
|
I probably won't have time to pick this back up this week, so assigning to myself to clean up early next. |
|
Are you able to resume work here? |
I haven't been able to come back to this yet. The project work is still on my todo list though, so I'll pick up the documentation when I'm back on the project. |
Happened to need this for my project so thought I'd add example for this... Old PR WordPress#8470
No description provided.