Skip to content

Conversation

@ammar-agent
Copy link
Collaborator

Follows up on #335 (syntax highlighting perf) with FileTree state persistence.

Problem

FileTree directory expand/collapse state resets on workspace switch, forcing users to re-expand directories every time.

Solution

Use existing pattern to remember directory expand state per workspace:

  • Store as Record<string, boolean> keyed by node path
  • Default to expanded for first 2 levels if no manual state
  • Use { listener: true } for cross-component sync
  • State copied on fork, deleted on removal

Implementation

Follows exact pattern from hunk expand state (PR #332):

  • Added getFileTreeExpandStateKey(workspaceId) to storage.ts
  • Registered in PERSISTENT_WORKSPACE_KEY_FUNCTIONS for cleanup/copy
  • Updated FileTree component to use usePersistedState instead of useState
  • Pass workspaceId from ReviewPanelFileTreeTreeNodeContent

Testing

  • ✅ TypeScript compilation passes
  • ✅ All 661 tests pass
  • Manual testing: Expand directories, switch workspaces, verify state persists

Generated with cmux

Use existing usePersistedState pattern to remember directory expand/collapse
preferences across workspace switches. State is stored in localStorage with
workspace-scoped key 'fileTreeExpandState:{workspaceId}'.

Implementation follows the same pattern as hunk expand state (PR #332):
- Store expand state as Record<string, boolean> keyed by node path
- Default to expanded for first 2 levels if no manual state exists
- Use { listener: true } for cross-component synchronization
- State is copied on workspace fork and deleted on workspace removal

Benefits:
- Users don't need to re-expand folders after switching workspaces
- Reduces cognitive load when navigating between workspaces
- Consistent UX with hunk expand/collapse behavior
@ammar-agent ammar-agent force-pushed the filetree-persist-toggle-state branch from 3309c27 to bfaa64d Compare October 19, 2025 18:35
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Previously every TreeNodeContent subscribed to the same storage key,
causing O(total nodes) re-renders on each toggle. Now FileTree owns
the persisted state and passes it down, so only affected branches
re-render on expand/collapse.

Addresses Codex P1 review comment.
Removed redundant background from DiffContainer. The individual diff lines
(DiffLineWrapper) already have appropriate backgrounds for add/remove lines,
so the container background was creating a double-layer grey effect.

Also added 'background: transparent' to pre/code elements in prism-syntax.css
and updated the generation script for future regenerations.

Resolves double-grey background issue in FileEditToolCall diffs.
@ammar-agent ammar-agent force-pushed the filetree-persist-toggle-state branch from 59648a5 to 56a90ab Compare October 19, 2025 18:47
Added --color-code-bg variable (hsl(0deg 6.43% 8.04%)) in colors.tsx
and replaced all hardcoded rgba(0, 0, 0, 0.2) code backgrounds with it.

Ensures consistent appearance across:
- DiffContainer (file edits, review diffs)
- HunkContent (review panel hunks)
- Tool call displays (file read, bash, etc.)
- Markdown code blocks
- Mermaid diagrams

Single source of truth prevents inconsistent shades of grey.
@ammar-agent ammar-agent force-pushed the filetree-persist-toggle-state branch from 3718403 to 0fcc420 Compare October 19, 2025 18:55
@ammario ammario added this pull request to the merge queue Oct 19, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Oct 19, 2025
@ammario ammario merged commit 1dc11e6 into main Oct 19, 2025
8 checks passed
@ammario ammario deleted the filetree-persist-toggle-state branch October 19, 2025 20:03
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.

2 participants