-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Modules: Load the import map polyfill when needed #57256
Conversation
This pull request has changed or added PHP files. Please confirm whether these changes need to be synced to WordPress Core, and therefore featured in the next release of WordPress. If so, it is recommended to create a new Trac ticket and submit a pull request to the WordPress Core Github repository soon after this pull request is merged. If you're unsure, you can always ask for help in the #core-editor channel in WordPress Slack. Thank you! ❤️ View changed files❔ lib/experimental/modules/class-gutenberg-modules.php |
I only make it a normal pull request to be able to use Gutenberg PR Previewer powered by Playground. I'm not sure if that will help though. |
Fixes an issue reported by @gziolo: > WordPress/gutenberg#57256 - I can’t preview this PR using Playground https://playground.wordpress.net/gutenberg.html. What do I miss? All CI checks are green. The culprit was that GitHub hosts that artifact on another domain: `productionresultssa0.blob.core.windows.net`. The current `file_get_contents` call follows the redirection URL and resends the same HTTP headers. That used to be fine, but now the windows.net host rejects those headers. This PR ensures we don't implicitly follow the 302 redirect, but parse the target URL and send an explicit request with a fresh set of HTTP headers. As a bonus, this makes the download much faster as we now use the `streamHttpResponse` function which immediately passes the response bytes back to the browser instead of buffering the entire response first. This PR also switches from HEAD-request-based PR validation to the same Query params–based one as the wordpress.html previewer uses. ## Testing instructions Try to preview the above PR in the Gutenberg PR previewer on https://playground.wordpress.net/gutenberg.html and confirm that it works now (this fix is already deployed).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @gziolo, this looks great! Two small concerns below.
It works as expected with browsers that don't support import maps, like Firefox 107: Screen.Recording.2023-12-20.at.22.56.48.mov@felixarntz, I'll look tomorrow into how to optimize it based on your feedback. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested it in iOS, iPadOS and macOS versions with Safari 13, 14 and 15, and it works as expected.
I tested again the document.head.appendChild(importMapPolyfill)
solution and that didn't work, so it seems like document.write
is the key to making this work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @gziolo, LGTM!
051bae9
to
8f5e260
Compare
I think this PR affected |
That's weird, because even though adding scripts with We could try adding Previous related conversations: |
@luisherranz, this could be due to the WP hook changing from |
Yeah, but theoretically, in modern browsers, all it adds is a <script>
if ( ! ( HTMLScriptElement.supports && HTMLScriptElement.supports( "importmap" ) ) ) {
// Nothing else to do, because the if is always false in all the modern browsers.
}
</script> So that shouldn't affect the LCP even if it's in the |
I'm not sure I'm looking in the correct place, but if I am, it seems like the performance tests are using the latest chromium version: gutenberg/bin/plugin/commands/performance.js Line 213 in 52ff927
Theoretically, that version should not load the polyfill. |
That's correct; perf tests use the latest browser versions provided for Playwright - https://github.com/microsoft/playwright/releases/tag/v1.39.0. |
Just to be sure, we are looking at these numbers, right? https://github.com/WordPress/gutenberg/actions/runs/7409967406/job/20161251805?pr=57256
Maybe we should run them a few more times to see if the numbers stay still? Any other ideas about what might be going on here? cc: @youknowriad, @gziolo |
That’s surprising results. It’s also unclear to me why it would impact negatively only the classic theme. |
We could try moving the polyfill to the footer as it seems to work in my basic testing, but as Luis pointed out it's a simple JS check for over 90% of users. |
Now that we've got a few more PRs after this one, it's clear that it affected the LCP (https://www.codevitals.run/project/gutenberg): As it still doesn't make sense that a single script with an |
What?
Explores whether there is a simple way to address the issue raised by @felixarntz in #55942 (comment):
Why?
It should be easier to handle in WordPress core, but as a quick experiment I replicated how we handle conditional polyfills in the past:
https://github.com/WordPress/wordpress-develop/blob/1bca32e30ede3f8731290b052b35c431d091e2f7/src/wp-includes/script-loader.php#L204-L214
How?
I used the conditional check for feature detection included on MDN:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules#feature_detection
Testing Instructions
Testing Instructions for Keyboard
Screenshots or screencast
It works correctly with browsers that support import maps. I tested with Safari and Chrome:
import-map-polyfill.mov