Skip to content

Commit

Permalink
Add board ID checks to avoid flaky behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
raimohanska committed Mar 11, 2024
1 parent c3fe3d9 commit f37316a
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions frontend/src/store/board-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,10 @@ export function BoardStore(
const users = state.users.map((u) => (u.sessionId === event.sessionId ? event : u))
return { ...state, users }
} else if (event.action === "board.init") {
if (event.board.id !== state.board?.id) {
console.warn(`Got board.init for non-matching board ${event.board.id} != ${boardId.get()}`)
return state
}
console.log(`Going to online mode. Init as new board at serial ${event.board.serial}`)
const newServerShadow = event.board
// Local board = server shadow + local queue
Expand All @@ -362,6 +366,10 @@ export function BoardStore(
sent: [],
}
} else if (event.action === "board.init.diff") {
if (event.boardAttributes.id !== state.board?.id) {
console.warn(`Got board.init for non-matching board ${event.boardAttributes.id} != ${state.board?.id}`)
return state
}
if (event.first) {
// Ensure local buffer empty on first chunk even if an earlier init was aborted.
initialServerSyncEventBuffer = []
Expand Down Expand Up @@ -512,6 +520,10 @@ export function BoardStore(
if (boardId) {
console.log("Got board id, fetching local state", boardId)
const storedInitialState = await localStore.getInitialBoardState(boardId)
if (storedInitialState && storedInitialState.serverShadow.id !== boardId) {
console.log("Abort: board id already changed")
return
}
dispatch({ action: "ui.board.setLocal", boardId, storedInitialState }) // This is for the reducer locally to start offline mode
checkReadyToJoin()
}
Expand Down

0 comments on commit f37316a

Please sign in to comment.