8000 feat(core): a block can follow the blocks it reads in the preview by Klehm · Pull Request #101 · Klehm/content-blocks-project · GitHub
[go: up one dir, main page]

Skip to content

feat(core): a block can follow the blocks it reads in the preview - #101

Merged
Klehm merged 1 commit into
masterfrom
feat/preview-dependents
Dec 2, 2026
Merged

Klehm merged 1 commit into
masterfrom
feat/preview-dependents

Conversation

@Klehm
@Klehm Klehm commented Dec 2, 2026
Copy link
Copy Markdown
Owner

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:

    • block save (cb:block:preview), add, duplicate, move and delete;
    • section duplicate, move and delete;
    • the /block/{id}/render fallback.

    The builder posts one cb:block:replace per dependent. One that cannot be swapped (it opts out of hot reload, or its render throws) turns the answer into dependentsReload: 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 by preview-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 in docs/internals/frontend.md, both interfaces added to the BC-covered list.

Tests

  • PHPUnit: AreaBlocksTest, PreviewDependentsTest, and the block, section and render controllers plus BlockComponent.
  • Vitest: every builder path that swaps dependents, plus the reload fallback.
  • e2e: new preview-dependents.spec.js. Picker tile counts updated in builder-shell.spec.js and picker-categories.spec.js.
  • Full main and Encore suites green locally.

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.
@Klehm
Klehm merged commit 8d7cd20 into master Dec 2, 2026
53 checks passed
@Klehm
Klehm deleted the feat/preview-dependents branch December 2, 2026 13:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

0