fix(updates): sync update center state after manual component changes

This commit is contained in:
zipg authored and GitHub committed 2026-09-20 18:43:02 +08:00
1 parent 1ef865008a
commit 4d150fc909
13 files changed
+143 -11

No files matched your search

@@ -1,7 +1,7 @@
// @vitest-environment happy-dom
import { describe, expect, it, vi } from "vitest";
import { COMPONENT_PLUGINS_UPDATED_EVENT, notifyComponentPluginsUpdated } from "@/lib/updates/componentUpdateEvents";
import { COMPONENT_PLUGINS_UPDATED_EVENT, COMPONENT_UPDATES_CHANGED_EVENT, notifyComponentPluginsUpdated, notifyComponentUpdatesChanged } from "@/lib/updates/componentUpdateEvents";
describe("component update events", () => {
it("notifies plugin surfaces after component-level plugin updates", () => {
@@ -13,4 +13,24 @@ describe("component update events", () => {
expect(listener).toHaveBeenCalledOnce();
window.removeEventListener(COMPONENT_PLUGINS_UPDATED_EVENT, listener);
});
it("notifies the app when a management surface changes component state", () => {
const listener = vi.fn();
window.addEventListener(COMPONENT_UPDATES_CHANGED_EVENT, listener);
notifyComponentUpdatesChanged();
expect(listener).toHaveBeenCalledOnce();
window.removeEventListener(COMPONENT_UPDATES_CHANGED_EVENT, listener);
});
it("is inert when the store runs outside a browser environment", () => {
vi.stubGlobal("window", undefined);
try {
expect(() => notifyComponentPluginsUpdated()).not.toThrow();
expect(() => notifyComponentUpdatesChanged()).not.toThrow();
} finally {
vi.unstubAllGlobals();
}
});
});
@@ -1,5 +1,12 @@
export const COMPONENT_PLUGINS_UPDATED_EVENT = "dbx:component-plugins-updated";
export const COMPONENT_UPDATES_CHANGED_EVENT = "dbx:component-updates-changed";
export function notifyComponentPluginsUpdated(): void {
if (typeof window === "undefined") return;
window.dispatchEvent(new Event(COMPONENT_PLUGINS_UPDATED_EVENT));
}
export function notifyComponentUpdatesChanged(): void {
if (typeof window === "undefined") return;
window.dispatchEvent(new Event(COMPONENT_UPDATES_CHANGED_EVENT));
}