Fix joinRoom failing when the roomviewstore state changes. (#34180)

* Fix joinRoom failing when the roomviewstore state changes.

* drive by type fix

* Help debugging failed dispatches

* Use proper types and include roomId in RoomViewStore tests

* remove focus

* Update apps/web/src/stores/RoomViewStore.tsx

Co-authored-by: R Midhun Suresh <hi@midhun.dev>

* fmt

* Add a test for coverage

---------

Co-authored-by: R Midhun Suresh <hi@midhun.dev>
This commit is contained in:
Will Hunt
2026-07-28 16:41:36 +00:00
committed by GitHub
co-authored by R Midhun Suresh
parent f2cc9353ac
commit ea38041c87
3 changed files with 67 additions and 31 deletions
+11 -8
View File
@@ -31,13 +31,12 @@ export function untilDispatch(
timeout = 1000,
): Promise<ActionPayload> {
const callerLine = new Error().stack!.toString().split("\n")[2];
if (typeof waitForAction === "string") {
const action = waitForAction;
waitForAction = (payload) => {
return payload.action === action;
};
}
const callback = waitForAction as (payload: ActionPayload) => boolean;
const callback =
typeof waitForAction === "string"
? (payload: ActionPayload) => {
return payload.action === waitForAction;
}
: waitForAction;
return new Promise((resolve, reject) => {
let fulfilled = false;
let timeoutId: number;
@@ -45,7 +44,11 @@ export function untilDispatch(
if (timeout > 0) {
timeoutId = window.setTimeout(() => {
if (!fulfilled) {
reject(new Error(`untilDispatch: timed out at ${callerLine}`));
reject(
new Error(
`untilDispatch: timed out (waiting for: ${typeof waitForAction === "function" ? "fn" : waitForAction}) at ${callerLine}`,
),
);
fulfilled = true;
}
}, timeout);