perf(webviews): avoid redundant New Tab motion scans

Merged
TE
19d ago
+6-3

What changed

Avoid redundant layout scans in the cmux-next New Tab list-motion hook. The hook now remeasures only when its row selector or key signature changes, while ResizeObserver continues to rebaseline geometry for resize-only changes. Cleanup restores the observer lifecycle under React StrictMode, cancels stale animations on transient DOM mismatches, and uses a collision-safe key signature.

Verification

  • bun build webviews/src/agent-session/acpmux/newtab/listMotion.ts --outfile /tmp/cmux-listMotion-check2.js --target browser --external react
  • git show --check 207dd96e89c3
  • Independent read-only review of call sites and StrictMode lifecycle

The full React Doctor script is already present in webviews/package.json, but this checkout has no installed webview dependencies, so bun run react-doctor:ci could not start (react-doctor: command not found).


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need.


Summary by cubic

Avoids redundant New Tab layout scans by running the list-motion effect and turn-marker pass only when their inputs change instead of on every render.

  • The list-motion hook remeasures only when the list, row selector, or row keys change; ResizeObserver still handles resize-only rebaselining.
  • Uses JSON.stringify for a collision-safe row key signature and restores ResizeObserver cleanup so StrictMode remounts stay in sync.
  • Cancels in-flight animations on transient DOM mismatches.
  • The turn-marker layout effect runs only when the rows, range, or last turn change; pointer-driven updates still call the callback directly.