Skip to content

[JSC] Refetch a module's static dependency after its fetch fails - #77546

Open
s1anden wants to merge 1 commit into
WebKit:mainfrom
s1anden:module-dependency-fetch-retry
Open

s1anden wants to merge 1 commit into
WebKit:mainfrom
s1anden:module-dependency-fetch-retry

Conversation

@s1anden

@s1anden s1anden commented Oct 19, 2026 •

Copy link
Copy Markdown

957e30d

[JSC] Refetch a module's static dependency after its fetch fails
https://bugs.webkit.org/show_bug.cgi?id=327747

Reviewed by NOBODY (OOPS!).

319474@main stopped caching failed module fetches, but only for the module
that failed. A module that statically imports it recorded the dependency's
fetch error as its own evaluation error, and hostLoadImportedModule kept
returning the dependency's cached fetch error, so the parent stayed errored
for the life of the page.

Per https://html.spec.whatwg.org/multipage/webappapis.html#fetch-a-single-module-script
step 13.1, a failed fetch removes the module map entry and nothing else; the
parent's module script stays in the map, so the next load fetches the
dependency again.

Tag fetch failures with a new ModuleFailure::Kind::Fetch, don't record them on
any entry other than the one that failed, clear the parent's rejected load
promise so the next load reruns LoadRequestedModules, and remove a failed
entry in hostLoadImportedModule the way loadModule already does.

Concurrent imports of a module share its load promise, and with the failed
entry no longer returned synchronously, that shared rejection can now settle
an import before its own graph load does. Duplicate fetch errors where each
import consumes the load promise so every import still rejects with its own
error object (dynamic-imports-fetch-error.sub.html). The loadedModules fast path
in hostLoadImportedModule also falls through when the load promise was
cleared, so the graph is loaded again.

* JSTests/modules/dependency-fetch-failure-retry.js: Added.
* LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/module/dynamic-import/shared-dependency-repeated-import.https-expected.txt: Progression.
* LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/module/shared-dependency-repeated-import.https-expected.txt: Progression.
* Source/JavaScriptCore/runtime/JSMicrotask.cpp:
(JSC::moduleRegistryFetchSettled):
(JSC::isModuleFetchFailure):
(JSC::moduleLoadStep):
(JSC::moduleLoadTopRejected):
(JSC::moduleLoadCombinedLoadSettled):
(JSC::moduleLoadStoreError):
* Source/JavaScriptCore/runtime/JSModuleLoader.cpp:
(JSC::JSModuleLoader::hostLoadImportedModule):
* Source/JavaScriptCore/runtime/JSModuleLoader.h:
* Source/JavaScriptCore/runtime/ModuleRegistryEntry.cpp:
(JSC::ModuleRegistryEntry::clearLoadPromise):
* Source/JavaScriptCore/runtime/ModuleRegistryEntry.h:

Co-Authored-By: Claude Opus 5.5 <[email protected]>

957e30d

Misc iOS, visionOS, tvOS & watchOS macOS Linux Windows
✅ 🧪 style ✅ 🛠 ios ✅ 🛠 mac ✅ 🛠 wpe ✅ 🛠 win
✅ 🛠 ios-sim ✅ 🛠 mac-cmake-debug ✅ 🧪 wpe-wk2 ✅ 🧪 win-tests
✅ 🧪 webkitperl ✅ 🧪 ios-wk2 ✅ 🧪 api-mac ✅ 🧪 api-wpe
✅ 🧪 ios-wk2-wpt ✅ 🧪 api-mac-cmake-debug ✅ 🧪 jsc-wpe
✅ 🧪 jsc-x86-64 ✅ 🧪 api-ios ✅ 🧪 mac-wk2 ✅ 🛠 gtk3-gcc
✅ 🛠 🧪 jsc-debug-arm64 ✅ 🛠 ios-safer-cpp ✅ 🧪 mac-cmake-debug-wk2 ✅ 🛠 gtk
✅ 🛠 vision ✅ 🧪 gtk-wk2
✅ 🛠 vision-sim ✅ 🧪 mac-intel-wk2 ✅ 🧪 api-gtk
✅ 🧪 vision-wk2 ✅ 🛠 mac-safer-cpp   🛠 playstation
✅ 🛠 tv ✅ 🧪 mac-site-isolation
✅ 🛠 tv-sim
✅ 🛠 watch
✅ 🛠 watch-sim

@s1anden

s1anden commented Oct 20, 2026

Copy link
Copy Markdown
Author

