chore(store): tighten the copy-on-write comments in hydration placeholders

This commit is contained in:
Neil
2026-09-06 13:41:46 -07:00
parent 2112bd2899
commit efe19bdfb5
2 changed files with 4 additions and 9 deletions
@@ -23,11 +23,8 @@ export function buildRuntimeSessionPlaceholders({
repos: readonly Repo[]
worktreesByRepo: Record<string, Worktree[]>
} {
// Why not `repos.slice()`: hydration writes this array straight back to the store, and
// sessions that add no placeholder repo are the common case. Copying unconditionally
// gave `repos` a new identity on every workspace hydration, rerendering every component
// that selects the whole array. Appends below already build a new array, as
// nextWorktreesByRepo does for its own copy-on-write.
// Why copy-on-write: hydration writes both straight to the store, and an unconditional copy
// rerendered every whole-array/map selector on every hydration with no data change.
let nextRepos: readonly Repo[] = repos
let nextWorktreesByRepo = worktreesByRepo
for (const workspaceSessionKey of Object.keys(runtimeHostIdByWorkspaceSessionKey)) {
@@ -12,10 +12,8 @@ export function addHydratedSshWorktreePlaceholders(
tabsByWorktree: Record<string, TerminalTab[]>
): Record<string, Worktree[]> {
const sshRepoIds = new Set(repos.filter((repo) => repo.connectionId).map((repo) => repo.id))
// Why copy-on-write: hydration writes this map straight to the store, and a session
// that needs no SSH placeholder is the common case. Copying unconditionally gave
// worktreesByRepo a new identity on every hydration, rerendering the sidebar and
// everything else selecting the whole map for no data change.
// Why copy-on-write: hydration writes this map straight to the store; an unconditional copy
// rerendered every whole-map selector on every hydration with no data change.
let worktreesByRepo = sourceWorktreesByRepo
for (const worktreeId of Object.keys(tabsByWorktree)) {
const repoId = getRepoIdFromWorktreeId(worktreeId)