Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changeset/webkit-style-recalc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### Changes

- **Less style work on every change** - Linux no longer re-checks a whole-document selector on every DOM change to hide scrollbars behind an open dialog; an attribute on the window root does it instead. Text uses the browser's default rendering mode, which keeps WebKit's fast text path while kerning stays on.
18 changes: 8 additions & 10 deletions src/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -528,12 +528,9 @@ html[data-os="linux"] { --window-radius: 8px; }
grayscale strokes can pick Grayscale in Settings -> Appearance. */
-webkit-font-smoothing: auto;
-moz-osx-font-smoothing: auto;
/* optimizeLegibility: proper kerning + shaping so UI text stays smooth and
crisp at every zoom level (optimizeSpeed skips shaping and looks rough,
especially scaled down). The perf-sensitive data grid opts back into
optimizeSpeed via a scoped rule (.studio-data-table) so large grids don't
pay the shaping cost on every cell. */
text-rendering: optimizeLegibility;
/* auto: lets WebKit/Blink use the fast ASCII text path while font-kerning
and font-feature-settings below still apply kerning cleanly. */
text-rendering: auto;
/* font-synthesis and text-size-adjust omitted: font-synthesis:none can trigger
a WebKit font assertion on Linux startup; text-size-adjust is a no-op on desktop. */
}
Expand Down Expand Up @@ -1819,13 +1816,14 @@ html:not(.dark) .key-well:focus-within { box-shadow: inset 0 0 0 1px var(--ring)

/* Linux (WebKitGTK) can draw a scroll area's scrollbar on its own layer, above
everything, so the sidebar's bar showed through Settings and other dialogs.
While a dialog is open, the scrollbars behind it are hidden; the dialog's
own keep working. */
html[data-os="linux"]:has([role="dialog"][data-state="open"], [role="alertdialog"][data-state="open"])
Driven by `html[data-dialog-open]` (set while a DialogContent is drawn)
instead of a root `:has()` selector, which made WebKitGTK invalidate styles
across the entire DOM on every unrelated mutation. */
html[data-os="linux"][data-dialog-open]
:is(.app-scroll, .overflow-auto, .overflow-y-auto, .overflow-x-auto):not(:is([role="dialog"], [role="alertdialog"]) *) {
scrollbar-width: none;
}
html[data-os="linux"]:has([role="dialog"][data-state="open"], [role="alertdialog"][data-state="open"])
html[data-os="linux"][data-dialog-open]
:is(.app-scroll, .overflow-auto, .overflow-y-auto, .overflow-x-auto):not(:is([role="dialog"], [role="alertdialog"]) *)::-webkit-scrollbar {
display: none;
}
Expand Down
10 changes: 10 additions & 0 deletions src/lib/components/ConnectionModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
import { ScrollArea } from "$lib/components/ui/scroll-area/index.js";
import { Button } from "$lib/components/ui/button/index.js";
import { Dialog as DialogPrimitive } from "bits-ui";
import { beginDialogOpen, endDialogOpen } from "$lib/dialog-open.js";
import ResizeHandle from "./ResizeHandle.svelte";
import { cn } from "$lib/utils.js";
import { IS_MAC, comboTitle } from '$lib/shortcuts.js';
Expand Down Expand Up @@ -3416,6 +3417,14 @@
/* browser/non-Tauri env */
}
}
// Same open-dialog marker as ui/dialog's DialogContent: set while the
// dialog element is drawn, so app.css can hide the scrollbars behind it.
let dialogContentEl = $state(/** @type {HTMLElement | null} */ (null));
$effect(() => {
if (!dialogContentEl) return;
beginDialogOpen();
return () => endDialogOpen();
});
</script>

