Refactor web stores into atomic slices#1708
Refactor web stores into atomic slices#1708justsomelegs wants to merge 2 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 |
ApprovabilityVerdict: Needs human review This is a major architectural refactor of the central state management store, converting from nested arrays to normalized atomic slices with new type abstractions (ThreadShell, ThreadTurnState). While runtime behavior should be equivalent, this restructures shared infrastructure that all components depend on and warrants human review to verify the migration is complete and correct. You can customize Macroscope's approvability policy. Learn more. |
What Changed
Refactored the web orchestration store from broad array-based state into a more atomic normalized shape.
Main changes:
projects[]/threads[]as the primary store shape with keyed records and id listsOld Pattern
New Pattern
Why
The old store shape forced many consumers to read broad collections and then search inside them. That made fine-grained subscriptions hard and set us up for unnecessary rerenders once we start breaking large components into smaller ones.
This change establishes the state model we actually want to build on:
Sidebar,ChatView, and other hot UI pathsKeeping this as a store-shape-first PR also keeps the follow-up performance work simpler. Future PRs can focus on splitting components and wiring each subcomponent to only the exact slice it needs.
Checklist
Note
Refactor web store state from denormalized arrays to normalized id/map slices
projects,threads, andsidebarThreadsByIdarrays inAppStatewith normalized maps (projectById,threadShellById,threadSessionById,threadTurnStateById, per-thread message/activity/plan/diff maps) and corresponding id arrays.writeThreadStateandremoveThreadStateas central writers that atomically update all normalized slices, handling project moves and sidebar summary maintenance.selectProjectsandselectThreadsselectors to hydrate full entity arrays from normalized state; existingselectProjectByIdandselectThreadByIdare reimplemented against the new maps.createThreadSelectorin storeSelectors.ts, a memoized selector factory that assembles a fullThreadfrom state shards and returns stable references when inputs are unchanged.state.projects,state.threads, orstate.sidebarThreadsByIddirectly will break; all reads must go through selectors or normalized maps.Macroscope summarized 0737ff4.