Skip to content

Commit 5000a57

Browse files
authored
Merge pull request Expensify#89748 from Expensify/claude-restoreWorkspacesTabFromSessionStorage
Fix workspace tab restore from session storage after refresh
2 parents 27ccc64 + b6b13dc commit 5000a57

2 files changed

Lines changed: 15 additions & 6 deletions

File tree

src/hooks/useRestoreWorkspacesTabOnNavigate.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ function useRestoreWorkspacesTabOnNavigate() {
5959
}
6060

6161
// Fall back to session storage when no workspace route exists anywhere in the navigation tree.
62-
const sessionRoute = getWorkspacesTabStateFromSessionStorage()
62+
// getStateFromPath returns state rooted at TAB_NAVIGATOR, so we must drill into it first.
63+
const sessionTabNavigatorRoute = getWorkspacesTabStateFromSessionStorage()?.routes?.findLast((route) => route.name === NAVIGATORS.TAB_NAVIGATOR);
64+
const sessionRoute = getTabState(sessionTabNavigatorRoute)
6365
?.routes?.findLast((route) => route.name === NAVIGATORS.WORKSPACE_NAVIGATOR)
6466
?.state?.routes?.findLast((route) => isWorkspaceNavigatorRouteName(route.name));
6567
if (sessionRoute) {

tests/unit/hooks/useRestoreWorkspacesTabOnNavigate.test.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -299,16 +299,23 @@ describe('useRestoreWorkspacesTabOnNavigate', () => {
299299
lastVisitedTabPathUtils.getWorkspacesTabStateFromSessionStorage.mockReturnValue({
300300
routes: [
301301
{
302-
name: NAVIGATORS.WORKSPACE_NAVIGATOR,
302+
name: NAVIGATORS.TAB_NAVIGATOR,
303303
state: {
304304
routes: [
305305
{
306-
name: NAVIGATORS.WORKSPACE_SPLIT_NAVIGATOR,
306+
name: NAVIGATORS.WORKSPACE_NAVIGATOR,
307307
state: {
308-
index: 1,
309308
routes: [
310-
{name: SCREENS.WORKSPACE.INITIAL, params: {policyID: fakePolicyID}},
311-
{name: SCREENS.WORKSPACE.WORKFLOWS, params: {policyID: fakePolicyID}},
309+
{
310+
name: NAVIGATORS.WORKSPACE_SPLIT_NAVIGATOR,
311+
state: {
312+
index: 1,
313+
routes: [
314+
{name: SCREENS.WORKSPACE.INITIAL, params: {policyID: fakePolicyID}},
315+
{name: SCREENS.WORKSPACE.WORKFLOWS, params: {policyID: fakePolicyID}},
316+
],
317+
},
318+
},
312319
],
313320
},
314321
},

0 commit comments

Comments
 (0)