Skip to content

Render classic meta boxes in iframes - #82198

Draft
ellatrix wants to merge 18 commits into
trunkfrom
try/render-meta-boxes-in-iframes
Draft

ellatrix wants to merge 18 commits into
trunkfrom
try/render-meta-boxes-in-iframes

Conversation

@ellatrix

@ellatrix ellatrix commented Aug 28, 2026 •

Copy link
Copy Markdown
Member

What?

Renders classic meta boxes in iframes that load the classic edit screen, instead of moving server rendered markup into the editor page. This is the rendering swap only. Refreshing the boxes on revision restore builds on top of it in a follow up.

Why?

Classic meta boxes are PHP rendered snapshots that the editor moves around its own DOM and cannot re-render. An iframe gives them a real classic document of their own: classic scripts run natively with no deferred initialization, their markup and styles cannot collide with the editor, and the document can be loaded again at any time, which gives features like revision restore and collaboration a way to bring the boxes up to date.

How?

  1. The loader page. The existing meta box loader URL renders the classic edit screen. A new parameter trims that page down to the meta boxes: admin chrome and the classic editor are hidden, meta boxes registered for backwards compatibility are removed (the editor renders their replacements), each iframe renders only its locations, the classic autosave is dequeued, and form submissions are prevented.
  2. Two iframes. One in the settings sidebar for the side location, which sizes itself to its content, and one in the bottom pane for normal and advanced.
  3. Media queries answer for the parent window. The iframes are narrower than the window, so small screen styles would wrongly apply. A bootstrap script rewrites width based @media conditions through the CSSOM to all or not all based on parent.matchMedia(), keeps them updated on window resizes, and wraps window.matchMedia the same way. Desktop minimum widths are overridden where the sidebar is narrower than they allow.
  4. Cross-origin isolation. The editor page may send Document-Isolation-Policy (for client side media processing), and an isolated document cannot script same origin frames that are not isolated the same way. The loader page sends the same header under the same conditions.
  5. Saving. Unchanged request, new source: each iframe's form is submitted with requestSubmit(), as if a button were pressed, so meta boxes that serialize their values in submit handlers run first (TinyMCE saves its editors from its own submit handler). The loader cancels every submission at the capture phase so the form never navigates, and renders a hidden formnovalidate submit button for the save flow to submit with, which skips constraint validation that would otherwise silently abort on invalid fields inside hidden boxes. The fields inside the meta boxes are then collected with the browser's own form serialization, merged with the base form data, and posted to the meta box loader as before.
  6. The editor page renders no meta boxes. The markup and callbacks are skipped there, the list of available meta boxes is dispatched from the filter that skips them, and the meta box visibility preferences are applied inside the iframe documents.

Known gaps

  • Unsaved meta box edits are lost when an iframe unmounts: closing the settings sidebar or switching to the Block tab for the side location. A follow up should keep the iframes mounted in a persistent layer positioned over their slots.
  • Plugin meta box scripts and styles still enqueue on the editor page even though nothing uses them there.
  • Third party plugin CSS written for desktop widths may need more overrides in the narrow sidebar iframe.

Testing Instructions

  1. Activate a plugin registering classic meta boxes, e.g. the gutenberg-test-plugin-meta-box test plugin, or the demo plugin Add end-to-end coverage for TinyMCE and side location meta boxes #82199 adds with a variety of boxes.
  2. Open a post. Side location boxes render in the settings sidebar, the others in the Meta Boxes pane.
  3. Fill values in several boxes, including the TinyMCE box, and save. Reload and confirm they persisted.
  4. Toggle meta boxes in Preferences and confirm they hide and show.
npm run test:e2e -- --project=chromium test/e2e/specs/editor/plugins/meta-boxes.spec.js

Testing Instructions for Keyboard

Tab from the editor into the meta box pane and sidebar boxes; fields, postbox toggles, and the move buttons are reachable and operable with the keyboard inside the iframes.

Screenshots or screencast

Editor with meta boxes in the sidebar and pane

Use of AI Tools

Written with the assistance of Claude Code, reviewed and tested by hand.

The classic meta boxes now render in two iframes loading the classic
edit screen through the meta box loader URL: one in the bottom pane for
the normal and advanced locations, one in the settings sidebar for the
side location. The loader page trims the screen down to the meta boxes,
sends the same Document-Isolation-Policy header as the editor, and
rewrites dimension media queries so styles respond to the editor
window instead of the iframe. Saving dispatches a submit event in each
iframe so submit handlers and TinyMCE write their values, then collects
the fields with the browser's form serialization. The editor page no
longer renders the meta boxes at all.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@github-actions github-actions Bot added [Package] Edit Post /packages/edit-post [Package] E2E Tests /packages/e2e-tests labels Aug 28, 2026
@github-actions

github-actions Bot commented Aug 28, 2026 •

Copy link
Copy Markdown

Size Change: -1.35 kB (-0.02%)

Total Size: 7.92 MB

