Import map sometimes prevents module script execution
Categories
(Core :: JavaScript Engine, defect, P2)
Tracking
()
Tracking | Status | |
---|---|---|
firefox-esr115 | --- | unaffected |
firefox122 | --- | fixed |
firefox123 | --- | fixed |
firefox124 | --- | fixed |
People
(Reporter: mozilla-bugzilla, Assigned: allstars.chh)
References
(Regression)
Details
(Keywords: regression)
Attachments
(2 files)
1.34 KB,
application/zip
|
Details | |
48 bytes,
text/x-phabricator-request
|
pascalc
:
approval-mozilla-beta+
dmeehan
:
approval-mozilla-release+
|
Details | Review |
User Agent: Mozilla/5.0 (X11; Linux x86_64; rv:121.0) Gecko/20100101 Firefox/121.0
Steps to reproduce:
Inserting an import map into the DOM from a classic script sometimes leads to subsequent module scripts failing to execute:
<!DOCTYPE html>
<html lang="en">
<head>
<script>
(function () {
const script = document.createElement('script');
script.type = 'importmap';
script.textContent = '{}';
document.head.appendChild(script);
}());
</script>
</head>
<body>
<script src="test.js" type="module" onerror="console.error('Failed to load ES Module script:', arguments[0])"></script>
</body>
</html>
Mozregression points to https://phabricator.services.mozilla.com/D194767 (and thus https://bugzilla.mozilla.org/show_bug.cgi?id=1865410) and from my testing this bug is not present in Firefox 120.
Actual results:
test.js
only executes successfully sometimes (upon failure the Console shows the following warning: "Loading failed for the module with source").
The most consistent way to reproduce is to disable the cache in the Network panel. It also seems to reproduce more consistently in Firefox Nightly.
Note that the content of the import map is irrelevant for the reproduction (as long as it's valid JSON).
I have not been able to find any other relevant logs.
Expected results:
test.js
should always execute.
Updated•2 years ago
|
Comment 1•2 years ago
|
||
:jonco, since you are the author of the regressor, bug 1865410, could you take a look? Also, could you set the severity field?
For more information, please visit BugBot documentation.
Assignee | ||
Updated•2 years ago
|
Updated•2 years ago
|
Updated•2 years ago
|
Assignee | ||
Comment 2•2 years ago
|
||
Fist, the module script bug_1873417.mjs is preloaded, then an import map is
inserted. Then ScriptLoader will cancel the preloaded request 1,
and create a new ScriptLoadRequest.
The new ScriptLoadRequest will be added into WaitingRequests in
mFetchingModules 2.
Finally, ScriptLoader finishes fetching the original preloaded ScriptLoadRequest,
but since it is cancelled, NS_BINDING_ABORTED will be passed to
OnFetchComplete 3 4 5, and then call ResumeWaitingRequests for the
new created ScriptLoadRequest 6, which in turn calls LoadFailed() 7.
To fix this, since the preloaded request isn't fetched yet, so I add a check
for the mModuleScript, if it doesn't exist yet, then we should reuse the
preloaded request.
Comment 4•2 years ago
|
||
bugherder |
Reporter | ||
Comment 5•2 years ago
|
||
Is there any chance this can be uplifted to Firefox 122? Web pages that rely on import maps inserted in this way currently fail to load at all in Firefox (or require clearing the cache or a few page reloads).
Assignee | ||
Comment 6•2 years ago
|
||
Please try nightly for a few days to see if it fixes your problem. If it doesn't cause any regression then I'll uplift it to beta or release (Firefox 122.0.1)
Comment 7•2 years ago
|
||
Set release status flags based on info from the regressing bug 1865410
Comment 8•2 years ago
|
||
The patch landed in nightly and beta is affected.
:allstars.chh, is this bug important enough to require an uplift?
- If yes, please nominate the patch for beta approval.
- If no, please set
status-firefox123
towontfix
.
For more information, please visit BugBot documentation.
Assignee | ||
Comment 9•2 years ago
|
||
Comment on attachment 9375423 [details]
Bug 1873417 : Cancel the preloaded request only if the it has been fetched.
Beta/Release Uplift Approval Request
- User impact if declined: Scripts might not be executed if it will inject an import map script.
- Is this code covered by automated tests?: Yes
- Has the fix been verified in Nightly?: Yes
- Needs manual test from QE?: No
- If yes, steps to reproduce:
- List of other uplifts needed: None
- Risk to taking this patch: Low
- Why is the change risky/not risky? (and alternatives if risky): This patch prevents a not-fetched-yet module script from being canceled after an import map is inserted.
- String changes made/needed: no
- Is Android affected?: Yes
Reporter | ||
Comment 10•2 years ago
|
||
I've tested with Nightly (124.0a1 (2024-01-24)), and while I can't reproduce anymore the test case attached, the application I've extracted it from still occasionally fails to load (with the same root cause - removing the insert of the import map ensures that the scripts are always executed).
The difference is that is happens less often and that the warning "Loading failed for the module with source" is no longer printed in the console. I'll try to see if I can extract another small test case, but it does seem like there are other conditions that result in scripts failing to execute.
Comment 11•2 years ago
|
||
Yoshi, given comment #10, should we pursue with the uplift request? Thanks
Assignee | ||
Comment 12•2 years ago
|
||
Thanks for asking.
I cannot reproduce the problem in comment 10 so far, maybe because I am using a debug build?
I'll try different build configurations to see if I can reproduce it, meanwhile, I'll cancel the uplift request by now.
Assignee | ||
Updated•2 years ago
|
Comment 13•2 years ago
|
||
:yoshi, we have a scheduled dot release for Fx122 next week. It builds on 2024-02-05 and releases on 2024-02-06.
I see there is some doubt about the fix, though is this something we should aim to get a fix in for the Fx122 dot release?
Or, if not then at least in time for Fx123.
Assignee | ||
Comment 14•2 years ago
|
||
Thanks for asking.
I am fixing Bug 1877122, hopefully, it will be fixed within this week so this bug and bug 1877122 can be uplifted to Fx122 dot release.
Assignee | ||
Comment 15•2 years ago
|
||
Comment on attachment 9375423 [details]
Bug 1873417 : Cancel the preloaded request only if the it has been fetched.
Beta/Release Uplift Approval Request
- User impact if declined: Scripts might not be executed if it will inject an import map script.
- Is this code covered by automated tests?: Yes
- Has the fix been verified in Nightly?: Yes
- Needs manual test from QE?: No
- If yes, steps to reproduce:
- List of other uplifts needed: Bug 1877122
- Risk to taking this patch: Low
- Why is the change risky/not risky? (and alternatives if risky): This patch prevents a module script which is still being fetched or being compiled from being canceled after an import map is inserted.
- String changes made/needed: no
- Is Android affected?: Yes
Assignee | ||
Comment 16•2 years ago
|
||
Comment on attachment 9375423 [details]
Bug 1873417 : Cancel the preloaded request only if the it has been fetched.
Beta/Release Uplift Approval Request
- User impact if declined: Scripts might not be executed if it will inject an import map script.
- Is this code covered by automated tests?: Yes
- Has the fix been verified in Nightly?: Yes
- Needs manual test from QE?: No
- If yes, steps to reproduce:
- List of other uplifts needed: Bug 1877122
- Risk to taking this patch: Low
- Why is the change risky/not risky? (and alternatives if risky): This patch prevents a module script which is still being fetched or being compiled from being canceled after an import map is inserted.
- String changes made/needed: no
- Is Android affected?: Yes
Comment 17•2 years ago
|
||
Comment on attachment 9375423 [details]
Bug 1873417 : Cancel the preloaded request only if the it has been fetched.
Approved for 123 beta 6, thanks.
Comment 18•2 years ago
|
||
uplift |
Comment 19•2 years ago
|
||
bugherder uplift |
Comment 20•2 years ago
|
||
Comment on attachment 9375423 [details]
Bug 1873417 : Cancel the preloaded request only if the it has been fetched.
Approved for 122.0.1
Comment 21•2 years ago
|
||
uplift |
Updated•2 years ago
|
Description
•