You are reviewing a real production React + Zustand + Vite codebase to give an…
- User
You are reviewing a real production React + Zustand + Vite codebase to give an opinionated architectural assessment. The user wants an INDEPENDENT take — don't echo any preconception, form your own view from the code.
The domain
The codebase has multiple "selection surfaces" (a gallery pane, a video-editor timeline, soon possibly more) that compose into a "current attachment set" consumed by an agent chat panel. The chat panel can also clear/replace attachments back into the underlying surfaces. Cross-surface coordination rules apply (e.g., clicking a clip in the timeline should clear gallery selection by default; agent-chat-driven attachment changes should NOT clear gallery).
Recent symptoms the user has hit, all in this surface area:
- Cmd+click multi-select on gallery items dropped the modifier intermittently (modifier read from racy global keydown listener instead of the click event).
- Single clicks on gallery items dropped intermittently when the user's hand moved a few px between mousedown and mouseup (HTML5
draggable=trueon a wrapper preempted the inner img onClick). - Clicking a timeline clip didn't clear gallery selection because a wrapper hook hardcoded
clearGallery: falsefor all callers, while the underlying store action defaulted toclearGallery: true. - Removing an attachment chip via the chat sometimes didn't propagate because the bridge from VideoEditorProvider into the agent chat used a
get timelineClips() { return clipsRef.current }getter — consumers of the React context never saw a value-identity change so they didn't re-render. - Clicking from a gallery item to a timeline clip causes the chat's attachment strip to FLICKER (unmount → remount) because the bridge propagates timeline updates ONE React commit later than the gallery store does.
- Generations pane HTTP 400s because supabase-js's
.or()was chained twice on the same query, producing duplicateor=query-string params that PostgREST rejects.
These were each fixed point-wise. The user is now asking: are these all symptoms of the same underlying structural issue? What's the right level of abstraction for this surface?
Files to read (PROJECT_DIR = /Users/user_c042661f/Documents/reigh-workspace/reigh-app)
Read these — they're the load-bearing pieces of the selection / coordination surface. You do NOT need to read tests.
Core selection store and adapters:
- src/shared/state/selectionStore.ts (the Zustand store with gallery + timeline slices, syncOptions, multiple mutation entry points)
- src/tools/video-editor/hooks/useTimelineSelection.ts (the wrapper that just had its hardcoded
clearGallery: falseflipped)
- Assistant
I’ll use the
desloppifyskill because this is explicitly an architectural/code-health assessment. I’m going to read the load-bearing files you listed and anchor the opinion in concrete call paths, not the symptom list. - Assistant
The skill’s full scan workflow is aimed at making code changes, but this request is a focused architectural review and the workspace is read-only. I’m narrowing to the listed selection/bridge files and will avoid generating tracker state.
- Assistant
The store already centralizes some cross-surface policy, but the policy is expressed as low-level booleans on mutation APIs. That matters: the call sites still have to know whether they are “user changed surface” or “composer edited attachments,” which is exactly where one of the bugs came from.
- Assistant