Known limitation: concurrent imports of a module share its per-entry load promise, and each import settles on whichever rejects first — that shared promise or its own graph load. If a dependency fails and a second import attaches to the parent's still-pending load promise, that import can reject with the earlier failure even when its own LoadRequestedModules refetches the dependency successfully. The next import recovers normally, and the window is a few microtasks, so I left it out of this patch. A full fix would stop settling dynamic imports from the shared load promise and rely only on each import's own graph load. Happy to do that as a follow-up if you'd prefer.

@s1anden
s1anden marked this pull request as ready for review October 20, 2026 14:33
@s1anden
s1anden requested a review from a team as a code owner October 20, 2026 14:33
@s1anden

s1anden commented Oct 20, 2026

Copy link
Copy Markdown
Author

🤖 written by Claude 🤖

@kmiller68 @yoavweiss this is a follow-up to #69559 (319474@main), which stopped caching failed module fetches for the module that failed. Modules that statically import a failed dependency still cached the failure and never refetched it, so the whole importing chain stayed broken until reload. This makes it retry. Details are in the commit message and https://bugs.webkit.org/show_bug.cgi?id=327747.

Testing

  • imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/module/: all 127 tests run as expected locally, including both shared-dependency-repeated-import variants, which now pass (20/20 over 10 iterations).
  • JSTests/modules: 1199/1199 on a Debug build. The new dependency-fetch-failure-retry.js covers diamond and cyclic graphs, concurrent and staggered imports, and checks that parse, link, and evaluation errors stay cached.

EWS
tv-sim, watch, and api-ios failed during bot setup, before compiling anything (tvOS simulator runtime / watchOS 26.5 is not installed / OS/SDK mismatch). Could someone retry those?

Known limitation
Concurrent imports of a module share its per-entry load promise, and each import settles on whichever rejects first: that shared promise or its own graph load. If a dependency fails and a second import attaches to the parent's still-pending load promise, that import can reject with the earlier failure even when its own LoadRequestedModules refetches the dependency successfully. The next import recovers, and the window is a few microtasks, so I left it out of this patch. A full fix would stop settling dynamic imports from the shared load promise and rely only on each import's own graph load. I'm happy to do that as a follow-up if you'd prefer.

https://bugs.webkit.org/show_bug.cgi?id=327747

Reviewed by NOBODY (OOPS!).

319474@main stopped caching failed module fetches, but only for the module
that failed. A module that statically imports it recorded the dependency's
fetch error as its own evaluation error, and hostLoadImportedModule kept
returning the dependency's cached fetch error, so the parent stayed errored
for the life of the page.

Per https://html.spec.whatwg.org/multipage/webappapis.html#fetch-a-single-module-script
step 13.1, a failed fetch removes the module map entry and nothing else; the
parent's module script stays in the map, so the next load fetches the
dependency again.

Tag fetch failures with a new ModuleFailure::Kind::Fetch, don't record them on
any entry other than the one that failed, clear the parent's rejected load
promise so the next load reruns LoadRequestedModules, and remove a failed
entry in hostLoadImportedModule the way loadModule already does.

Concurrent imports of a module share its load promise, and with the failed
entry no longer returned synchronously, that shared rejection can now settle
an import before its own graph load does. Duplicate fetch errors where each
import consumes the load promise so every import still rejects with its own
error object (dynamic-imports-fetch-error.sub.html). The loadedModules fast path
in hostLoadImportedModule also falls through when the load promise was
cleared, so the graph is loaded again.

* JSTests/modules/dependency-fetch-failure-retry.js: Added.
* LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/module/dynamic-import/shared-dependency-repeated-import.https-expected.txt: Progression.
* LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/module/shared-dependency-repeated-import.https-expected.txt: Progression.
* Source/JavaScriptCore/runtime/JSMicrotask.cpp:
(JSC::moduleRegistryFetchSettled):
(JSC::isModuleFetchFailure):
(JSC::moduleLoadStep):
(JSC::moduleLoadTopRejected):
(JSC::moduleLoadCombinedLoadSettled):
(JSC::moduleLoadStoreError):
* Source/JavaScriptCore/runtime/JSModuleLoader.cpp:
(JSC::JSModuleLoader::hostLoadImportedModule):
* Source/JavaScriptCore/runtime/JSModuleLoader.h:
* Source/JavaScriptCore/runtime/ModuleRegistryEntry.cpp:
(JSC::ModuleRegistryEntry::clearLoadPromise):
* Source/JavaScriptCore/runtime/ModuleRegistryEntry.h:

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@s1anden
s1anden force-pushed the module-dependency-fetch-retry branch from 98b9c44 to 957e30d Compare November 4, 2026 15:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants