Skip to content

A select field's attribute schema (type: object) doesn't match its stored value (plain string), so it always renders as the default and poisons sidebar hydration for the whole block #208

Closed

Description

@chechman

Bug

A "type": "select" field's WordPress attribute schema is registered as type: 'object' with a {value, label} default — but the value actually serialized into the saved block comment (and returned by parse_blocks()) is a plain string matching one of options[].value. Since a plain string fails type: 'object' schema validation, WordPress core's WP_Block_Type::prepare_attributes_for_render() silently discards the stored value and substitutes the registered default. The render callback therefore always receives the default option, never whatever was actually selected/stored, regardless of post_content.

This also cascades in the block editor: on any block instance that includes at least one select-type field, every other attribute on that same block (plain text/textarea fields with correctly-typed schemas) fails to hydrate into the Inspector sidebar — fields show blank even though the real data exists in the database and renders correctly elsewhere — and edits typed into those blank fields are not persisted on save (confirmed: a typed value appears live in the canvas preview, but is absent from post_content after clicking Update).

Steps to reproduce

  1. A block with a select field and an unrelated text field:
{
  "$schema": "https://blockstudio.dev/schema/block",
  "name": "acme/example",
  "title": "Example",
  "category": "text",
  "blockstudio": {
    "attributes": [
      { "id": "heading", "type": "text", "label": "Heading" },
      { "id": "side", "type": "select", "label": "Side", "options": [
        { "value": "left", "label": "Left" },
        { "value": "right", "label": "Right" }
      ], "default": "right" }
    ]
  }
}
<?php
// index.php
echo '<div useBlockProps>heading=' . esc_html($a['heading'] ?? '') . ' side=' . esc_html($a['side'] ?? '') . '</div>';
  1. Create a page whose post_content is:
    <!-- wp:acme/example {"heading":"Hello","side":"left"} /-->
    
  2. View the page on the frontend.
  3. Open the page in the block editor and select the block.

Expected

  • Frontend: side=left.
  • Editor: Inspector shows "Hello" in the Heading field and "Left" selected in Side.

Actual

  • Frontend always renders side=right (the schema default), never left, no matter what's stored.
  • Editor Inspector shows both fields blank/empty — including Heading, despite its own schema being correctly typed string.
  • Typing a new value into Heading and clicking Update does not change post_content — the edit is silently lost. (Saving an untouched page is safe — only the typed edit itself disappears.)

What I verified

  • WP_Block_Type_Registry::get_registered('acme/example')->attributes['side'] → ['type' => 'object', 'field' => 'select', 'options' => [...], 'default' => ['value' => 'right', 'label' => 'Right'], ...]. The equivalent heading text field correctly registers as ['type' => 'string', 'field' => 'text', ...].
  • parse_blocks($post->post_content) returns the correct plain string ('side' => 'left') — WP core's comment parser is fine; the problem is downstream, at render/REST-attribute-sanitization time.
  • render_block(['blockName' => ..., 'attrs' => ['side' => 'left', ...]]) still resolves to 'right', both with a plain string and with the {value, label} object passed directly — reproduced the same way against a real saved page with global $post / setup_postdata() / apply_filters('the_content', ...), not just a synthetic call.
  • In the editor, wp.data.select('core/block-editor').getBlocks() shows the top-level attributes.side already coerced to {value: 'right', label: 'Right'} (the default), and a parallel attributes.blockstudio.attributes object — the one the Inspector sidebar panel actually reads from — with every field blank, including heading, which is a plain string at the top level.
  • No related JS console errors.
  • Bisected across the full release history: 7.0.0 (first GitHub release), 7.4.0, 7.7.13, and 7.7.14 (latest) all reproduce identically. This is not a regression — it's present as far back as there's a version to test.
  • Workaround: declaring the field as "type": "text" instead of "type": "select" avoids the broken schema registration entirely (plain text fields register correctly as type: 'string'), at the cost of losing the dropdown UI — the author has to type a valid value from a documented list instead of picking one. No data migration was needed in our case, since the values already stored in post_content were plain strings matching the options' value.

Environment

  • Blockstudio 7.7.13, also reproduced on 7.0.0, 7.4.0, 7.7.14
  • WordPress 7.1.4, PHP 8.3.23 (live Local by Flywheel site) and PHP 8.5.12 (WP-CLI) — identical behavior on both
  • Classic (GeneratePress child) theme, file-based blocks under blockstudio/blocks/<name>/, standard Gutenberg comment-delimited blocks (not <block> tag patterns)

Suspected cause

The attribute schema generated for a select field mirrors the shape the editor UI keeps in its own React state ({value, label}, so the sidebar can show a label without re-deriving it from options), but the value actually written into the saved block comment is the plain value string. WordPress core's attribute-schema validation (used both in WP_Block::render()'s prepare_attributes_for_render() and in the editor's own attribute parsing) treats that mismatch as invalid and falls back to the registered default — so the real stored selection can never survive a normal save→render round trip, and the mismatch appears to poison the editor's blockstudio.attributes mirror for the whole block, not just the offending field.

Happy to share the exact test block/page and the editor JS state dump if useful.

Activity

  1. chechman commented on Nov 11, 2026

    @chechman
    Author

    Follow-up with something that may help narrow this down: the broken top-level schema validation turns out to be avoidable entirely by including the editor's own "blockstudio":{"attributes":{...}} mirror alongside the flat attrs in the saved comment, e.g.:

    <!-- wp:acme/example {"side":"left","blockstudio":{"attributes":{"side":"left"}}} /-->
    

    With that mirror present, render_block() resolves side to 'left' correctly — the broken top-level type: object schema validation is bypassed entirely, presumably because the render path reads from blockstudio.attributes when it's present rather than the WP-core-sanitized top-level attrs.

    This also explains a second, related problem we ran into: any block comment built without that mirror (e.g. written programmatically, not through the editor) has every field — not just select fields — show blank in the Inspector sidebar, and typed edits into those blank fields don't persist on save. Adding the mirror to our own generated content fixed both issues at once. Mentioning it here in case it's useful context for tracking down the actual validation/rendering code path, or worth documenting as the expected comment shape for anything that writes Blockstudio block content outside the editor.

  2. dnnsjsk commented on Nov 12, 2026

    @dnnsjsk
    Contributor
  3. dnnsjsk commented on Nov 23, 2026

    @dnnsjsk
    Contributor

    Released in Blockstudio 7.7.15, via #209. Flat field values in imported block comments, including saved select values, now work in rendering and in the editor. Saving subsequent edits uses the existing blockstudio.attributes format. No migration is needed for existing content.

  4. chechman commented on Nov 23, 2026

    @chechman
    Author

    Released in Blockstudio 7.7.15, via #209. Flat field values in imported block comments, including saved select values, now work in rendering and in the editor. Saving subsequent edits uses the existing blockstudio.attributes format. No migration is needed for existing content.

    Can confirm 7.7.15 fixes this for me ✅

    • Updated on both staging and production
    • Re-tested the pages that were hitting the issue (imported block comments with flat field values + the blockstudio.attributes mirror)
    • Everything hydrates correctly in the editor now, no regressions elsewhere

    Thanks for the quick turnaround on this!

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