authorgravatar for julius0216@outlook.comJulius Marminge <julius0216@outlook.com> 2026-04-09 14:26:28-07:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2026-04-09 14:26:28-07:00
log70f5dfcef78a8e153ab698c0b83661974a4fc033
treea0b7a282eab3757e3ada68d80b18e92241c9cbe1
parent9847e9b6211df61bd6d3d1142538ec4df77e0013
signature Signed by PGP key B5690EEEBB952194

Stabilize keybindings toast stream setup (#1860)

Co-authored-by: Julius Marminge <julius@macmini.local>

1 files changed, 29 insertions(+), 8 deletions(-)

apps/web/src/components/KeybindingsToast.browser.tsx+29-8
...@@ -21,7 +21,7 @@ import { render } from "vitest-browser-react";...@@ -21,7 +21,7 @@ import { render } from "vitest-browser-react";
21import { useComposerDraftStore } from "../composerDraftStore";21import { useComposerDraftStore } from "../composerDraftStore";
22import { __resetLocalApiForTests } from "../localApi";22import { __resetLocalApiForTests } from "../localApi";
23import { AppAtomRegistryProvider } from "../rpc/atomRegistry";23import { AppAtomRegistryProvider } from "../rpc/atomRegistry";
24import { getServerConfig } from "../rpc/serverState";24import { getServerConfig, getServerConfigUpdatedNotification } from "../rpc/serverState";
25import { getWsConnectionStatus } from "../rpc/wsConnectionState";25import { getWsConnectionStatus } from "../rpc/wsConnectionState";
26import { getRouter } from "../router";26import { getRouter } from "../router";
27import { useStore } from "../store";27import { useStore } from "../store";
...@@ -303,11 +303,6 @@ async function waitForNoToasts(): Promise<void> {...@@ -303,11 +303,6 @@ async function waitForNoToasts(): Promise<void> {
303 );303 );
304}304}
305305
306async function warmServerConfigUpdateStream(): Promise<void> {
307 sendServerConfigUpdatedPush([]);
308 await new Promise((resolve) => setTimeout(resolve, 50));
309}
310
311async function waitForInitialWsSubscriptions(): Promise<void> {306async function waitForInitialWsSubscriptions(): Promise<void> {
312 await vi.waitFor(307 await vi.waitFor(
313 () => {308 () => {
...@@ -331,6 +326,33 @@ async function waitForServerConfigSnapshot(): Promise<void> {...@@ -331,6 +326,33 @@ async function waitForServerConfigSnapshot(): Promise<void> {
331 );326 );
332}327}
333328
329async function waitForServerConfigStreamReady(): Promise<void> {
330 const previousNotificationId = getServerConfigUpdatedNotification()?.id ?? 0;
331 for (let attempt = 0; attempt < 20; attempt += 1) {
332 rpcHarness.emitStreamValue(WS_METHODS.subscribeServerConfig, {
333 version: 1,
334 type: "settingsUpdated",
335 payload: { settings: fixture.serverConfig.settings },
336 });
337
338 try {
339 await vi.waitFor(
340 () => {
341 const notification = getServerConfigUpdatedNotification();
342 expect(notification?.id).toBeGreaterThan(previousNotificationId);
343 expect(notification?.source).toBe("settingsUpdated");
344 },
345 { timeout: 200, interval: 16 },
346 );
347 return;
348 } catch {
349 await new Promise((resolve) => setTimeout(resolve, 25));
350 }
351 }
352
353 throw new Error("Timed out waiting for the server config stream to deliver updates.");
354}
355
334async function mountApp(): Promise<{ cleanup: () => Promise<void> }> {356async function mountApp(): Promise<{ cleanup: () => Promise<void> }> {
335 const host = document.createElement("div");357 const host = document.createElement("div");
336 host.style.position = "fixed";358 host.style.position = "fixed";
...@@ -356,6 +378,7 @@ async function mountApp(): Promise<{ cleanup: () => Promise<void> }> {...@@ -356,6 +378,7 @@ async function mountApp(): Promise<{ cleanup: () => Promise<void> }> {
356 await waitForInitialWsSubscriptions();378 await waitForInitialWsSubscriptions();
357 await waitForWsConnection();379 await waitForWsConnection();
358 await waitForServerConfigSnapshot();380 await waitForServerConfigSnapshot();
381 await waitForServerConfigStreamReady();
359 await waitForNoToasts();382 await waitForNoToasts();
360383
361 return {384 return {
...@@ -429,8 +452,6 @@ describe("Keybindings update toast", () => {...@@ -429,8 +452,6 @@ describe("Keybindings update toast", () => {
429 const mounted = await mountApp();452 const mounted = await mountApp();
430453
431 try {454 try {
432 await warmServerConfigUpdateStream();
433
434 sendServerConfigUpdatedPush([]);455 sendServerConfigUpdatedPush([]);
435 await waitForToast("Keybindings updated", 1);456 await waitForToast("Keybindings updated", 1);
436457