Repository navigation
feat(core): a block can follow the blocks it reads in the preview - #101
Merged
Merged
Conversation
A block type implementing PreviewDependentInterface answers dependsOn($block, $changed), by type or by the block a field targets. Every action that patches the preview in place (block save, add, duplicate, move, delete; section duplicate, move, delete) renders the live dependents into its own response, and the builder swaps them in place. One that opts out of hot reload, or fails to render, turns the answer into a full reload. AreaBlocksInterface lists the blocks a mode renders, in page order, with the data that mode reads, so a dependent's resolver shows the draft in the builder and the published state on the public page. The sandbox gains a counter total block, pinned by preview-dependents.spec.js.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Hot reload swaps one block at a time. A block whose view shows what other blocks hold (a total under a product list) kept its old figure after an edit, and the only way around it was to opt the edited block out of hot reload: a full preview reload on every keystroke.
What
PreviewDependentInterface(optional, on a block type):dependsOn(Block $block, Block $changed): bool. It is asked of the dependent, by type or by the block one of its fields targets.Every action that patches the preview in place renders the live dependents into its own response, so there is no extra request:
cb:block:preview), add, duplicate, move and delete;/block/{id}/renderfallback.The builder posts one
cb:block:replaceper dependent. One that cannot be swapped (it opts out of hot reload, or its render throws) turns the answer intodependentsReload: true, which triggers a full reload.AreaBlocksInterface: the blocks a mode renders, in page order, and the data that mode reads (the draft in the builder, the published state on the public page). A dependent's resolver reads its neighbours through it instead of walking the entities and showing unpublished content.No cost for hosts that don't use it: the area is not walked unless a registered type implements the interface.
Not transitive: a block that reads a dependent should declare the real source.
The sandbox gains a "Total des compteurs" block (
CounterTotalBlock+CounterTotalResolver), pinned bypreview-dependents.spec.js: edit, duplicate and delete refresh it without reloading the preview, and the public page keeps the published sum.Docs: guide section Blocks that read other blocks in
custom-blocks.md, rationale indocs/internals/frontend.md, both interfaces added to the BC-covered list.Tests
AreaBlocksTest,PreviewDependentsTest, and the block, section and render controllers plusBlockComponent.preview-dependents.spec.js. Picker tile counts updated inbuilder-shell.spec.jsandpicker-categories.spec.js.