From 8371d709dd032d0a56ac7c2090ff044b478e79a4 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Thu, 7 May 2026 15:44:30 -0400 Subject: [PATCH] fix: Regression in client plugins not loading (#12291) --- app/utils/PluginManager.test.ts | 46 +++++++++++++++++++++++++++++++++ app/utils/PluginManager.ts | 9 +++++-- 2 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 app/utils/PluginManager.test.ts diff --git a/app/utils/PluginManager.test.ts b/app/utils/PluginManager.test.ts new file mode 100644 index 0000000000..611162d9b9 --- /dev/null +++ b/app/utils/PluginManager.test.ts @@ -0,0 +1,46 @@ +import { createLazyComponent } from "~/components/LazyLoad"; +import { Hook, PluginManager } from "./PluginManager"; + +const SettingsComponent = () => null; +const Icon = () => null; +const component = createLazyComponent(async () => ({ + default: SettingsComponent, +})); + +describe("PluginManager", () => { + it("returns registered hooks from observable plugin arrays", () => { + PluginManager.add([ + { + id: "test-settings-plugin-low", + name: "Low priority plugin", + type: Hook.Settings, + priority: 20, + value: { + group: "Integrations", + icon: Icon, + component, + }, + }, + { + id: "test-settings-plugin-high", + name: "High priority plugin", + type: Hook.Settings, + priority: 10, + value: { + group: "Integrations", + icon: Icon, + component, + }, + }, + ]); + + const hooks = PluginManager.getHooks(Hook.Settings).filter((plugin) => + plugin.id.startsWith("test-settings-plugin") + ); + + expect(hooks.map((plugin) => plugin.id)).toEqual([ + "test-settings-plugin-high", + "test-settings-plugin-low", + ]); + }); +}); diff --git a/app/utils/PluginManager.ts b/app/utils/PluginManager.ts index b6b7826b41..281f7577d2 100644 --- a/app/utils/PluginManager.ts +++ b/app/utils/PluginManager.ts @@ -1,5 +1,6 @@ import { isArray, sortBy } from "es-toolkit/compat"; import { action, observable } from "mobx"; +import type { IObservableArray } from "mobx"; import type Team from "~/models/Team"; import type User from "~/models/User"; import type { LazyComponent } from "~/components/LazyLoad"; @@ -116,7 +117,8 @@ export class PluginManager { * @returns A list of plugins */ public static getHooks(type: T) { - return sortBy(this.plugins.get(type) || [], "priority") as Plugin[]; + const plugins = this.plugins.get(type) ?? []; + return sortBy([...plugins], "priority") as Plugin[]; } /** @@ -152,7 +154,10 @@ export class PluginManager { return this.loaded; } - private static plugins = observable.map[]>(); + private static plugins = observable.map< + Hook, + IObservableArray> + >(); @observable private static loaded = false;