-
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
Synchronise inner block attribute updates to a partially synced parent pattern block #50649
Synchronise inner block attribute updates to a partially synced parent pattern block #50649
Conversation
- Use a BlockEdit filter to optionally wrap the setAttributes function when a partially synced pattern block exits - Merge inner block attributes updates into a pattern block `content` attribute - Batch the updates into one action`
Size Change: +265 B (0%) Total Size: 1.39 MB
ℹ️ View Unchanged
|
return <BlockEdit { ...props } />; | ||
} | ||
|
||
const setContentAttributes = useCallback( |
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.
Worth noting that this "monkey patching" technique likely won't work if the child decides to call updateBlockAttributes
directly from useDispatch
. We might want to think of an alternative, but I think it's good to make this work as a POC first here so that we can discuss other topics 👍 .
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 a really good point. 👍
This might be ok as a proof of concept for partial syncing, but in the long run it looks like it'd be best to explore a different solution.
Flaky tests detected in 2bded3a. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/4988011851
|
I've been thinking about what alternative solutions to this might look like:
|
I've been playing with two different prototypes to see whether we can avoid changing the block editor store and/or overloading I started with #50777 implementing the concept of converting all template content data into virtual blocks I switched to another prototype that is still in progress, but you can watch the progress in #50901. The new idea is similar to this PR, and I probably recreated some aspects on it as I had this branch open during the development. I came up to the conclusion after playing with controlled and uncontrolled inner blocks, that the simplest model is to always use the copy of the design while editing with the template lock enabled that allows only changing content. The whole challenge would be to mark every block that can receive edits with a unique name and list the attributes that can be edited. Once we have it in place in both the source pattern storing the design, and the copy where we edit content, we can parse both HTML representations and use the marked places for all necessary transformations that I can explain later in more detail. |
Implemented by #56235 |
What?
Related: #50456, #48458, #50159
This is an experimental proof of concept PR for the pattern block. When the pattern block is partially synced, a goal is to store any child block attributes that have
content: role
in an attribute of the pattern block itself.There are a few different way this could be achieved. This PR tries monkey patching the
setAttributes
function for blocks that are a child of a partially synced pattern, so that attribute changes are stored both on the parent pattern block and the child block.Why?
The idea is that eventually these attributes will be used to dynamically render the pattern block
How?
BlockEdit
filter to create a higher order component around blocksBlockEdit
component as normalsetAttributes
function to additionally store attribute changes on the pattern block.Testing Instructions
Prerequisite: enable the Enhanced Patterns experiment toggle in the Gutenberg plugins experiment screen.
<!-- wp:pattern {"slug":"twentytwentythree/cta", "syncStatus":"partial"} /-->
Problems to solve
__experimentalRole: 'content'
data-attribute
keys as described in Partially synced patterns #50456, but they still need to be implemented.Screenshots or screencast