Skip to content

Navigation store: reopen a restored Daily Journal tab on today's date - #3854

Merged
mstomar125 merged 3 commits into
mainfrom
fix/3836-daily-journal-today
Oct 20, 2026
Merged

mstomar125 merged 3 commits into
mainfrom
fix/3836-daily-journal-today

Conversation

@mstomar125

Copy link
Copy Markdown
Contributor

What changed

loadPersistedState now passes restored tabs through withDailyJournalOnToday: a tab with id === DAILY_JOURNAL_TAB_ID whose node type is a date and whose nodeId is not today (local date) is re-pointed at today, its title set to the date, and its saved expandedNodeIds dropped (they belong to the other day's nodes). Other tabs, including other date tabs, are untouched. Node type is resolved with isA (ADR-086 gate).

Midnight rollover with the app left open is not handled here (separate from restore, as the issue allows).

Testing

  • bunx vitest run src/tests/stores/navigation.test.ts: 73 passed, with new cases: past-dated daily-journal tab shows today (title updated, expansion state dropped); tab already on today kept; non-daily-journal date tab untouched. Removing the fix makes the rewrite test fail.
  • eslint and prettier on the changed test file, eslint on the store, svelte-check: clean. Pre-push gate passed.

Closes #3836

🤖 Generated with Claude Code

@mstomar125 mstomar125 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review (initial) - #3854

Verdict: APPROVE WITH NITS

Reviewed at head, against #3836. Ran bun x vitest run src/tests/stores/navigation.test.ts in a throwaway worktree: 73 passed.

Requirements (#3836)

  • Unit test: past-dated daily-journal tab shows today after load; non-daily-journal date tab untouched (navigation.test.ts "Daily Journal date", 3 cases).
  • Midnight rollover with the app left open is explicitly noted as not handled in the PR body, as the issue allows.

Scenario check

  • Stale persisted date (the reported bug): covered. loadPersistedState maps restored tabs through withDailyJournalOnToday; only id === DAILY_JOURNAL_TAB_ID with a date node type and nodeId !== today is rewritten.
  • Deliberately opened past day: safe. Tabs opened through NavigationService.focusOrOpenNode get a fresh uuidv4() id (navigation-service.ts:523, :571), never daily-journal, so a past journal day the user opened on purpose is not matched. The test "leaves a date tab that is not the Daily Journal untouched" covers it. The one case that is rewritten is the daily-journal tab itself after the user paged it with the arrows or navigated it in place (pane-content.svelte:227, navigation-service.ts:425/447). That is exactly what the issue asks for ("also if the user paged with the arrows"), so it is correct, but see nit 3.
  • Timezone / DST: getTodayDateId() is formatDateISO(new Date()), i.e. the local calendar date, compared as a plain YYYY-MM-DD string. No date arithmetic, so DST transitions cannot shift it. A state saved in one timezone and restored in another is simply compared against the local date at load, which is the desired behaviour. The test uses the local-time Date constructor, consistent with that.
  • Multiple tabs / panes: only the single tab with the reserved id is touched; the map preserves tab order and pane/activeTabIds references (the id is unchanged). Other tabs, including other date tabs, keep their state.
  • Title / expansion state: expandedNodeIds is dropped for a rewritten tab only (correct: those ids belong to the other day's nodes, and scheduleRestoration then skips it); a tab already on today keeps it (tested). The rewritten title is cosmetic, because tab titles are derived at render (tab-system.svelte:301 via computeTabTitle, and the date viewer shows "Today").
  • A tab with missing content or a non-date type returns early (tab.content?.nodeType + isA), so a malformed persisted entry cannot throw.

Findings

  • Non-blocking (nit) packages/desktop-app/src/lib/stores/navigation.svelte.ts:181-186: the two-line comment ("The Daily Journal tab always opens on the current date...") is duplicated verbatim, and the blank line between the copies has trailing whitespace. Remove one copy.
  • Non-blocking (nit) navigation.svelte.ts:185: persisted.tabs = ... mutates the object returned by TabPersistenceService.load(). Harmless today (fresh parse each call), but building the new tabs array into the state assignment directly is cleaner and avoids surprising a future caching load().
  • Non-blocking (follow-up) midnight rollover: with the app left open overnight the daily-journal tab stays on yesterday, and the sidebar "Daily Journal" button then opens a second tab for the new today (navigation-sidebar.svelte:~250, matchNodeType) rather than re-pointing the journal tab. Fine per the issue, but worth a tracking issue so it is not forgotten.
  • Non-blocking (test gap) no test for a non-date content.nodeType on the daily-journal id (the in-place-navigated-to-a-regular-node case, which must stay untouched), nor for a two-pane layout. The code path is covered by the early return; a one-line test would lock it.
  • Informational a daily-journal tab navigated in place to a non-date node restores that node forever (pre-existing, out of scope here).

No security or performance concerns. Docs: none needed.

mstomar125 and others added 3 commits October 20, 2026 13:29
loadPersistedState rewrote nothing, so the daily-journal tab kept the date it
was saved with. withDailyJournalOnToday re-points a date-typed daily-journal
tab at the current local date, updates its title and drops its saved expansion
state; other tabs are untouched.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…ly-journal tab is kept

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@mstomar125
mstomar125 force-pushed the fix/3836-daily-journal-today branch from 11e72bc to 1c0f963 Compare October 20, 2026 11:29
@mstomar125
mstomar125 merged commit e4ccc8f into main Oct 20, 2026
@mstomar125
mstomar125 deleted the fix/3836-daily-journal-today branch October 20, 2026 11:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Daily Journal tab restores a stale date from persisted tab state

1 participant