Skip to content

Conversation

@dcalhoun
Copy link
Member

@dcalhoun dcalhoun commented Oct 21, 2025

What?

Fix undefined reference error causing remote editor loading failure.

Why?

Address #193 (comment). The error leaves the remote editor in a broken state.

How?

Update getBlockTypes() to lazy-load the required @wordpress/blocks dependency, ensuring the relevant global is available before access it.

Testing Instructions

  1. Enable the native inserter.
  2. Add and load a remote editor.
  3. Open the block inserter.
  4. Verify blocks are listed.

Accessibility Testing Instructions

N/A, no user-facing changes.

Screenshots or screencast

N/A, no user-facing changes.

@dcalhoun dcalhoun added the [Type] Bug An existing feature does not function as intended label Oct 21, 2025
@dcalhoun dcalhoun marked this pull request as ready for review October 21, 2025 17:35
@dcalhoun dcalhoun requested a review from kean October 21, 2025 17:35
Copy link
Contributor

@kean kean left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error leaves the remote editor in a broken state.

My bad – I never used a remote editor for testing.

// Lazy-load getBlockTypes to defer the import until this function is called.
// In the remote editor, dependencies are loaded asynchronously, so this ensures
// window.wp.blocks is defined before we access it.
const { getBlockTypes } = await import( '@wordpress/blocks' );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL: await import

Base automatically changed from task/ios-demo-app-discovers-remote-editors to trunk October 21, 2025 20:00
We cannot reference `@wordpress` modules in the remote editor runtime
until after the site-specific scripts are loaded. Utilizing a dynamic
import defers the global `window.wp` reference.

We now also apply the same transformations made to static imports to
dynamic imports as well.
@dcalhoun dcalhoun force-pushed the fix/defer-native-inserter-wp-global-reference branch from b57569c to b57d479 Compare October 21, 2025 20:00
@dcalhoun dcalhoun enabled auto-merge (squash) October 21, 2025 20:01
@dcalhoun dcalhoun merged commit 83232e9 into trunk Oct 21, 2025
11 checks passed
@dcalhoun dcalhoun deleted the fix/defer-native-inserter-wp-global-reference branch October 21, 2025 20:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Type] Bug An existing feature does not function as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants