Skip to content
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

Patterns: nested pattern block with overrides will not load #58291

Closed
glendaviesnz opened this issue Jan 26, 2024 · 7 comments · Fixed by #58541
Closed

Patterns: nested pattern block with overrides will not load #58291

glendaviesnz opened this issue Jan 26, 2024 · 7 comments · Fixed by #58541
Assignees
Labels
[Feature] Patterns A collection of blocks that can be synced (previously reusable blocks) or unsynced [Status] In Progress Tracking issues with work in progress [Type] Bug An existing feature does not function as intended

Comments

@glendaviesnz
Copy link
Contributor

Description

If you have a synced pattern block with overrides and you nest another synced pattern with overrides within it the nested block causes an exception.

Step-by-step reproduction instructions

  • Add a synced pattern with overrides set on at least one block
  • Create a second pattern with overrides and nest the first block in it
  • In a post insert the second pattern and notice the nested pattern causes and exception

Screenshots, screen recording, code snippet

Screenshot 2024-01-26 at 1 13 33 PM

Environment info

WP 6.4.2 and GB trunk

Please confirm that you have searched existing issues in the repo.

Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

Yes

@glendaviesnz glendaviesnz added [Type] Bug An existing feature does not function as intended [Feature] Patterns A collection of blocks that can be synced (previously reusable blocks) or unsynced labels Jan 26, 2024
@glendaviesnz glendaviesnz self-assigned this Jan 28, 2024
@github-actions github-actions bot added the [Status] In Progress Tracking issues with work in progress label Jan 28, 2024
@glendaviesnz
Copy link
Contributor Author

glendaviesnz commented Jan 28, 2024

@talldan, @kevin940726 I have taken a look at what would be needed to support nested patterns with overrides, and because the nested pattern does not get a <!-- wp:block {"ref":387} /--> entry in the post content all attribute changes would need to be somehow bubbled up to the root parent pattern to be saved in content.

A nested pattern's inner blocks are not resolved in the parent patterns edit component currently, so to get the attribute changes we would either need to resolve all nested pattern entities in the parent, or add some sort of context provider so nested patterns could push their changes up to the parent.

This adds an extra level of complexity that would require significant work and testing, and I don't see supporting nested patterns with overrides as critical for the first release in 6.5 so I suggest we go with the simple approach of disabling this for now - but happy to discuss further if you think we need to support this initially.

@kevin940726
Copy link
Member

because the nested pattern does not get a <!-- wp:block {"ref":387} /--> entry in the post content all attribute changes would need to be somehow bubbled up to the root parent pattern to be saved in content.

If I understand this correctly, I think this only affects when the user tries to edit nested patterns? Could we maybe instead disallow editing the patterns when they are nested in another pattern?

@glendaviesnz
Copy link
Contributor Author

Could we maybe instead disallow editing the patterns when they are nested in another pattern?

Hmm, interesting - it sort of negates the value of the pattern overrides if the pattern can't be edited once inserted in an instance in the editor, but will have a play around with this and see if it makes sense if we just change the wording of this to "You cannot edit a pattern with overrides when it is nested inside another pattern."

@glendaviesnz
Copy link
Contributor Author

glendaviesnz commented Jan 29, 2024

@kevin940726 I have updated the text of the editor message to You cannot edit a pattern with overrides when it is nested in another pattern. as it is possible, even though not much use, to nest a pattern with overrides in another, it is just not possible to load in the editor currently.

@kevin940726
Copy link
Member

Oh I mean a little bit differently I think. Let's say we have two overridable patterns 1 and 2. Pattern 1 has pattern 2 inside with overrides, and that can be edited in the pattern editor.

<!-- Pattern 1 -->
<!-- wp:block {"ref":2,"overrides":{...}} /-->

The post has pattern 1 with some other overrides.

<!-- Post -->
<!-- wp:block {"ref":1,"overrides":{...}} /-->

The post will render both pattern 1 and pattern 2, but could we disallow editing pattern 2 in this case? The other parts of pattern 1 can still be edited. WDYT? Or am I maybe misunderstanding the problem?


Now that I think about it, maybe bubbling the overrides isn't too difficult after all? Maybe all we need is to give the nested pattern a block id just like other synced blocks? That's probably for a future enhancement though 😅.

@talldan
Copy link
Contributor

talldan commented Jan 30, 2024

Bubbling is an interesting idea. Using @kevin940726's example above of Pattern 1 & 2, I think when you insert pattern 2 inside pattern 1, the editing experience of that inner pattern becomes a question mark. Are you allowed to set overrides at that point? And then when you insert pattern 1 into a post, can you override the overrides you set for pattern 2?

Being able to compose patterns and overrides in that way sounds pretty powerful, but also very complicated, so I'm not sure it's something to attempt until the feature has had more time to mature. It's also something a user might want control over, rather than being the default. 🤔

There's also an oddity that the overrides/content attribute starts to contain a lot more data than is directly referenced via the ref, so it might be worth thinking about the data structure more.

I think it might be best to explore fixing this for v1 without bubbling. Each pattern instance is self-contained and responsible for its own overrides. Users can still compose patterns, but inner instance overrides aren't editable from the outer instance (that seems to be what @kevin940726 is describing above).

@glendaviesnz
Copy link
Contributor Author

glendaviesnz commented Jan 31, 2024

The editing of the nested patterns in the parent patterns the wp_block entity edit screen just works as expected with not changes needed 😃

I have updated the fix PR to show the block with editing disabled instead of showing the can't nest message - seems to work.

Although editing of the nested patterns in the post may be possible with some changes I agree with @talldan that we should limit the complexity for this initial release of this feature and circle back on that later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Patterns A collection of blocks that can be synced (previously reusable blocks) or unsynced [Status] In Progress Tracking issues with work in progress [Type] Bug An existing feature does not function as intended
3 participants