<!-- ⌘R / Ctrl+R rescans what's running locally while the dialog is open. The
Expand Down Expand Up @@ -3949,6 +3958,7 @@
class="fixed inset-x-0 z-50 bg-black/65 data-open:animate-in data-closed:animate-out data-open:fade-in-0 data-closed:fade-out-0 ease-out duration-150"
/>
<DialogPrimitive.Content
bind:ref={dialogContentEl}
data-connection-modal
style={modalInset}
class="fixed inset-x-0 z-50 flex bg-background text-foreground outline-none data-open:animate-in data-closed:animate-out data-open:fade-in-0 data-closed:fade-out-0 data-open:zoom-in-[0.98] data-closed:zoom-out-[0.98] ease-out duration-200"
Expand Down
10 changes: 10 additions & 0 deletions src/lib/components/ui/dialog/dialog-content.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import { cn } from "$lib/utils.js";
import X from '@lucide/svelte/icons/x';
import { installFocusTracker, getLastExternalFocus } from "$lib/focus-tracker.js";
import { beginDialogOpen, endDialogOpen } from "$lib/dialog-open.js";

let {
ref = $bindable(null),
Expand Down Expand Up @@ -36,6 +37,15 @@
// dialogs (no trigger) would otherwise drop focus to <body>.
installFocusTracker();

// This wrapper mounts with its Dialog.Root, open or not, so the marker
// follows the content element instead: bits-ui sets `ref` while the dialog
// is drawn and back to null when it closes.
$effect(() => {
if (!ref) return;
beginDialogOpen();
return () => endDialogOpen();
});

/** @param {Event} e */
function handleCloseAutoFocus(e) {
// Let an explicit consumer handler run / opt out first.
Expand Down
26 changes: 26 additions & 0 deletions src/lib/dialog-open.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Marks an open modal dialog on <html> as `data-dialog-open`.
//
// app.css hides the scrollbars behind a dialog on Linux. It used to find the
// open dialog with a root `:has([role="dialog"][data-state="open"])`, which
// made WebKitGTK re-check that selector against the whole document on every
// DOM change anywhere in the app. An attribute on <html> costs nothing until
// it flips.

let openDialogs = 0

/** Count a dialog in; DialogContent calls this when it mounts. */
export function beginDialogOpen() {
openDialogs++
if (typeof document !== 'undefined') {
document.documentElement.setAttribute('data-dialog-open', '')
}
}

/** Count a dialog out; the marker goes when the last one unmounts. */
export function endDialogOpen() {
openDialogs = Math.max(0, openDialogs - 1)
if (openDialogs > 0) return
if (typeof document !== 'undefined') {
document.documentElement.removeAttribute('data-dialog-open')
}
}
29 changes: 29 additions & 0 deletions src/lib/dialog-open.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { describe, it, expect, beforeEach } from 'vitest'
import { beginDialogOpen, endDialogOpen } from './dialog-open.js'

describe('dialog-open marker', () => {
/** @type {Set<string>} */
let attrs
beforeEach(() => {
attrs = new Set()
globalThis.document = /** @type {any} */ ({
documentElement: {
setAttribute: (/** @type {string} */ k) => void attrs.add(k),
removeAttribute: (/** @type {string} */ k) => void attrs.delete(k),
},
})
for (let i = 0; i < 4; i++) endDialogOpen()
})

it('stays set until the last nested dialog closes', () => {
beginDialogOpen()
beginDialogOpen()
expect(attrs.has('data-dialog-open')).toBe(true)
endDialogOpen()
expect(attrs.has('data-dialog-open')).toBe(true)
endDialogOpen()
expect(attrs.has('data-dialog-open')).toBe(false)
endDialogOpen()
expect(attrs.has('data-dialog-open')).toBe(false)
})
})
2 changes: 1 addition & 1 deletion src/lib/webkit-has-selectors.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('non-subject :has() selectors', () => {
.replace(/<!--[\s\S]*?-->/g, '')
.replace(/\/\*[\s\S]*?\*\//g, '')
.replace(/^\s*\/\/.*$/gm, '')
for (const re of [/\bgroup-has-[\w[\]>=-]*\//g, /\bhas-\[[^\]\s]*\]\]?:\[&/g, /:has\([^)]*\)\s+[[.\w*]/g]) {
for (const re of [/\bgroup-has-[\w[\]>=-]*\//g, /\bhas-\[[^\]\s]*\]\]?:\[&/g, /:has\([^)]*\)\s+[[.\w*:]/g]) {
for (const m of src.matchAll(re)) bad.push(`${path.relative(root, f)}: ${m[0]}`)
}
}
Expand Down
Loading