📦 View Changed
Filename Size Change
build/scripts/edit-post/index.min.js 52.5 kB -191 B (-0.36%)
build/styles/edit-post/style-rtl.css 2.92 kB -399 B (-12.04%) 👏
build/styles/edit-post/style-rtl.min.css 1.78 kB -185 B (-9.41%) ✅
build/styles/edit-post/style.css 2.92 kB -398 B (-12%) 👏
build/styles/edit-post/style.min.css 1.78 kB -182 B (-9.25%) ✅

compressed-size-action

@ellatrix ellatrix closed this Aug 28, 2026
@ellatrix
ellatrix deleted the try/render-meta-boxes-in-iframes branch August 28, 2026 21:23
@ellatrix
ellatrix restored the try/render-meta-boxes-in-iframes branch August 28, 2026 21:26
@ellatrix ellatrix reopened this Aug 28, 2026
ellatrix and others added 2 commits August 28, 2026 14:42
The loader changes how meta boxes render unconditionally, with no
experiment toggle, so it is core bound code and belongs in
lib/compat/wordpress-7.0, not lib/experimental.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The plugin is only used by the new end-to-end tests, so it belongs in
the same change as those tests.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@github-actions github-actions Bot removed the [Package] E2E Tests /packages/e2e-tests label Aug 28, 2026
ellatrix and others added 11 commits August 28, 2026 15:04
The Preferences modal checkboxes no longer toggle a block editor panel
preference. They save to the metaboxhidden_{screen} user option over
the same admin-ajax action the classic Screen Options use, so both
editors share one visibility setting and the loader page renders the
boxes hidden on the server. The listing dispatched to the editor now
carries each box's hidden state, and the injected visibility style
sheet is replaced by a sync of the rendered boxes with the store.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The require was left behind when the file moved out of experimental.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
A memoized private selector returns the hidden meta box ids as a
stable array, the iframe tracks its document through the load event,
and an effect toggles the hide-if-js class the admin styles already
hide boxes with, instead of building a style sheet. Toggling the class
both ways also stops the classic Screen Options hidden state from
applying inside the iframes, which the block editor ignores.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The script that adapts the classic screen to the iframe now lives in
meta-box-iframe.js, printed inline by the PHP so that it is not a
registered script anything can depend on. It also applies the editor's
meta box visibility preferences itself: a style built from the parent's
preferences hides boxes before first paint, and the boxes follow later
changes through a parent store subscription, so the editor side needs
no code for it. The classic Screen Options hidden state no longer
applies inside the iframes, which matches how the block editor treats
it. The save flow finds the iframes by their frame names through the
elements; the browsing context names are cleared under the editor's
Document-Isolation-Policy, so window.frames cannot resolve them.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
It is the only caller, so the lookup does not need to be a utility.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The form submits as if a button were pressed: a real, trusted submit
event with a submitter. The loader page cancels every submission at
the capture phase, which no meta box handler can prevent, so the form
never navigates, and the temporary submitter skips constraint
validation, which would otherwise silently abort on invalid fields
inside hidden meta boxes.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The loader page renders the hidden submit button at the top of the
post form instead of the save flow creating a temporary one, so
submitting the form is a plain requestSubmit call, and pressing Enter
in a field uses the same submitter.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The save flow skips documents without the post form, still loading or
failed, in one place instead of each step guarding on its own.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The fields are collected right after each form is submitted, with the
form reached through the submit button, and a document is skipped when
the button is missing because the page is still loading or failed to
load.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Aug 29, 2026 •

Copy link
Copy Markdown

Flaky tests detected in 0f95851.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/33226908617
📝 Reported tests:

passes the search value in the main inserter when clicking `Browse all` in /test/e2e/specs/editor/various/inserting-blocks.spec.js, passed after 1 failed attempt.
TimeoutError: locator.fill: Timeout 10000ms exceeded.
Call log:
  - waiting for getByRole('searchbox', { name: 'Search' }).first()

    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/various/inserting-blocks.spec.js:750:5

ellatrix and others added 4 commits August 28, 2026 17:28
The loader now renders a bare admin iframe document with only the post
form and the requested meta boxes, using the same core functions the
classic edit screen is built from, instead of loading the full classic
screen and hiding most of it.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The screen flag makes do_meta_boxes() skip the boxes the block editor
replaces, so the removal pass is no longer needed, and the poststuff
wrapper from the block editor page restores the admin postbox styles.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The block editor page no longer renders the boxes, so instead of
re-sending the listing core computes from a footer script, each iframe
reports the boxes in its own document to the editor's store. The
iframes stay mounted while hidden, since their documents are now the
source of that listing.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
A modal opened inside an iframe cannot render outside of it, so the
loader script watches its document for one, a fixed element covering
the viewport, and the frame grows to cover the whole editor while it is
open. The stacking contexts between the frame and the page are
flattened for the frame's level to decide, and the pane's shadow moves
from a filter to a box-shadow since a filter would confine the frame.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@ellatrix
ellatrix force-pushed the try/render-meta-boxes-in-iframes branch from 2454011 to 4ef214b Compare August 31, 2026 19:18

This branch has not been deployed

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

Labels

[Package] Edit Post /packages/edit-post

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant