chore(rules): document render-phase ref-seed choice + no-render-in-render caveat#5333
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
PR SummaryLow Risk Overview
Reviewed by Cursor Bugbot for commit 5da3dab. Configure here. |
… + no-render-in-render caveat Two recurring pitfalls surfaced by the /w react-doctor pass, verified against react.dev: - sim-hooks.md: adjusting state on a prop transition uses the React-canonical useState prev-value tracker (NOT a useRef — React forbids reading/writing ref.current during render; the react-hooks 'refs' lint flags it, and useState is concurrent-safe). The tracker's initial value decides mount behavior (sentinel vs current value) — a mis-seed silently drops the mount action. The existing useRef variant is noted as discouraged for new code. - sim-components.md: no-render-in-render is a false positive for a helper called inline (reconciled by position, no remount); extract only when mechanical. Refs: react.dev useState 'Storing information from previous renders'; useRef 'Do not write or read ref.current during rendering'; react-hooks 'refs' lint.
5da3dab to
781fbea
Compare
Summary
/wreact-doctor cleanup, so future coding agents avoid them.sim-hooks.md: theprevXrender-phase idiom now explains that the ref seed decides mount behavior — seed a sentinel (useRef(null)) when the replaced effect did real work on mount, else the mount action is silently dropped (this was a real bug we caught). Also clarifiesuseState→useRefis safe only when the value is never read in render and never a hook dependency.sim-components.md: addsno-render-in-renderto the known react-doctor false positives — a helper called inline is reconciled by position and does not remount, so extracting it is usually churn/risk unless mechanical.Type of Change
Testing
Docs-only. Cross-checked against existing rules for contradictions — deliberately did not add notes already covered (e.g.
toSortedruntime-polyfill,no-barrel-import,rerender-state-only-in-handlers, absolute-import rules), and dropped a proposedtoSorted/libnote that would have been wrong now thatapps/sim/tsconfig.jsonsetslib: ES2023.Checklist