Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set the API context when using Comlink.wrap() (#1085)
Fixes WordPress Playground Block not loading when the Site Editor is wrapped in an iframe. Playground uses Comlink to talk to the remote API via `window.postMessage()`. By default, Comlink binds the `message` event listener to the current global window object. However, when the Site Editor is iframed, the `startPlaygroundWeb` function runs in the global `window` context, but the Playground iframe lives inside of the Editor Canvas iframe context. Playground's `remote.html` would then send all its messages (via `postMessage`) to the parent window, which is Editor Canvas and not the global `window`. As a result, Comlink would never notice any communication and the Playground wouldn't load. This PR ensires the `context` argument is always set to Playground's iframe parent window. ## Testing instructions This is convoluted: 1. Clone https://github.com/WordPress/playground-tools/tree/trunk/packages/wordpress-playground-block 1. Update the remote URL to `http://localhost:5400/remote.html` 1. Build the `@wp-playground/client` package in this repo and substitute the block's dependency with it (or use npm link) 1. Run the Playground block in the dev mode (as described in its README) 1. Install the Gutenberg plugin to enable iframe-based Canvas 1. Insert the Playground block 1. Confirm Playground loads correctly
- Loading branch information