Skip to content

perf: skip the hidden fields pass on editor load when a block needs no defaults #151

Closed

Description

@Contributolo

Every Blockstudio block mounts its complete <Fields portal /> tree into document.body when its edit component mounts, keeps it for 100 ms, and only then renders the preview (src/blocks/index.tsx:85-110, gate at line 134). In portal mode all group and tabs panels are forced open (components/panel/index.tsx:84, components/el/index.tsx:46), so every field mounts, including one TipTap editor per wysiwyg field per repeater row.

As far as I can tell, the pass exists for three side effects that only happen while the field UI is mounted:

  1. Repeaters with min (also nested) and no value write their minimum rows from inside element() during render (components/fields/index.tsx:243-275). All other defaults already come from the registered blockstudio attribute default (utils/get-default-block.ts), and the effect at fields/index.tsx:99-115 only runs with config.
  2. Code fields with asset: true inject their style or script into the canvas in an effect (fields/components/code.tsx:186-206). The server skips these assets in the editor (includes/classes/block.php:2536).
  3. Custom field types may run mount effects.

With the pass disabled, freshly inserted blocks got identical attributes, except that the minimum repeater rows and the asset style were missing. For blocks loaded with stored values none of this applies, but the whole tree is mounted anyway.

Two smaller things: the wrapper uses css({ display: 'hidden' }) (src/blocks/index.tsx:98), which is not valid CSS, so the container is laid out below the editor (921 px tall for the first block in my test). And the pass ends after a fixed 100 ms, not when it is done: with 4x CPU throttling only 38 of 62 editors had mounted before it was removed.

Measurement: WordPress Playground (PHP 8.4), Blockstudio 7.7.5, a real theme, a page with 30 blocks saved with full attributes (repeaters with 3 to 4 rows, nested repeaters, wysiwyg, files, links, selects). Headless Chromium, runs interleaved, median of 6. "Ready" means all 30 previews are in the canvas and no spinner is left.

7.7.5 proposal
ready 3445 ms 1692 ms
script time (CDP) 815 ms 437 ms
long tasks total 556 ms 144 ms
style recalc 95 ms 30 ms
DOM nodes in hidden containers 7185 0
ProseMirror instances created 62 0
JS heap 128 MB 85 MB

With 4x CPU throttling: ready 5.8 to 7.1 s vs 3.1 to 4.0 s.

Proposal:

  1. Compute repeater minimum rows with a pure function at registration, next to the existing defaults in getDefaultBlock, recursively, using getDefaults for the row fields as the field already does. Fresh inserts then get their rows from the attribute default.
  2. Before mounting the hidden pass, walk the field definitions and the stored values once. Only mount it if a repeater with min or default rows is still empty, an asset code field exists, or a custom field type is used. Otherwise render the preview right away.
  3. Possible follow-up: inject code field assets from a small hook without mounting CodeMirror, so the hidden pass can go away completely. Until then, use display: none on the wrapper.

I tried this locally (about 110 lines, src only). Inserted blocks get the same attributes as in 7.7.5, the asset style is still injected, and a stored page loads with identical attributes, no dirty state and no undo entry. As a side effect, inserting a block no longer creates an extra undo step for the row write (today one undo leaves the block with a half-written row), and the repeater/nested and repeater/complete fixtures get the full nested rows with field defaults even when the block is not selected.

Is this the direction you want? If so I'll open a PR with e2e coverage for insert defaults and stored-content load.

Activity

  1. dnnsjsk commented on Oct 22, 2026

    @dnnsjsk
    Contributor

    Released in Blockstudio 7.7.6. Ordinary blocks now skip the hidden field initialization pass; compatibility initialization only runs when needed, and nested repeater minimum rows and defaults are prepared before insertion without extra undo steps. Implemented in c9521d2, with follow-up nested-default coverage in 748d5bc. The release commit passed the full CI and distribution suites.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions