Skip to content

Commit 03ae8ec

Browse files
authored
[Website] Controlled iframe for the latest Guteneberg version (#2857)
## Motivation for the change, related issues [Missing CSS and images because the Gutenberg iframe isn't controlled by the service worker](#646 (comment) back in the latest Gutenberg release. This PR adjusts the script rewriting expression to resolve it. ## Testing Instructions (or ideally a Blueprint) Visit http://127.0.0.1:5400/website-server/?gutenberg-pr=72916&url=%2Fwp-admin%2Fpost-new.php Below is what you should see.. Before this PR: <img width="3608" height="1834" alt="CleanShot 2025-11-03 at 17 03 20@2x" src="https://github.com/user-attachments/assets/f2020598-54f4-4f40-9d1f-1ce9078bf97d" /> After this PR: <img width="3620" height="1840" alt="CleanShot 2025-11-03 at 17 00 36@2x" src="https://github.com/user-attachments/assets/f81d17be-0caf-49ec-8b5c-b546fe230aec" />
1 parent cf36ff3 commit 03ae8ec

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

packages/playground/remote/service-worker.ts

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -393,13 +393,11 @@ async function handleScopedRequest(event: FetchEvent, scope: string) {
393393
// @see controlledIframe below for more details.
394394
if (
395395
// WordPress Core version of block-editor.js
396-
unscopedUrl.pathname.endsWith('/wp-includes/js/dist/block-editor.js') ||
397-
unscopedUrl.pathname.endsWith(
398-
'/wp-includes/js/dist/block-editor.min.js'
399-
) ||
396+
unscopedUrl.pathname.endsWith('/block-editor.js') ||
397+
unscopedUrl.pathname.endsWith('/block-editor.min.js') ||
400398
// Gutenberg version of block-editor.js
401-
unscopedUrl.pathname.endsWith('/build/block-editor/index.js') ||
402-
unscopedUrl.pathname.endsWith('/build/block-editor/index.min.js')
399+
unscopedUrl.pathname.endsWith('/block-editor/index.js') ||
400+
unscopedUrl.pathname.endsWith('/block-editor/index.min.js')
403401
) {
404402
const script = await workerResponse.text();
405403
const newScript = `${controlledIframe} ${script.replace(
@@ -470,15 +468,15 @@ window.__playground_ControlledIframe = window.wp.element.forwardRef(function (pr
470468
*/
471469
const __playground_readBlobAsText = function (url) {
472470
try {
473-
let xhr = new XMLHttpRequest();
474-
xhr.open('GET', url, false);
475-
xhr.overrideMimeType('text/plain;charset=utf-8');
476-
xhr.send();
477-
return xhr.responseText;
471+
let xhr = new XMLHttpRequest();
472+
xhr.open('GET', url, false);
473+
xhr.overrideMimeType('text/plain;charset=utf-8');
474+
xhr.send();
475+
return xhr.responseText;
478476
} catch(e) {
479-
return '';
477+
return '';
480478
} finally {
481-
URL.revokeObjectURL(url);
479+
URL.revokeObjectURL(url);
482480
}
483481
};
484482
if (props.srcDoc) {

0 commit comments

Comments
 (0)