Fix Chromium scrollbar-induced layout shifts
This commit addresses an issue in Chromium on Linux and Windows where the appearance of a vertical scrollbar causes unexpected horizontal layout shifts. This behavior typically occurs when the window is resized, a card is opened or a script is selected, resulting in content being pushed to the left. The solution implemented involves using `scrollbar-gutter: stable` to ensure space is always allocated for the scrollbar, thus preventing any shift in the page layout. This fix primarily affects Chromium-based browsers on Linux and Windows. It has no impact on Firefox on any platform, or any browser on macOS (including Chromium). Because these render the scrollbar as an overlay, and do not suffer from this issue. Steps to reproduce the issue using Chromium browser on Linux/Windows: 1. Open the app with a height large enough where a vertical scrollbar is not visible. 2. Resize the window to a height that triggers a vertical scrollbar. 3. Notice the layout shift as the body content moves to the right. Changes: - Add a CSS mixin to handle scrollbar gutter allocation with a fallback. - Add support for modal dialog background lock to handle `scrollbar-gutter: stable;` in calculations to avoid layout shift when a modal is open. - Add E2E test to avoid regression. - Update DevToolkit to accommodate new scrollbar spacing.
This commit is contained in:
@@ -31,6 +31,7 @@ import { defineComponent, ref } from 'vue';
|
||||
import { injectKey } from '@/presentation/injectionSymbols';
|
||||
import FlatButton from '@/presentation/components/Shared/FlatButton.vue';
|
||||
import { dumpNames } from './DumpNames';
|
||||
import { useScrollbarGutterWidth } from './UseScrollbarGutterWidth';
|
||||
|
||||
export default defineComponent({
|
||||
components: {
|
||||
@@ -39,6 +40,7 @@ export default defineComponent({
|
||||
setup() {
|
||||
const { log } = injectKey((keys) => keys.useLogger);
|
||||
const isOpen = ref(true);
|
||||
const scrollbarGutterWidth = useScrollbarGutterWidth();
|
||||
|
||||
const devActions: readonly DevAction[] = [
|
||||
{
|
||||
@@ -58,6 +60,7 @@ export default defineComponent({
|
||||
devActions,
|
||||
isOpen,
|
||||
close,
|
||||
scrollbarGutterWidth,
|
||||
};
|
||||
},
|
||||
});
|
||||
@@ -71,10 +74,14 @@ interface DevAction {
|
||||
<style scoped lang="scss">
|
||||
@use "@/presentation/assets/styles/main" as *;
|
||||
|
||||
$viewport-edge-offset: $spacing-absolute-large; // close to Chromium gutter width (15px)
|
||||
|
||||
.dev-toolkit-container {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
right: 0;
|
||||
|
||||
top: $viewport-edge-offset;
|
||||
right: max(v-bind(scrollbarGutterWidth), $viewport-edge-offset);
|
||||
|
||||
background-color: rgba($color-on-surface, 0.5);
|
||||
color: $color-on-primary;
|
||||
padding: $spacing-absolute-medium;
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
import {
|
||||
computed, readonly, ref, watch,
|
||||
} from 'vue';
|
||||
import { throttle } from '@/application/Common/Timing/Throttle';
|
||||
import { useAutoUnsubscribedEventListener } from '../Shared/Hooks/UseAutoUnsubscribedEventListener';
|
||||
|
||||
const RESIZE_EVENT_THROTTLE_MS = 200;
|
||||
|
||||
export function useScrollbarGutterWidth() {
|
||||
const scrollbarWidthInPx = ref(getScrollbarGutterWidth());
|
||||
|
||||
const { startListening } = useAutoUnsubscribedEventListener();
|
||||
startListening(window, 'resize', throttle(() => {
|
||||
scrollbarWidthInPx.value = getScrollbarGutterWidth();
|
||||
}, RESIZE_EVENT_THROTTLE_MS));
|
||||
|
||||
const bodyWidth = useBodyWidth();
|
||||
watch(() => bodyWidth.value, () => {
|
||||
scrollbarWidthInPx.value = getScrollbarGutterWidth();
|
||||
}, { immediate: false });
|
||||
|
||||
const scrollbarWidthStyle = computed(() => `${scrollbarWidthInPx.value}px`);
|
||||
return readonly(scrollbarWidthStyle);
|
||||
}
|
||||
|
||||
function getScrollbarGutterWidth(): number {
|
||||
return document.documentElement.clientWidth - document.documentElement.offsetWidth;
|
||||
}
|
||||
|
||||
function useBodyWidth() {
|
||||
const width = ref(document.body.offsetWidth);
|
||||
const observer = new ResizeObserver((entries) => throttle(() => {
|
||||
for (const entry of entries) {
|
||||
width.value = entry.borderBoxSize[0].inlineSize;
|
||||
}
|
||||
}, RESIZE_EVENT_THROTTLE_MS));
|
||||
observer.observe(document.body, { box: 'border-box' });
|
||||
return readonly(width);
|
||||
}
|
||||
Reference in New Issue
Block a user