Repository navigation
fix(theme): load theme scripts deferred instead of as modules - #514
Merged
Merged
Conversation
Firefox ignores WordPress's import map once a module script has started loading before it. A classic theme gets the import map in the footer, and the theme marked its sage/ and gds- scripts type="module", so the ones printed in the head started module loading first and core modules (fit-text) failed to import @wordpress/interactivity. The builds are plain scripts, so they load deferred; async ones stay async. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Set the defer strategy on sage/ and gds- handles instead of rewriting their tags, so core prints the attribute, keeps dependencies in order and handles inline scripts. Handles in assets.async_scripts stay with the async loader. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
oxyc
added a commit
that referenced
this pull request
Dec 3, 2026
sage/app.js is in assets.deferred_scripts, so AsyncLoaderServiceProvider adds defer to its tag; the core defer strategy from #514 added a second one. Chrome drops the nonce of a script with a duplicated attribute, so a nonce-based CSP blocks app.js. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Firefox ignores WordPress's import map when a module script has started loading before it. A classic theme gets the import map in the footer, and
SageServiceProvidermarked everysage/…andgds-…scripttype="module", so the menu scripts printed in the head started module loading first. Core's fit-text module then failed in Firefox withThe specifier “@wordpress/interactivity” was a bare specifier.The theme's builds are plain bundled scripts (no ES module output in the webpack config), so they now load deferred through core's loading strategy: late on
wp_enqueue_scripts, every registeredsage/…/gds-…handle without a strategy getsstrategy: defer. Core prints the attribute, keeps dependencies in order (it falls back to blocking when a blocking script depends on one) and handles inline scripts, so there's no tag rewriting. Handles inassets.async_scriptsstay withAsyncLoaderServiceProvider. A real ES module belongs inwp_enqueue_script_module(), which core prints after the import map.Tests: theme and block handles get
deferand print withouttype="module", other plugins' scripts are left alone, async handles aren't deferred.🤖 Generated with Claude Code