refactor: depend on the position numbers instead of a memo helper - #213
refactor: depend on the position numbers instead of a memo helper#213Eliav2 wants to merge 1 commit into
Conversation
Review feedback on this PR. usePositionMemoize called useRef from inside dependencies.map(), which is a hook in a callback, and wrote ref.current during render. The pattern predates this PR, but it only existed to work around comparing an object that getElemPos rebuilds every render. Since the comparison was four numbers, the four numbers can be the dependency array. That removes samePosition, usePositionMemoize and usePositionEffect outright, and the effect fires on exactly the same condition as before. Rendered output still byte identical to main across all five cases. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Review or Edit in CodeSandboxOpen the branch in Web Editor • VS Code • Insiders |
✅ Deploy Preview for react-xarrows ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe position comparison helpers were removed. Start and end position updates now use separate ChangesPosition tracking
Estimated code review effort: 2 (Simple) | ~10 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
|
Closing. Behavior is equivalent for all real coordinates, but the change is not worth the risk right now: it swaps === for Object.is on the position deps, which fires one extra render when a coordinate is exactly -0. Keeping the current memo helper. |
Follow-up to #212. This commit was pushed to that branch but landed after it was merged, so it never reached
main.What it fixes
CodeRabbit's review point on #212, which was correct:
useLayoutEffect(callback, dependencies.map(usePositionMemoize))calls a hook inside a.map()callback, and mutates the ref during render.Why the simple version works
The comparison was only ever four numbers, so the four numbers can be the dependency array:
That removes
samePosition,usePositionMemoizeandusePositionEffectoutright rather than relocating theuseRef. The effect fires on exactly the same condition as before. 31 lines deleted, 8 added.History
The hook-in-a-callback predates all of this. The original was
useLayoutEffect(callback, dependencies.map(useDeepCompareMemoize))with a lodashisEqualinside; #212 swapped the equality function and kept the shape. It only existed to work around comparing an object thatgetElemPosrebuilds every render, which stops being a problem once the dependencies are primitives.Verification
Rendered five prop combinations against the
mainbuild and this one and diffed the markup: byte identical. 53 library tests and 2 demo tests pass, type-check clean.🤖 Generated with Claude Code
Summary by CodeRabbit