chore(core): remove react-remove-scroll dependency#3373
Conversation
Modal was the only consumer of react-remove-scroll. Replaced it with useBodyScrollLock — a small ref-counted hook that toggles document.body's overflow and pads for the scrollbar to avoid layout jump. Multiple stacked modals share a single lock via the counter. Drops one third-party dep that every MFE consuming @vibe/core re-bundles, since Trident's shared-deps list does not externalize react-remove-scroll. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Code Review by Qodo
1. Unlocks during exit
|
| useBodyScrollLock(show); | ||
|
|
There was a problem hiding this comment.
1. Unlocks during exit 🐞 Bug ≡ Correctness
Modal calls useBodyScrollLock(show), so when show becomes false the hook cleanup restores document.body styles immediately even though the modal stays mounted for the exit animation. This makes the background scrollable while the modal/overlay is still visible during CSSTransition exit.
Agent Prompt
### Issue description
`useBodyScrollLock(show)` unlocks scroll immediately when `show` flips to `false`, but the modal remains mounted during the exit animation (`CSSTransition` + `.containerExitActive`). This creates a window where the modal is still visible while body scroll is already re-enabled.
### Issue Context
The modal uses `CSSTransition` with `timeout.exit` and `unmountOnExit`, and exit animations are defined in SCSS. Scroll lock should remain active until the modal is actually unmounted / exit completes.
### Fix Focus Areas
- packages/core/src/components/Modal/Modal/Modal.tsx[112-196]
- packages/core/src/components/Modal/hooks/useBodyScrollLock/useBodyScrollLock.ts[10-35]
### Implementation sketch
- Introduce a local state like `isScrollLocked`.
- Set `isScrollLocked` to `true` on enter (or when mounting).
- Set `isScrollLocked` to `false` in `CSSTransition`’s `onExited` callback (after exit animation completes).
- Call `useBodyScrollLock(isScrollLocked)` instead of `useBodyScrollLock(show)`.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
|
📦 Bundle Size Analysis Changed Components
Unchanged Components
📊 Summary:
|
User description
Summary
react-remove-scroll. Replaced it with a small internal hook (useBodyScrollLock) that togglesdocument.body'soverflowand pads for the scrollbar to prevent layout jump.Why
@vibe/coreis shipped into every monday MFE that uses Vibe via Trident's shared-dependencies system, butreact-remove-scrollis not in Trident's shared lists (BASE_LIST/EXPANDED_LIST). Every MFE bundle re-includes it. Removing this dependency reduces the per-MFE bundle size and trims one source of dependency-permutation risk.Test plan
🤖 Generated with Claude Code
PR Type
Enhancement
Description
Replace
react-remove-scrollwith internaluseBodyScrollLockhookImplement reference-counted scroll lock for stacked modals
Prevent layout shift by padding body for scrollbar width
Remove third-party dependency from package.json
Diagram Walkthrough
File Walkthrough
useBodyScrollLock.ts
New useBodyScrollLock hook implementationpackages/core/src/components/Modal/hooks/useBodyScrollLock/useBodyScrollLock.ts
overflowandpaddingRightstylesModal.tsx
Replace RemoveScroll with useBodyScrollLock hookpackages/core/src/components/Modal/Modal/Modal.tsx
RemoveScrollcomponent import and wrapperuseBodyScrollLockhook import and callRemoveScrollcomponentpackage.json
Remove react-remove-scroll dependencypackages/core/package.json
react-remove-scrolldependency from dependencies list