Indicating context to innerBlocks #36582
Replies: 3 comments 5 replies
-
For me, the main point here is conceptual: the Overall, I'm not too concerned with any of the options though. Starting with the coupling avoids extra attribute/API and doesn't prevent us from introducing it later, doing the opposite is harder. |
Beta Was this translation helpful? Give feedback.
-
Thank you for these answers @glendaviesnz and @youknowriad! They're helpful. For our goals on the mobile-side, instead of continuing to pursue the addition of context constants in #35510, I ended up taking a different approach and adding a new block support, I'd be curious to hear whether this seems like an okay alternative to contexts or if there any better alternatives for meeting our goals. |
Beta Was this translation helpful? Give feedback.
-
Nice, this certainly covers the use case in web for the inner Image blocks of the gallery as the |
Beta Was this translation helpful? Give feedback.
-
Following on from a question raised by @SiobhyB here about why it was not considered good practice to be adding new contexts to pass down to inner blocks, based on concerns raised here and here by @danr and @youknowriad.
I don't think the idea of adding the additional contexts in general is frowned upon, it was just that our use of them in the Gallery block refactor was seen as non-standard.
Dan's concern was that normally a context value was a used to pass down a standard attribute value from a parent container to child blocks, but in the Gallery block the values we were setting were not being serialized as attributes in the parent. They were instead just constant values that the parent block never actually used or manipulated itself - hence the suggestion of a
contextConstant
value to differentiate them from the standard use of context values.Riad's view was that the Image block could just find out if it was part of a Gallery by using the data module instead of the parent block having to pass down a context to indicate this.
I think passing down the context values from the parent is a slightly less coupled approach than having to make the Image block aware of each of the different parent blocks that it might be part of, and how to behave with each parent. For example knowing what to do in a fixedHeight context is much less tightly coupled, and can be relevant to a range of different parent blocks, as apposed to knowing how to behave if my parent is a Gallery block.
I am also not sure that it is a big issue that some of these context may never be serialized into the parent block attributes, as there are a lot of cases where default attributes don't end up serialized in the block content if they aren't changed from the default.
I guess the key questions that need to be answered are:
context
value to behave to warrant a new API, eg. acontextConstant
?Beta Was this translation helpful? Give feedback.
All reactions