Skip to content

Commit 27551ad

Browse files
committed
WordPress: Fix the srcDoc patch in WordPress block-editor.js (#408)
Gutenberg loads the site editor using <iframe srcDoc="<!doctype html>" to force the standards mode and not the quirks mode: WordPress/gutenberg#38855 This commit patches the site editor to achieve the same result via <iframe src="/doctype.html"> and a doctype.html file containing just `<!doctype html>`. This allows the iframe to inherit the service worker and correctly load all the css, js, fonts, images, and other assets. More details: WordPress/wordpress-playground#91 (comment)
1 parent aa32df5 commit 27551ad

File tree

5 files changed

+7
-10
lines changed

5 files changed

+7
-10
lines changed

packages/playground/compile-wordpress/Dockerfile

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,8 @@ RUN git clone https://github.com/WordPress/sqlite-database-integration.git \
3030
--single-branch \
3131
--depth 1 && \
3232
rm -rf wordpress/wp-content/plugins/sqlite-database-integration/.git && \
33-
cat wordpress/wp-content/plugins/sqlite-database-integration/db.copy \
34-
| sed "s#{SQLITE_IMPLEMENTATION_FOLDER_PATH}#' . __DIR__ . '/plugins/sqlite-database-integration#g" \
35-
| sed 's#{SQLITE_PLUGIN}#sqlite-database-integration#g' \
36-
> wordpress/wp-content/db.php && \
3733
# Required by the SQLite integration plugin:
34+
cp wordpress/wp-content/plugins/sqlite-database-integration/db.copy wordpress/wp-content/db.php && \
3835
cp wordpress/wp-config-sample.php wordpress/wp-config.php
3936

4037
# Separate WordPress static files
@@ -74,8 +71,8 @@ RUN cp -r wordpress wordpress-static && \
7471
# See https://github.com/WordPress/wordpress-playground/issues/42 for more details
7572

7673
RUN echo '<!doctype html>' > wordpress-static/wp-includes/empty.html && \
77-
sed -E 's#srcDoc:"[^"]+"#src:"/wp-includes/empty.html"#g' -i wordpress-static/wp-includes/js/dist/block-editor.min.js && \
78-
sed -E 's#srcDoc:"[^"]+"#src:"/wp-includes/empty.html"#g' -i wordpress-static/wp-includes/js/dist/block-editor.js
74+
sed -E 's#srcDoc:\s*("[^"]+"|[^,\n}]+)#src:"/wp-includes/empty.html"#g' -i wordpress-static/wp-includes/js/dist/block-editor.min.js && \
75+
sed -E 's#srcDoc:\s*("[^"]+"|[^,\n}]+)#src:"/wp-includes/empty.html"#g' -i wordpress-static/wp-includes/js/dist/block-editor.js
7976

8077
# Move the static files to the final output directory
8178
RUN mkdir /root/output/$OUT_FILENAME

packages/playground/remote/public/wp-6.0/wp-includes/js/dist/block-editor.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20944,7 +20944,7 @@ function Iframe(_ref3, ref) {
2094420944
ref: (0,external_wp_compose_namespaceObject.useMergeRefs)([ref, setRef]),
2094520945
tabIndex: tabIndex // Correct doctype is required to enable rendering in standards mode
2094620946
,
20947-
srcDoc: "<!doctype html>",
20947+
src:"/wp-includes/empty.html",
2094820948
title: (0,external_wp_i18n_namespaceObject.__)('Editor canvas')
2094920949
}), iframeDocument && (0,external_wp_element_namespaceObject.createPortal)((0,external_wp_element_namespaceObject.createElement)(external_wp_element_namespaceObject.Fragment, null, (0,external_wp_element_namespaceObject.createElement)("head", {
2095020950
ref: headRef

packages/playground/remote/public/wp-6.1/wp-includes/js/dist/block-editor.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22997,7 +22997,7 @@ function Iframe(_ref3, ref) {
2299722997
ref: (0,external_wp_compose_namespaceObject.useMergeRefs)([ref, setRef]),
2299822998
tabIndex: tabIndex // Correct doctype is required to enable rendering in standards mode
2299922999
,
23000-
srcDoc: "<!doctype html>",
23000+
src:"/wp-includes/empty.html",
2300123001
title: (0,external_wp_i18n_namespaceObject.__)('Editor canvas')
2300223002
}), iframeDocument && (0,external_wp_element_namespaceObject.createPortal)((0,external_wp_element_namespaceObject.createElement)(external_wp_element_namespaceObject.Fragment, null, (0,external_wp_element_namespaceObject.createElement)("head", {
2300323003
ref: headRef

packages/playground/remote/public/wp-6.2/wp-includes/js/dist/block-editor.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20332,7 +20332,7 @@ function Iframe(_ref2) {
2033220332
// mode. Also preload the styles to avoid a flash of unstyled
2033320333
// content.
2033420334
,
20335-
srcDoc: srcDoc,
20335+
src:"/wp-includes/empty.html",
2033620336
title: (0,external_wp_i18n_namespaceObject.__)('Editor canvas')
2033720337
}), iframeDocument && (0,external_wp_element_namespaceObject.createPortal)((0,external_wp_element_namespaceObject.createElement)(external_wp_element_namespaceObject.Fragment, null, (0,external_wp_element_namespaceObject.createElement)("head", {
2033820338
ref: headRef

packages/playground/remote/public/wp-6.2/wp-includes/js/dist/block-editor.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)