Retry invalid anywidget modules#10259
Merged
Merged
Conversation
Closes #10214 Successful imports were cached before their exports were validated, so reruns could reuse an unusable module. These changes evict modules that fail AFM validation so a fresh URL can be loaded.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes anywidget ESM cache invalidation when a module import succeeds but fails AFM export validation, ensuring reruns can load a fresh URL instead of reusing a cached unusable module (closes #10214).
Changes:
- Add
WidgetDefRegistry.invalidate(jsHash)to explicitly evict a cached module promise by hash. - Invalidate the cached module when AFM validation fails (
resolveAnyWidgetreturns null) before throwing the AFM error. - Add/extend unit tests to cover invalidation behavior and ensure
invalidateis invoked on AFM validation failures.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| frontend/src/plugins/impl/anywidget/widget-binding.ts | Adds explicit cache eviction API (invalidate) for module promises keyed by jsHash. |
| frontend/src/plugins/impl/anywidget/runtime.ts | Evicts the cached module when AFM validation fails so subsequent attempts can re-import from a new URL. |
| frontend/src/plugins/impl/anywidget/tests/widget-binding.test.ts | Adds a test asserting invalidation enables a new promise for the same hash with a new URL. |
| frontend/src/plugins/impl/anywidget/tests/registry.test.ts | Adds an assertion that AFM validation failures trigger WIDGET_DEF_REGISTRY.invalidate(spec.hash). |
Comment on lines
+312
to
+323
| @@ -318,6 +319,8 @@ describe("WidgetRegistry.getWidget", () => { | |||
| await expect(registry.getWidget(testId)).rejects.toThrow( | |||
| /missing a default export/, | |||
| ); | |||
| expect(invalidateSpy).toHaveBeenCalledWith(SPEC.hash); | |||
| invalidateSpy.mockRestore(); | |||
Contributor
There was a problem hiding this comment.
All reported issues were addressed across 4 files
Architecture diagram
sequenceDiagram
participant UI as Widget UI
participant RT as Widget Runtime
participant Mod as Module Loader
participant Registry as WidgetDefRegistry
participant Import as Import Cache (#doImport)
UI->>RT: getWidget(spec)
RT->>Mod: resolveAnyWidget(mod, url)
Mod->>Registry: getModule(url, hash)
alt Cache hit (hash exists)
Registry->>Import: Return cached promise
Import-->>Registry: Module exports
else Cache miss
Registry->>Import: #doImport(url)
Import-->>Registry: Module exports
Registry->>Registry: Cache promise for hash
end
Registry-->>Mod: Module exports
Mod-->>RT: Widget export or null
alt Widget export is valid
RT->>RT: Create WidgetBinding
RT-->>UI: Widget instance
else No valid widget export
RT->>Registry: invalidate(hash)
RT->>RT: throw getInvalidAnyWidgetModuleError
Registry->>Registry: Remove hash from #cache
UI->>UI: Catch error, trigger retry with new URL
UI->>Registry: getModule(newUrl, sameHash)
Registry->>Import: #doImport(newUrl)
Import-->>Registry: Fresh module exports
Registry-->>UI: Promise for new module
end
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
mscolnick
approved these changes
Jul 21, 2026
Contributor
|
🚀 Development release published. You may be able to view the changes at https://marimo.app?v=0.23.15-dev48 |
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.
Closes #10214
Successful imports were cached before their exports were validated, so reruns could reuse an unusable module. These changes evict modules that fail AFM validation so a fresh URL can be loaded.