refactor: remove all three runtime dependencies - #212
Conversation
Closes #118. Supersedes #175. The package now declares no runtime dependencies at all, only a React peer. lodash was three call sites and two functions: - _.pick(o, ['x','y']) became an object literal, twice. - _.isEqual is only ever reached from the two effects that track element positions, and getElemPos always returns { x, y, right, bottom }, including on its null-element branch. So the deep comparison was comparing four numbers. Replaced with an explicit field comparison rather than another dependency: v3 swapped lodash for react-fast-compare, but v2 does not need even that, and a general deep-equal would also have to be careful around the refs and React elements that appear elsewhere in the props. prop-types is dead weight on React 19, which dropped support for it: its dev runtime mentions propTypes zero times, against 19 in React 18. It only ever provided dev-time warnings for JavaScript consumers on React 16.8 to 18, and TypeScript users already get the same checks at compile time. @types/prop-types was declared as a runtime dependency, is never imported in src, and does not appear in the emitted declarations, so every consumer has been installing it for nothing. @types/lodash goes with lodash. react is now the only external, so a script-tag consumer needs nothing else. CI's UMD smoke test supplies only React, which would catch a regression that reintroduced a runtime dependency. Sizes, minified: ESM 22.80 -> 21.47 kB gzip 7.45 -> 7.07 CJS 18.50 -> 16.89 kB gzip 6.43 UMD 18.71 -> 17.06 kB gzip 6.52 That understates it: lodash was external, so consumers were resolving it from their own tree. Behaviour verified rather than assumed. Rendered five prop combinations against the main build and this one and diffed: byte identical. Packed the tarball and loaded ESM, CJS and UMD in a project with neither lodash nor prop-types installed. 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. |
📝 WalkthroughWalkthroughThe PR removes Lodash and PropTypes from runtime code, package dependencies, and UMD configuration. Position comparisons now inspect only relevant coordinates. The CI UMD sandbox provides only React and ChangesRuntime dependency cleanup
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/Xarrow/useXarrowProps.ts`:
- Around line 307-318: Update usePositionEffect to use primitive coordinate
dependencies directly instead of mapping through usePositionMemoize: pass
startPos.x, startPos.y, startPos.right, and startPos.bottom, and apply the
equivalent four dependencies for endPos at each call site. Remove
usePositionMemoize and samePosition once no longer referenced, preserving the
existing useLayoutEffect behavior.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 7864739e-e5e7-4590-a43d-a3e483492f29
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (7)
.github/workflows/ci.ymlpackage.jsonsrc/Xarrow/Xarrow.tsxsrc/Xarrow/propTypes.tssrc/Xarrow/useXarrowProps.tssrc/Xarrow/utils/GetPosition.tsxvite.config.mts
💤 Files with no reviewable changes (3)
- src/Xarrow/propTypes.ts
- package.json
- src/Xarrow/Xarrow.tsx
Closes #118. Supersedes #175.
The package now declares no runtime dependencies at all, only a React peer.
lodash
Three call sites, two functions.
_.pick(o, ["x","y"])became an object literal, twice._.isEqualis the interesting one. It is only ever reached from the two effects that track element positions, andgetElemPosalways returns{ x, y, right, bottom }, including on its null-element branch. So the "deep compare" was comparing four numbers.That killed the obvious plan. v3 (
dev-back-to-life) swapped lodash forreact-fast-compare, and copying that would have replaced one unnecessary dependency with another. An explicit field comparison is exact here, and avoids a general deep-equal having to be careful around the refs and React elements that appear elsewhere in the props.prop-types
Dead weight on React 19, which dropped support for it. Measured rather than assumed:
propTypesin the dev runtimeIt only ever produced dev-time warnings for JavaScript consumers on React 16.8 to 18. TypeScript users already get the same checks at compile time. This is the one change that removes a real capability, small as it is.
@types/prop-types
Declared as a runtime dependency, never imported in
src, and absent from the emitted declarations. Every consumer has been installing it for nothing.@types/lodashgoes with lodash.Sizes
That understates the real win: lodash was external, so consumers were resolving the whole of it from their own tree.
Verification
Behaviour is unchanged. Rendered five prop combinations against the
mainbuild and this one and diffed the markup: byte identical.It actually works without them installed. Packed the tarball into a fresh project with neither lodash nor prop-types present and loaded all three formats: ESM, CJS, and UMD with React as the only global.
reactis now the only external, and CI's UMD smoke test supplies only React, so a regression that reintroduced a runtime dependency would fail there.🤖 Generated with Claude Code
Summary by CodeRabbit
Bug Fixes
Chores