-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
WIP: Blocks: Reimplement shared block as embedded editor #7453
Conversation
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.
Very clever! I haven't looked at this closely yet but I like the idea.
Just dropping a note to be careful when dropping the shared blocks API controller. It has a few workarounds in it which ensure that only certain roles can read and delete shared blocks, see #4725.
* | ||
* @dataProvider data_capabilities | ||
*/ | ||
public function test_capabilities( $action, $role, $expected_status ) { |
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 don't think we should remove these tests. They help us prevent #4725 from regressing.
Yeah, fair to say its removal is tentative, though I'd like to see it gone, merely for the inconsistencies it has with the posts responses, and the fact that it doesn't seem like it should be any more special than a standard post. Shouldn't the posts endpoint already be accounting for these capabilities? |
In theory, yes. I vaguely remember running into some issues with the WP API posts controller. So long as we confirm that the capability checking hasn't regressed (e.g. by keeping |
Reference to original implementation as reference in preparation for pending rebase: 58c5103 |
58c5103
to
21d74e4
Compare
Rebased to account for the new data registry implemented by @youknowriad in #7527 . This is still very much work-in-progress, but it's back to a workable state, and simpler too now with the new registry. I'm curious to get feedback on the idea with cloning registries / creating editor stores. I added a |
I really like the overall approach! I'm fine with how Are you OK for me to pick this PR up and sand off the remaining rough edges? I'm not sure how your schedule looks 🙂 From my very quick testing, I spot these problems:
The E2E tests that I added in 5eb5fdd should act nicely as a set of acceptance tests for this PR. |
Yes! Please feel free. |
❤️ ❤️ ❤️ |
21d74e4
to
fc7a096
Compare
I rebased and fixed some of the regressions identified above. Will continue on this tomorrow. One regression that I'm struggling with is that changes to a shared block aren't picked up by other blocks on the page. For example:
(The same issue manifests itself in a few different ways. For example, if you change a shared block's title, the inserter doesn't immediately update to have the new title.) I suspect that this happens because changes to a Does that make sense, @aduth? Do you have any ideas on how to address this? |
While editing the shared blocks, I'd say it's acceptable, but we should probably rely on the serialized value of the original store when we're not in |
Unfortunately this doesn't work when previewing e.g. a shared columns block because |
I guess I assumed that there's a two-way sync between both states: <EmbedRegistry>
<EditorProvider onChange={updateSharedBlock} post={sharedBlock}>
</EditorProvider>
</EmbedRegistry> Having this kind of API would be ace, not only for this shared block issue but also to reuse Gutenberg as a standalone editor (passing a value, and having changes persisted with |
fc7a096
to
9e7b7a3
Compare
Any updates on this, could this be expected to get merged before 5.0? |
Yes, it's something we want to get in. I've been working on other tasks but hopefully can focus on this again soon. At the very least it would be good to deprecate the REST API endpoint which I think is the only breaking API change involved. |
Splitting off the refactoring to remove |
While I'd love for this to happen sooner rather than later. It doesn't seem ready for 4.2 (or close to be ready). Thoughs @noisysocks |
Nooo, another month or something without converting reusable block templates with nested blocks (crying like a baby) |
Agreed. I'll go further and say that I'd be OK with punting this work to Phase 2 because:
|
My bigger issue at this point is the inclusion of related actions and selectors as part of the public API, and whether that will be something we can deprecate after a phase one. Maybe need a pass at prefixing |
That's a good point. I should have bandwidth this week to replace the reusable block selectors and actions with edit: 🤦♂️ Wasn't thinking straight—we can't use the data methods unless we also swap out |
Closing this PR for now—will split it out into smaller PRs going forward. |
So how has this been resolved? Every page of my site has reusable blocks of images that I cannot access now. I do not know how this happened in my case, I was editing and working with blocks. I think that one of my pages has a section with the old editor and this caused it? IDK, the blocks are still "there" I'm not a tech person, I just barely know how to do this. Help. |
@ezkitcabs I'm not familiar with the issue you describe, and the effort in this pull request was not included in any WordPress release, nor do I think it would be related to what you're describing. For general troubleshooting and support, your best option will be to search / post to the WordPress support forum. If after troubleshooting it can be determined there's a bug in the block editor, a new issue should be created in this repository detailing the steps to recreate the issue. |
Related: #7409, #7130
Closes #7119
Note: Work-In-Progress. Most basic behaviors work as expected, though lack some of the UX polish which had existed previously around intermediate states (saving, etc), unit tests, documentation.
This pull request seeks to explore a reimplementation of the shared block to render its editable form as a nested instance of
<EditorProvider><BlockList /></EditorProvider>
.In doing so, it explores:
core/data
namespace (e.g.core/editor-shared-8174
)@wordpress/data
are shared in a common global namespaceselect
calls within an element tree viawithCustomReducerKey
to avoid each descendent needing to be updated to account for the custom store namespacegutenberg/editor/components/provider/index.js
Lines 130 to 136 in 58c5103
REQUEST_POST_UPDATE
since it is in-fact a post, rather than a customSAVE_SHARED_BLOCK
action)state.sharedBlocks
, since as being part of its own provider context, it can simply call the same selectors for edited post (e.g.getEditedPostAttribute( 'title' )
to retrieve the shared block title)gutenberg/core-blocks/block/edit-panel/index.js
Lines 128 to 134 in 58c5103
There's some future work here that may enable removing all shared block knowledge from the top-level editor, not addressed here:
core
data namespace