Skip to content

improvement(files): react-doctor performance pass on the files module#5330

Merged
waleedlatif1 merged 2 commits into
stagingfrom
worktree-files-react-doctor
Jul 1, 2026
Merged

improvement(files): react-doctor performance pass on the files module#5330
waleedlatif1 merged 2 commits into
stagingfrom
worktree-files-react-doctor

Conversation

@waleedlatif1

Copy link
Copy Markdown
Collaborator

Summary

  • Ran npx react-doctor on the files module and applied the safe, behavior-preserving performance wins
  • Owner resolution in the file list was O(rows × members) — every row and every sort comparison did a linear members.find(...). Now builds a membersById map once and does O(1) lookups; ownerCell accepts either the array or a precomputed Map (backward compatible, no change for tables/knowledge callers)
  • Replaced two redundant [...arr].sort() copies with non-mutating arr.toSorted() (apps/sim is on the ES2023 lib)
  • Merged the selectedFileIds/selectedFolderIds memos into a single-pass partition instead of parsing every selected row id twice
  • Documented the react-doctor best-practice patterns + known false-positive judgments in .claude/rules/sim-components.md so future agent passes apply them

Type of Change

  • Performance improvement

Testing

  • tsc clean (0 errors), Biome clean, bun run lint green
  • Four independent audit passes confirmed identical observable behavior and zero regressions (owner column, sort order, filter labels, selection counts). Duplicate-userId edge is impossible given the permissions uniqueness constraint
  • react-doctor Performance findings 25 → 19, total 122 → 116

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel

vercel Bot commented Jul 1, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
docs Ready Ready Preview, Comment Jul 1, 2026 8:12pm

Request Review

@cursor

cursor Bot commented Jul 1, 2026

Copy link
Copy Markdown

PR Summary

Low Risk
UI-only performance and backward-compatible ownerCell typing; no auth, API, or data-model changes.

Overview
Files list performance: The workspace files view no longer resolves owners with repeated members.find(...) per row, per sort comparison, or in filter UI. It builds a membersById Map once and uses membersById.get everywhere those names are needed.

ownerCell: Accepts either the member array or a precomputed Map<string, WorkspaceMember> so callers with many rows can pass the map without changing behavior for existing array callers.

Selection: selectedFileIds / selectedFolderIds are derived in one useMemo pass over selectedRowIds instead of two separate map/filter chains.

Docs (.claude/rules/sim-components.md): Adds list-render performance rules (precompute lookup maps, use [...arr].sort(cmp) in client components—not unpolyfilled toSorted on Safari <16—and single-pass partitioning) plus react-doctor guidance on which diagnostics to apply vs treat as false positives in this repo.

Reviewed by Cursor Bugbot for commit 3c0b175. Configure here.

@greptile-apps

greptile-apps Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR applies targeted, behavior-preserving performance improvements to the files module: a membersById lookup Map replaces per-row Array.find scans, a single-pass partition replaces two duplicate memo traversals, and ownerCell is extended to accept a precomputed Map alongside the existing array type.

  • membersById Map (files.tsx): Built once in useMemo, replaces O(n) .find(...) calls inside the sort comparator (eliminating the O(n²·log n) worst-case) and all cell-builder callsites. Downstream memos correctly depend on membersById instead of the raw members array.
  • Selection partition (files.tsx): Two Array.from → map → filter → map chains are collapsed into one for…of pushing into fileIds/folderIds buckets, returned from a single useMemo.
  • ownerCell overload (owner-cell.tsx): The members parameter now accepts WorkspaceMember[] | Map<string, WorkspaceMember>, with an instanceof Map branch — fully backward-compatible for existing array callers.

Confidence Score: 5/5

All three changes are behavior-preserving refactors with no new network calls, state mutations, or API contract changes; safe to merge.

The Map lookup and single-pass partition are strictly equivalent to the replaced code for all inputs reachable at runtime: membersById is always a truthy Map so the !members early-return in ownerCell is now unreachable, but the downstream !member guard produces the same null label; parseRowId always returns kind 'file' | 'folder' so the else branch correctly populates folderIds. No behavioral edge case was introduced.

No files require special attention — all changes are local to the files module and the owner-cell utility.

Important Files Changed

Filename Overview
apps/sim/app/workspace/[workspaceId]/files/files.tsx Builds membersById Map once via useMemo, replaces all members?.find(...) calls with O(1) .get(), merges two selection-partition memos into one single-pass loop. All changes are behavior-preserving.
apps/sim/app/workspace/[workspaceId]/components/resource/components/owner-cell/owner-cell.tsx Extends ownerCell parameter type to `WorkspaceMember[]
.claude/rules/sim-components.md Documents the new O(1) lookup Map pattern, explains why toSorted is a won't-fix in client components (Safari compat), and catalogues react-doctor false positives for future agent passes.

Reviews (3): Last reviewed commit: "fix(files): use spread-sort not toSorted..." | Re-trigger Greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cursor review

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 2bf35a9. Configure here.

…rash)

SWC does not polyfill Array.prototype.toSorted and the repo sets no
core-js/browserslist target, so it throws on Safari <16 / iOS 15. Revert
the two client-side toSorted calls to [...arr].sort() and correct the
harness guidance in sim-components.md accordingly.
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cursor review

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 3c0b175. Configure here.

@waleedlatif1 waleedlatif1 merged commit 76537c8 into staging Jul 1, 2026
17 checks passed
@waleedlatif1 waleedlatif1 deleted the worktree-files-react-doctor branch July 1, 2026 20:15
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.

1 participant