Skip to content
This repository has been archived by the owner on Jul 28, 2023. It is now read-only.

Commit

Permalink
Merge pull request #8 from DAreRodz/support-initially-hidden-inner-bl…
Browse files Browse the repository at this point in the history
…ocks

Support initially hidden inner blocks
  • Loading branch information
luisherranz authored May 5, 2022
2 parents dc567c0 + 11533bc commit 56d5c46
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Feel free to inspect the code, open issues, submit PRs, ask questions...
- [x] Make sure Frontend components are automatically rehydrated if they appear in the DOM at any point (not only on page load).
- [ ] Make sure Frontend components are automatically hydrated even if their component is registered after the connectedCallback execution.
- [x] Support partial hydration with Inner blocks (children raw HTML).
- [ ] Support initially hidden Inner blocks.
- [x] Support initially hidden Inner blocks: https://github.com/luisherranz/block-hydration-experiments/pull/8
- [x] Use `children` instead of `<InnerBlocks.Content />` in Save component to be able to reuse the same component in the Frontend.
- [x] Serialize attributes and pass them down to the Frontend component.
- [ ] Support definition of public frontend attributes and only serialize those.
Expand Down
19 changes: 18 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/frontend/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Title from "../shared/title";
import Button from "./button";

const Block = ({ blockProps, attributes, children }) => {
const [show, setShow] = useState(true);
const [show, setShow] = useState(false);
const [counter, setCounter] = useState(0);

return (
Expand Down
6 changes: 5 additions & 1 deletion src/gutenberg-packages/frontend.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class GutenbergBlock extends HTMLElement {
const blockProps = JSON.parse(
this.getAttribute("data-gutenberg-block-props"),
);
const innerBlocks = this.querySelector("gutenberg-inner-blocks");
const innerBlocks = this.querySelector("template.gutenberg-inner-blocks");
const Comp = blockTypes.get(blockType);
hydrate(
<EnvContext.Provider value="frontend">
Expand All @@ -41,6 +41,10 @@ class GutenbergBlock extends HTMLElement {
suppressHydrationWarning={true}
/>
</Comp>
<template
className="gutenberg-inner-blocks"
suppressHydrationWarning={true}
/>
</EnvContext.Provider>,
this,
);
Expand Down
5 changes: 5 additions & 0 deletions src/gutenberg-packages/wordpress-blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ const save = (name, Comp) =>
<InnerBlocks.Content />
</gutenberg-inner-blocks>
</Comp>
{/* Render InnerBlocks inside a template, to avoid losing them
if Comp doesn't render them. */}
<template class="gutenberg-inner-blocks">
<InnerBlocks.Content />
</template>
</gutenberg-interactive-block>
);
};
Expand Down

0 comments on commit 56d5c46

Please sign in to comment.