Fix x-trap.noscroll layout shift conflict with scrollbar-gutter#4512
Fix x-trap.noscroll layout shift conflict with scrollbar-gutter#4512dotfrag wants to merge 1 commit intoalpinejs:mainfrom
Conversation
55909e8 to
4dc5cbe
Compare
|
Initial and unset shouldn't impact "get computed style" since that will find what the actual applied value is, not what an elements literal setting is. |
|
Ah yes that's true! |
|
I would really like this to be merged. I'm using |
As a temporary workaround you can use the patch tool, i.e. |
Thanks, I didn't know this was possible, I've been forking all this time! |
|
Why this fix was not already merged? As a temporary workaround I'm doing this: |
PR Review: #4512 — Fix x-trap.noscroll layout shift conflict with scrollbar-gutterType: Bug fix What's happening (plain English)
The fix: before adding Other approaches considered
The PR's approach (check computed style, skip padding if gutter is active) is the simplest correct solution. Changes Made
Test Results
Code ReviewThe fix at let scrollbarGutter = window.getComputedStyle(document.documentElement).scrollbarGutter
// ... after setting overflow: hidden ...
if (scrollbarGutter && scrollbarGutter !== 'auto') {
return () => {
document.documentElement.style.overflow = overflow
}
}The One minor note: the code style matches Alpine's conventions (no semicolons, SecurityNo security concerns identified. VerdictMerge. This is a clean, surgical bug fix for a real problem affecting users of To merge: you'll want to cherry-pick the contributor's commit and the test commit from Reviewed by Claude |
If
scrollbar-gutteris set to something other than the initial value 'auto' (e.g. 'stable'), do not modify padding-right. See issue #4511.This is my attempt to fix it, hoping it's heading to the right direction. I'm using it in my app and it's working. Feel free to discard/modify as you like.
EDIT: Does not appear to work reliably in all cases. I'm trying to understand why, otherwise I'll close it. Fixed, checking the failed test now.Tested and seems to be working:
scrollbar-gutterundefined =>overflow: hidden; padding-right: 15px;scrollbar-gutterunchanged (defaults to 'auto') =>overflow: hidden; padding-right: 15px;scrollbar-gutter: stable=>overflow: hidden;scrollbar-gutter: stable both-edges=>overflow: hidden;Ready for review.
Caveat: scrollbar-gutter, like many other CSS properties supports the global values inherit/revent/etc... which I'm not accounting for. I believe these are really edge-cases. If you want to check for those, then the if check must be explicit (i.e. check for 'stable' and 'stable both-edges') and the return statements reversed.