Skip to content

Commit c04019d

Browse files
committed
fix(app): hoist navigate out of removeSessions produce callback
Gemini code review on PR #26 flagged that removeSessions ran navigate() inside the Immer produce callback, which is unsafe — produce should be pure mutation only, and triggering routing during the store write phase can cause race conditions and double-renders. removeTab already followed the correct pattern (compute nextHref inside produce, navigate outside); mirror it for removeSessions. Refs: LAC-2281
1 parent 5993c24 commit c04019d

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

‎packages/app/src/components/titlebar.tsx‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@ export function Titlebar(props: { update?: TitlebarUpdate }) {
299299
},
300300
removeSessions: (input: SessionTabsRemovedDetail) => {
301301
void startTransition(() => {
302+
let nextHref: string | undefined
302303
setStore(
303304
produce((tabs) => {
304305
const sessionIDs = new Set(input.sessionIDs)
@@ -319,10 +320,12 @@ export function Titlebar(props: { update?: TitlebarUpdate }) {
319320

320321
if (!removedCurrent) return
321322
const nextTab = tabs[currentIndex] ?? tabs[tabs.length - 1]
322-
if (nextTab) navigate(nextTab.href)
323-
else navigate("/")
323+
nextHref = nextTab ? nextTab.href : "/"
324324
}),
325325
)
326+
if (nextHref !== undefined) {
327+
navigate(nextHref)
328+
}
326329
})
327330
},
328331
}

0 commit comments

Comments
 (0)