Repository navigation
fix(COffcanvas): restore body scroll when unmounted while visible - #562
Merged
Merged
Conversation
The effect that locks body scroll had no cleanup, so unmounting an open offcanvas left `overflow: hidden` and the padding compensation on the body with nothing to undo them — the page stayed unscrollable. An SPA route change that tears the tree down while the offcanvas is open is the ordinary way to hit it. CModal next door already does this correctly; the effect now has the same shape, with the lock and release in one if/else and the release repeated in a cleanup. The early `return` in the visible branch is what made a cleanup impossible to add without restructuring: it skipped the return value in exactly the case the cleanup exists for. Test: an offcanvas rendered visible and then unmounted leaves no overflow or padding-right on the body. Verified red beforehand.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
React half of the same defect fixed for vanilla in coreui#1192. The Vue half is in coreui-vue.
What was wrong
The effect that locks body scroll had no cleanup, so unmounting an open offcanvas left
overflow: hiddenand the padding compensation on the body with nothing to undo them. The page stayed unscrollable. A route change that tears the tree down while the offcanvas is open is the ordinary way to reach this.CModalnext door already handles it — its effect ends in a cleanup that removes the same properties. This bringsCOffcanvasto the same shape.Why it could not just be appended
The effect had an early
returnin the visible branch:React takes the effect's return value as the cleanup, so that branch registered none — in exactly the state the cleanup exists for. The lock and release are one
if/elsenow, with the release repeated in the returned cleanup.Test
An offcanvas rendered visible and then unmounted leaves no
overfloworpadding-righton the body. Verified red beforehand. Full suite green — 130 files, 402 tests.Scope
coreui-react-procarries the same file and is currently 0 commits behind, so it gets this through the next free→pro sync. v6 solved it differently: both frameworks moved to a shareduseDialoghook whose unmount effect closes the dialog and clears the lock.