Skip to content

Commit ba2f6f1

Browse files
committed
refactor(tables): tidy lazy ref init and align perf-rule cross-reference
- use-workspace-imports: lazy-init the status Map at its point of use in the effect ((ref.current ??= new Map())) instead of mutating the ref during render with a separate in-effect fallback. The ref is only read in the effect, so this removes the render-phase write and the dead '?? new Map()' branch while keeping the identical persistent Map. - CLAUDE.md: fix the render-performance pointer so it matches the rule doc — toSorted/toReversed are unsafe on client render paths (SWC does not polyfill prototype methods), not merely an ES2022/ES2023 lib note.
1 parent dc4510c commit ba2f6f1

2 files changed

Lines changed: 2 additions & 3 deletions

File tree

CLAUDE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ export function Component({ requiredProp, optionalProp = false }: ComponentProps
127127

128128
Extract when: 50+ lines, used in 2+ files, or has own state/logic. Keep inline when: < 10 lines, single use, purely presentational.
129129

130-
Behavior-preserving render-performance idioms — lazy-init object refs, hoist closure-free values/functions to module scope, pre-index repeated lookups with `Map`/`Set`, and immutable array methods (`toSorted`) with the ES2022-vs-ES2023 lib caveat — are in `.claude/rules/sim-react-performance.md`. For the render-timing effect/state anti-patterns use the `/you-might-not-need-*` skills and verify against the running UI.
130+
Behavior-preserving render-performance idioms — lazy-init object refs, hoist closure-free values/functions to module scope, pre-index repeated lookups with `Map`/`Set`, and never mutating a shared array in place — are in `.claude/rules/sim-react-performance.md` (which also explains why `toSorted`/`toReversed` are unsafe on client render paths despite the ES2023 tsconfig lib — SWC does not polyfill prototype methods, so use `[...arr].sort()`). For the render-timing effect/state anti-patterns use the `/you-might-not-need-*` skills and verify against the running UI.
131131

132132
## API Contracts
133133

apps/sim/app/workspace/[workspaceId]/tables/components/import-progress-menu/use-workspace-imports.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,9 @@ export function useWorkspaceImports(
5252
const { data: exportJobs } = useWorkspaceExportJobs(workspaceId)
5353

5454
const prevStatusRef = useRef<Map<string, string> | null>(null)
55-
prevStatusRef.current ??= new Map()
5655
useEffect(() => {
5756
if (!tables) return
58-
const prevStatus = prevStatusRef.current ?? new Map<string, string>()
57+
const prevStatus = (prevStatusRef.current ??= new Map())
5958
const store = useImportTrayStore.getState()
6059
for (const table of tables) {
6160
const before = prevStatus.get(table.id)

0 commit comments

Comments
 (0)