A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.
Python artificial-intelligencedagdata-sciencedata-visualizationdataflowdeveloper-toolsmachine-learningnotebookspipelinepythonreactivesqlweb-app
Retry invalid anywidget modules (#10259)
Trevor Manz0f8bee7582f9
diff --git a/frontend/src/plugins/impl/anywidget/__tests__/registry.test.ts b/frontend/src/plugins/impl/anywidget/__tests__/registry.test.tsindex cfe8363507..8007998d2f 100644--- a/frontend/src/plugins/impl/anywidget/__tests__/registry.test.ts+++ b/frontend/src/plugins/impl/anywidget/__tests__/registry.test.ts@@ -210,7 +210,7 @@ describe("WidgetRegistry.getWidget", () => {});afterEach(() => {- getModuleSpy.mockRestore();+ vi.restoreAllMocks();});it("binds an undisplayed widget from its ESM spec", async () => {@@ -309,6 +309,7 @@ describe("WidgetRegistry.getWidget", () => {});it("rejects with the AFM error when the module has no usable exports", async () => {+ const invalidateSpy = vi.spyOn(WIDGET_DEF_REGISTRY, "invalidate");getModuleSpy.mockResolvedValue({ notAWidget: true });const model = new Model<ModelState>({ count: 0 }, createMockComm());@@ -318,6 +319,7 @@ describe("WidgetRegistry.getWidget", () => {await expect(registry.getWidget(testId)).rejects.toThrow(/missing a default export/,);+ expect(invalidateSpy).toHaveBeenCalledWith(SPEC.hash);});it("rejects when the model never arrives", async () => {diff --git a/frontend/src/plugins/impl/anywidget/__tests__/widget-binding.test.ts b/frontend/src/plugins/impl/anywidget/__tests__/widget-binding.test.tsindex 7b4f59ff09..a5119c450c 100644--- a/frontend/src/plugins/impl/anywidget/__tests__/widget-binding.test.ts+++ b/frontend/src/plugins/impl/anywidget/__tests__/widget-binding.test.ts@@ -95,6 +95,16 @@ describe("WidgetDefRegistry", () => {promise1.catch(() => undefined);});+ it("should retry a new URL after invalidating the same hash", () => {+ const promise1 = getModule(registry, "http://localhost/a.js", "same-hash");+ registry.invalidate("same-hash");+ const promise2 = getModule(registry, "http://localhost/b.js", "same-hash");++ expect(promise1).not.toBe(promise2);+ promise1.catch(() => undefined);+ promise2.catch(() => undefined);+ });+it("should create different promises for different hashes", () => {const promise1 = getModule(registry, "http://localhost/a.js", "hash-a");const promise2 = getModule(registry, "http://localhost/b.js", "hash-b");diff --git a/frontend/src/plugins/impl/anywidget/runtime.ts b/frontend/src/plugins/impl/anywidget/runtime.tsindex 2035af7b18..9e5121dcb9 100644--- a/frontend/src/plugins/impl/anywidget/runtime.ts+++ b/frontend/src/plugins/impl/anywidget/runtime.ts@@ -211,6 +211,7 @@ export class WidgetRuntime {});const widget = resolveAnyWidget(mod, spec.url);if (!widget) {+ WIDGET_DEF_REGISTRY.invalidate(spec.hash);throw getInvalidAnyWidgetModuleError(mod, spec.url);}return WidgetBinding.create({diff --git a/frontend/src/plugins/impl/anywidget/widget-binding.ts b/frontend/src/plugins/impl/anywidget/widget-binding.tsindex 981739501d..96c11f3356 100644--- a/frontend/src/plugins/impl/anywidget/widget-binding.ts+++ b/frontend/src/plugins/impl/anywidget/widget-binding.ts@@ -80,6 +80,10 @@ class WidgetDefRegistry {return promise;}+ invalidate(jsHash: string): void {+ this.#cache.delete(jsHash);+ }+async #doImport(jsUrl: string,opts: { kernelAuthored?: boolean } = {},