Skip to content

Commit 672b2a1

Browse files
fix(ui): preserve profile theme while offline (#133417)
1 parent ef3b02e commit 672b2a1

4 files changed

Lines changed: 73 additions & 6 deletions

File tree

‎ui/src/app/app-host.server-prefs.test.ts‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,10 @@ describe("OpenClaw shell locale preferences", () => {
4848
const runtimeConfig = { state } as unknown as ApplicationContext["runtimeConfig"];
4949
const refreshTheme = vi.fn();
5050
const context = {
51-
gateway: { connection: { gatewayUrl: "ws://locale.test" } },
51+
gateway: {
52+
connection: { gatewayUrl: "ws://locale.test" },
53+
snapshot: { phase: "connected" },
54+
},
5255
navigation: { update: vi.fn() },
5356
theme: { refresh: refreshTheme },
5457
runtimeConfig,
@@ -84,7 +87,10 @@ describe("OpenClaw shell locale preferences", () => {
8487
const runtimeConfig = { state } as unknown as ApplicationContext["runtimeConfig"];
8588
const refreshTheme = vi.fn();
8689
const context = {
87-
gateway: { connection: { gatewayUrl: "ws://locale.test" } },
90+
gateway: {
91+
connection: { gatewayUrl: "ws://locale.test" },
92+
snapshot: { phase: "connected" },
93+
},
8894
navigation: { update: vi.fn() },
8995
theme: { refresh: refreshTheme },
9096
runtimeConfig,
@@ -116,7 +122,10 @@ describe("OpenClaw shell locale preferences", () => {
116122
const runtimeConfig = { state } as unknown as ApplicationContext["runtimeConfig"];
117123
const recordServerSelection = vi.fn();
118124
const context = {
119-
gateway: { connection: { gatewayUrl: "ws://theme.test" } },
125+
gateway: {
126+
connection: { gatewayUrl: "ws://theme.test" },
127+
snapshot: { phase: "connected" },
128+
},
120129
navigation: { update: vi.fn() },
121130
theme: { recordServerSelection, refresh: vi.fn(), serverSelection: null },
122131
runtimeConfig,

‎ui/src/app/app-host.test.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,10 @@ describe("OpenClaw shell server preferences", () => {
618618
},
619619
} as unknown as ApplicationContext["runtimeConfig"];
620620
const context = {
621-
gateway: { connection: { gatewayUrl: "ws://sidebar.test" } },
621+
gateway: {
622+
connection: { gatewayUrl: "ws://sidebar.test" },
623+
snapshot: { phase: "connected" },
624+
},
622625
navigation: { update: updateNavigation },
623626
theme: { refresh: refreshTheme },
624627
// reconcileServerUiPrefs only accepts the current context's capability.

‎ui/src/app/app-shell-gateway.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,13 @@ export class ShellGatewayOwner {
100100
reconcileServerUiPrefs(runtimeConfig: ApplicationContext["runtimeConfig"]): void {
101101
const snapshot = runtimeConfig.state.configSnapshot;
102102
const context = this.host.context;
103-
if (!snapshot?.config || !context || context.runtimeConfig !== runtimeConfig) {
103+
if (
104+
!snapshot?.config ||
105+
!context ||
106+
context.runtimeConfig !== runtimeConfig ||
107+
// selfUser is cleared on close; retained config must not reclassify that as an identity swap.
108+
context.gateway.snapshot.phase !== "connected"
109+
) {
104110
return;
105111
}
106112
const scope = context.gateway.connection.gatewayUrl;

‎ui/src/e2e/settings-prefs-reconnect.e2e.test.ts‎

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@ function patchPrefs(request: MockGatewayRequest): Record<string, unknown> {
4444
return requireRecord(ui.prefs, "config.patch ui.prefs");
4545
}
4646

47-
async function createContext(): Promise<BrowserContext> {
47+
async function createContext(colorScheme?: "dark" | "light"): Promise<BrowserContext> {
4848
return suite.browser.newContext({
49+
...(colorScheme ? { colorScheme } : {}),
4950
locale: "en-US",
5051
serviceWorkers: "block",
5152
viewport: { height: 900, width: 1440 },
@@ -135,6 +136,54 @@ function themeModeOption(page: Page, mode: "system" | "light" | "dark") {
135136
}
136137

137138
suite.define(() => {
139+
it("preserves a profile's explicit light theme while reconnecting", async () => {
140+
const context = await createContext("dark");
141+
const page = await context.newPage();
142+
const initial = configResponse({}, "prefs-profile-light-1");
143+
const gateway = await installMockGateway(page, {
144+
methodResponses: {
145+
"config.get": initial,
146+
"users.prefs.get": {
147+
entries: { "ui.theme": "claw", "ui.themeMode": "light" },
148+
status: "ok",
149+
},
150+
},
151+
presenceUsers: [{ id: "profile-theme-light", self: true }],
152+
});
153+
154+
try {
155+
const response = await page.goto(`${suite.server.baseUrl}chat`);
156+
expect(response?.status()).toBe(200);
157+
await gateway.waitForRequest("config.get");
158+
await gateway.waitForRequest("users.prefs.get");
159+
await gateway.waitForRequest("chat.startup");
160+
await expect.poll(() => page.locator("html").getAttribute("data-theme-mode")).toBe("light");
161+
await expect
162+
.poll(() => page.locator("html").getAttribute("data-theme-resolved"))
163+
.toBe("light");
164+
await expect
165+
.poll(() => readSettingsMirror(page))
166+
.toMatchObject({ theme: "claw", themeMode: "light" });
167+
168+
await gateway.setOnline(false);
169+
await page.locator(".sidebar-footer-bar__status").filter({ hasText: "Offline" }).waitFor();
170+
await page
171+
.locator(".agent-chat__composer-status-band")
172+
.filter({ hasText: "Offline" })
173+
.waitFor();
174+
175+
await expect.poll(() => page.locator("html").getAttribute("data-theme-mode")).toBe("light");
176+
await expect
177+
.poll(() => page.locator("html").getAttribute("data-theme-resolved"))
178+
.toBe("light");
179+
await expect
180+
.poll(() => readSettingsMirror(page))
181+
.toMatchObject({ theme: "claw", themeMode: "light" });
182+
} finally {
183+
await context.close();
184+
}
185+
});
186+
138187
it("replays an offline theme edit after a same-client reconnect", async () => {
139188
const context = await createContext();
140189
const page = await context.newPage();

0 commit comments

Comments
 (0)