-
Notifications
You must be signed in to change notification settings - Fork 11
Support initially hidden inner blocks #8
Support initially hidden inner blocks #8
Conversation
Exciting! 😄 Any ideas to avoid sending duplicate HTML? We'd need to detect if a block has inner blocks, but they are not in the output. I'm not sure we can solve it here, though. But it'd be nice to start discussing the approach. Astro does it in the compiler. My initial guess is that we would need to do it inside the serializer, checking if the rendered block contains By the way, I've just added you as a contributor. |
The Code Editor is crashing: Screen.Capture.on.2022-05-04.at.18-16-09.movThis is the saved content: <!-- wp:luisherranz/block-hydration-experiments -->
<gutenberg-interactive-block ...>
<div class="wp-block-luisherranz-block-hydration-experiments">
<h2 class="title">Block title</h2>
<button>Show</button><button>0</button>
</div>
<template class="gutenberg-inner-blocks"
><!-- wp:paragraph -->
<p>This is an inner paragraph</p>
<!-- /wp:paragraph --></template
></gutenberg-interactive-block
>
<!-- /wp:luisherranz/block-hydration-experiments --> It looks fine to me. I'm not sure if this is a Gutenberg bug because one hook is crashing and React is complaining that the order of hooks is wrong. |
I talked too soon. This is also happening in the |
I also experienced some problems, but I assumed they came from different block renders after modifying the component. 🤔 |
I've debugged it, and it's because of the throw of I'll open an issue to inform, but I don't think we need to fix that because it'll never make it to Gutenberg. So, any ideas to avoid sending duplicate HTML? 🙂 EDIT: Issue opened #9 |
I don't have any ideas yet, haha. 😄 I'm trying using the |
There are some docs for that filter as well. 👀
EDIT: Okay, that's actually not true. I'll take a deeper look because I experienced that previously. |
This is something we shouldn't solve using filters if we ever add this to Gutenberg, so maybe it's not worth trying to solve it here David. It's good to know that I'll merge this as it is and we can solve the duplication later 🙂 |
<template | ||
className="gutenberg-inner-blocks" | ||
suppressHydrationWarning={true} | ||
/> |
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.
@DAreRodz Why do we need to render this empty template
here? If I comment it out, it seems that I can still render initially hidden inner blocks. 🤔
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.
It's simply to avoid a hydration warning. 😄
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.
oh duh, thanks :)
This PR adds support for hidden inner blocks.
It duplicates
<InnerBlocks>
inside a<template>
tag next to the block component. During component hydration, the<template>
tag is emptied.