fix(web): persist collapsed sidebar project state across relaunch#2259
fix(web): persist collapsed sidebar project state across relaunch#2259Marve10s wants to merge 4 commits intopingdotgg:mainfrom
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
9feb55e to
620f909
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 620f909. Configure here.
ApprovabilityVerdict: Needs human review This bug fix adds immediate state persistence for sidebar project collapse state. While the changes are contained and low-risk, there's an unresolved review comment questioning whether the approach is optimal, suggesting a simpler alternative may exist. You can customize Macroscope's approvability policy. Learn more. |
Dismissing prior approval to re-evaluate f1fcafe
| useUiStateStore, | ||
| } from "./uiStateStore"; | ||
|
|
||
| function createLocalStorageStub(): Storage { |
There was a problem hiding this comment.
Already have one of these.
Also i think u can just useUiStore.persist.clear() or whatever and it will use a memory fallback when LS is not available?
There was a problem hiding this comment.
Fixed this by extracting the duplicated createLocalStorageStub() into a shared test helper and reusing it from the affected tests.
I didn’t switch useUiStateStore over to useUiStateStore.persist.clearStorage() because this store doesn’t use Zustand’s persist middleware. Its persistence is manual (readPersistedState / persistState plus the module-level persisted-state caches), so the test still needs an explicit localStorage stub and explicit state reset.
Is this okay ? store architecture is smth I can edit but I think it's not the scope for this PR
There was a problem hiding this comment.
I meant this one: https://github.com/pingdotgg/t3code/blob/main/apps/web/src/lib/storage.ts
And ah, forgot this used manual storage. Not sure why 😝
There was a problem hiding this comment.
Oh, I misunderstood.
storage.ts exposes the repo’s StateStorage, not a full DOM Storage, tests are stubbing window.localStorage directly, so I'm kinda fine with the code in this PR. But if you think there is something to change - I can fix that up
Dismissing prior approval to re-evaluate 4d11318

Summary
This fixes project collapse state in the threads sidebar so it survives relaunches more reliably.
What Changed
collapsedProjectCwdsandexpandedProjectCwdsin sidebar UI stateRoot Cause
There were two separate persistence gaps:
User Impact
Collapsed projects in the sidebar now stay collapsed after relaunch instead of reopening unexpectedly.
Validation
bun fmtbun lintbun typecheckcurrently fails on unrelated existing repository issues inpackages/contractsbun run --cwd apps/web typecheckcurrently fails on unrelated existingmakeUnsafeand contracts typing issues elsewhere in the workspaceNote
Fix sidebar project collapsed state to persist across relaunch
useUiStateStoreactionssyncProjects,toggleProject,setProjectExpanded, andreorderProjectsnow callpersistStateimmediately after modifying state, instead of relying on a later sync.createLocalStorageStubis extracted from inline duplicates inclientPersistenceStorage.test.tsandlocalApi.test.ts.Macroscope summarized 4d11318.
Note
Medium Risk
Touches sidebar UI persistence and state synchronization logic; incorrect persistence or legacy-shape handling could cause project groups to re-expand or order to regress on restart.
Overview
Fixes sidebar project expand/collapse persistence by writing both
collapsedProjectCwdsandexpandedProjectCwdsso an “all collapsed” state round-trips across relaunch, while preserving the legacy “not in expanded list = collapsed” behavior for one upgrade session.Updates
useUiStateStoreactions (syncProjects,toggleProject,setProjectExpanded,reorderProjects) to persist immediately when they actually change state (in addition to the existing debounced subscriber), and adds regression tests for all-collapsed restart and immediate persistence. Also factors duplicated testlocalStoragestubs into a sharedcreateLocalStorageStubhelper.Reviewed by Cursor Bugbot for commit 4d11318. Bugbot is set up for automated code reviews on this repo. Configure here.