Compare commits

...
Author SHA1 Message Date
Sonarly Claude Code 5cd7daefe3 fix: clear navigation stack when closing side panel via Escape key
https://sonarly.com/issue/19881?type=bug

When closing a company record's side panel with Escape, the navigation stack retains the old entry, causing the duplicate-record guard to block reopening the same record.

Fix: Moved `store.set(sidePanelNavigationStackState.atom, newNavigationStack)` above the early-return guard in `goBackFromSidePanel()`. Previously, when the navigation stack became empty (single-record side panel closed via Escape), the function returned early without updating the stack state. This left stale entries that caused `openRecordInSidePanel`'s duplicate-record guard to block reopening the same record.

The fix ensures the navigation stack atom is always updated to the new value (whether empty or not) before any early return. The redundant duplicate `store.set` that was below the guard has been removed.

Updated the existing test to verify the navigation stack is cleared immediately after `goBackFromSidePanel()` — previously the test called both `goBackFromSidePanel()` and `sidePanelCloseAnimationCompleteCleanup()` in the same `act()` block, which masked the bug since the cleanup also resets the stack.
2026-03-31 08:10:12 +00:00
2 changed files with 7 additions and 3 deletions
@@ -100,10 +100,14 @@ describe('useSidePanelHistory', () => {
act(() => {
result.current.commandMenuHistory.goBackFromSidePanel();
result.current.sidePanelCloseAnimationCompleteCleanup.sidePanelCloseAnimationCompleteCleanup();
});
expect(jotaiStore.get(sidePanelNavigationStackState.atom)).toEqual([]);
act(() => {
result.current.sidePanelCloseAnimationCompleteCleanup.sidePanelCloseAnimationCompleteCleanup();
});
expect(jotaiStore.get(sidePanelPageState.atom)).toBe(
SidePanelPages.CommandMenuDisplay,
);
@@ -67,6 +67,8 @@ export const useSidePanelHistory = () => {
const newNavigationStack = currentNavigationStack.slice(0, -1);
const lastNavigationStackItem = newNavigationStack.at(-1);
store.set(sidePanelNavigationStackState.atom, newNavigationStack);
if (!isDefined(lastNavigationStackItem)) {
closeSidePanelMenu();
return;
@@ -80,8 +82,6 @@ export const useSidePanelHistory = () => {
instanceId: lastNavigationStackItem.pageId,
});
store.set(sidePanelNavigationStackState.atom, newNavigationStack);
store.set(hasUserSelectedSidePanelListItemState.atom, false);
}, [cleanupCurrentPage, closeSidePanelMenu, store]);