diff --git a/frontend-web/src/App.tsx b/frontend-web/src/App.tsx index a4a67c48..0235b013 100644 --- a/frontend-web/src/App.tsx +++ b/frontend-web/src/App.tsx @@ -61,7 +61,10 @@ function AppProviders({ children }: { children: React.ReactNode }) { // 走 next-themes forcedTheme(不写 localStorage)→ 同浏览器另开的正常系统页不受影响。 const embedTheme = resolveForcedEmbedTheme(location.search); if (embedTheme) return embedTheme; - const routeTheme = resolveForcedThemeForPath(location.pathname); + const routeTheme = resolveForcedThemeForPath( + location.pathname, + location.search, + ); if (routeTheme) return routeTheme; if (location.pathname === "/embed/roundtable") { const wp = readWujieProps(); diff --git a/frontend-web/src/core/page-layout/chats-iframe-route.test.mjs b/frontend-web/src/core/page-layout/chats-iframe-route.test.mjs index eefe33b2..5cdb649b 100644 --- a/frontend-web/src/core/page-layout/chats-iframe-route.test.mjs +++ b/frontend-web/src/core/page-layout/chats-iframe-route.test.mjs @@ -31,3 +31,20 @@ test("forces light theme for landing and chats_iframe routes only", () => { ); assert.equal(resolveForcedThemeForPath("/page/workspace/chats/new"), undefined); }); + +test("honors the dark-blue theme query on chats_iframe routes", () => { + assert.equal( + resolveForcedThemeForPath( + "/page/workspace/chats_iframe/new", + "?from=iframe&theme=dark-blue", + ), + "dark", + ); + assert.equal( + resolveForcedThemeForPath( + "/page/workspace/chats_iframe/new", + "?from=iframe&theme=red", + ), + "light", + ); +}); diff --git a/frontend-web/src/core/page-layout/chats-iframe-route.ts b/frontend-web/src/core/page-layout/chats-iframe-route.ts index 30c6ba78..06b13117 100644 --- a/frontend-web/src/core/page-layout/chats-iframe-route.ts +++ b/frontend-web/src/core/page-layout/chats-iframe-route.ts @@ -1,3 +1,5 @@ +import { resolveEmbedThemeMode } from "@/core/embed/embed-session"; + export function isChatsIframeWorkspacePath(pathname: string): boolean { return ( pathname === "/page/workspace/chats_iframe/new" || @@ -7,10 +9,17 @@ export function isChatsIframeWorkspacePath(pathname: string): boolean { export function resolveForcedThemeForPath( pathname: string, -): "light" | undefined { - if (pathname === "/landing" || isChatsIframeWorkspacePath(pathname)) { + search = "", +): "light" | "dark" | undefined { + if (pathname === "/landing") { return "light"; } + if (isChatsIframeWorkspacePath(pathname)) { + const normalizedSearch = search.startsWith("?") ? search : `?${search}`; + const rawTheme = new URLSearchParams(normalizedSearch).get("theme")?.trim(); + return rawTheme ? resolveEmbedThemeMode(rawTheme) : "light"; + } + return undefined; }