Skip to content

The agent that grows with you

fix(plugins): keep loading gate when cached manifests include a /chat override

kshitijc0c45ab68ae4
diff --git a/web/src/plugins/usePlugins.test.ts b/web/src/plugins/usePlugins.test.ts
index 69cc24098de..05d0cd40dbf 100644
--- a/web/src/plugins/usePlugins.test.ts
+++ b/web/src/plugins/usePlugins.test.ts
@@ -2,6 +2,7 @@ import { describe, it, expect, beforeEach, afterEach, vi } from "vitest";
import {
getCachedManifests,
cacheManifests,
+ canSeedLoadedFromCache,
MANIFEST_CACHE_KEY,
} from "./usePlugins";
import type { PluginManifest } from "./types";
@@ -100,3 +101,44 @@ describe("plugin manifest cache helpers", () => {
expect(() => cacheManifests([exampleManifest])).not.toThrow();
});
});
+
+describe("canSeedLoadedFromCache (loading seed gate)", () => {
+ it("returns false when there is no cache (first visit keeps loading=true)", () => {
+ expect(canSeedLoadedFromCache(null)).toBe(false);
+ });
+
+ it("returns true for an empty cached list", () => {
+ expect(canSeedLoadedFromCache([])).toBe(true);
+ });
+
+ it("returns true when no cached manifest overrides /chat", () => {
+ const list: PluginManifest[] = [
+ exampleManifest,
+ {
+ ...exampleManifest,
+ name: "other",
+ tab: { path: "/other", override: "/skills" },
+ },
+ ];
+ expect(canSeedLoadedFromCache(list)).toBe(true);
+ });
+
+ it("returns false when a cached manifest overrides /chat — loading must stay true so App.tsx's pluginsLoading gate keeps the persistent chat host unmounted", () => {
+ const list: PluginManifest[] = [
+ exampleManifest,
+ {
+ ...exampleManifest,
+ name: "chat-replacer",
+ tab: { path: "/chat-alt", override: "/chat" },
+ },
+ ];
+ expect(canSeedLoadedFromCache(list)).toBe(false);
+ });
+
+ it("tolerates malformed cached entries missing a tab object", () => {
+ const malformed = [
+ { ...exampleManifest, tab: undefined },
+ ] as unknown as PluginManifest[];
+ expect(canSeedLoadedFromCache(malformed)).toBe(true);
+ });
+});
diff --git a/web/src/plugins/usePlugins.ts b/web/src/plugins/usePlugins.ts
index 336d4b523fd..f03a069839b 100644
--- a/web/src/plugins/usePlugins.ts
+++ b/web/src/plugins/usePlugins.ts
@@ -38,6 +38,25 @@ export function cacheManifests(manifests: PluginManifest[]): void {
}
}
+/**
+ * Whether it is safe to skip the initial plugin-loading gate for a set of
+ * cached manifests.
+ *
+ * App.tsx waits on `pluginsLoading` before mounting the persistent ChatPage
+ * host: if a plugin overrides /chat (`tab.override === "/chat"`), mounting
+ * the built-in chat first would spawn a PTY and then yank it out from under
+ * the user when the plugin resolves. That gate is load-bearing — so we may
+ * only seed `loading = false` from the cache when no cached manifest
+ * declares a /chat override. Manifests are still seeded either way; only
+ * the loading flag stays conservative.
+ */
+export function canSeedLoadedFromCache(
+ cached: PluginManifest[] | null,
+): boolean {
+ if (cached === null) return false;
+ return !cached.some((m) => m.tab?.override === "/chat");
+}
+
export function usePlugins() {
// Lazy initialisers run once at mount — safe to read sessionStorage here.
// This avoids the "cannot access ref during render" lint error that would
@@ -51,8 +70,12 @@ export function usePlugins() {
// registered synchronously on the first render after a refresh.
// The catch-all in App.tsx is only a safety net for the very first visit
// (no cache yet). On subsequent visits this flag starts false immediately.
+ //
+ // Exception: if any cached manifest overrides /chat we must keep
+ // loading=true — App.tsx's pluginsLoading gate around the persistent
+ // ChatPage host is load-bearing (see canSeedLoadedFromCache).
const [loading, setLoading] = useState<boolean>(
- () => getCachedManifests() === null,
+ () => !canSeedLoadedFromCache(getCachedManifests()),
);
const loadedScripts = useRef<Set<string>>(new Set());