8000 perf(core): a sidebar save ships the preview markup by Klehm · Pull Request #100 · Klehm/content-blocks-project · GitHub
[go: up one dir, main page]

Skip to content

perf(core): a sidebar save ships the preview markup - #100

Merged
Klehm merged 1 commit into
masterfrom
perf/preview-markup-in-save
Dec 2, 2026
Merged

Klehm merged 1 commit into
masterfrom
perf/preview-markup-in-save

Conversation

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

Why

A sidebar edit cost two requests: the save, then, after a 500 ms quiet period, GET /block/{id}/render (or /section/{id}/render) for the markup to swap into the preview. Every site using the builder paid a full extra request (kernel boot, session, firewall, Doctrine) and half a second per edit.

What

  • Block: BlockComponent::persistDraft() renders the block it just wrote (same renderBlock() + RenderContext::forPreview() as the endpoint) and dispatches the internal cb:block:preview ({blockId, html}) right before cb:block:saved.
  • Section: a settings save answers 200 {hotReload, html} instead of 204; the form relays it as cb:section:preview.
  • Builder: keeps that markup for the saved-event that follows, by id, at most once, and swaps it in at once: no request, no quiet period.

The public cb:block:saved / cb:section:saved are unchanged: the markup rides on internal events so it never becomes contract.

Fallbacks, unchanged

  • A type out of hot reload ships nothing → the old path (render endpoint, or full reload).
  • A render that throws ships nothing and never fails the save.
  • The render endpoints stay: fallback, column label saves, and the i18n workbench (other locale).

Measured (local, sandbox)

requests per edit blur → preview updated
before 2 (save + render) ~830 ms
after 1 ~150 ms

Tests

  • PHPUnit: the block save ships the markup before the saved-event; none for a type out of hot reload; a throwing render still saves. The section save answers 200 with the markup, or 204 if the render throws.
  • Vitest: swap with no fetch for blocks and sections; markup for another block is dropped and the render fetched; the form relays the markup before cb:section:saved.
  • Playwright preview-markup-in-save.spec.js: one request per block or section edit, no /render, preview updated (fails on master). responsive-display.spec.js now checks the save succeeded rather than its exact 204.
  • Full suites locally on Ubuntu 26.04: main e2e 258 green, Encore 11, Vitest and PHPUnit of every package, PHPStan, php-cs-fixer.

Docs: docs/internals/frontend.md#the-save-carries-the-preview-markup.

An edit cost two requests: the save, then, after a 500 ms quiet period,
GET /block/{id}/render (or /section/{id}/render) for the markup to swap in.
The save now renders the element it just wrote: BlockComponent dispatches
the internal cb:block:preview before cb:block:saved, and a section settings
save answers 200 {hotReload, html} instead of 204, relayed as
cb:section:preview. The builder swaps it in at once.

A type out of hot reload, or a render that throws, ships nothing: the save
still succeeds and the builder falls back to the render endpoint. Locally,
an edit now reaches the preview in ~150 ms instead of ~830 ms.
@Klehm
Klehm force-pushed the perf/preview-markup-in-save branch from 28a4afa to c9a4a7a Compare December 2, 2026 10:51
@Klehm
Klehm merged commit 056a320 into master Dec 2, 2026
104 of 106 checks passed
@Klehm
Klehm deleted the perf/preview-markup-in-save branch December 2, 2026 11:02
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