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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,6 @@ A shared constructable stylesheet sets `scrollbar-width: thin` and a
document and by every shadow root, found through a patched
`Element.prototype.attachShadow` plus mutation observers that catch roots
created before the call or attached inside other roots.

Where the browser lacks `scrollbar-width`, as WebKit before 18.2 does, the sheet
would have no effect, so the call does nothing and patches nothing.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "thin-scrollbars-everywhere",
"version": "0.2.0",
"version": "0.2.1",
"description": "Thin, translucent scrollbars for the document and every shadow root.",
"keywords": [
"scrollbar",
Expand Down
10 changes: 9 additions & 1 deletion src/scrollbars/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,17 @@ function patchRoot(root: Document | ShadowRoot): void {
* later are styled too. Closed shadow roots that already exist at call
* time cannot be reached, so call this as early as possible. An iframe
* is a separate page with its own realm; call this inside it. Calling
* it more than once has no further effect.
* it more than once has no further effect. Does nothing where the
* browser lacks `scrollbar-width`, as WebKit before 18.2 does.
*/
export function applyThinScrollbarsEverywhere(): void {
// The sheet has no effect without `scrollbar-width`, so patching would be
// pure risk: on the WebKit of Safari 16.6 it left Lit's shadow roots
// without their own sheets. Checked here, not at module level, because
// `CSS` does not exist where this module is only imported, such as SSR.
if (!CSS.supports("scrollbar-width", "thin")) {
return;
}
if (installed) {
return;
}
Expand Down
20 changes: 20 additions & 0 deletions tests/unsupported-browser.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* Regression: where the browser lacks `scrollbar-width`, the call patches
* nothing and adopts nothing, so old WebKit keeps its shadow roots intact.
*/

import { expect, it, vi } from "vite-plus/test";

import { applyThinScrollbarsEverywhere } from "#scrollbars";

it("leaves the page alone without scrollbar-width", () => {
const supports = vi.fn().mockReturnValue(false);
vi.stubGlobal("CSS", { supports });

applyThinScrollbarsEverywhere();

expect(supports).toHaveBeenCalledWith("scrollbar-width", "thin");
expect(document.adoptedStyleSheets).toHaveLength(0);
const root = document.createElement("div").attachShadow({ mode: "open" });
expect(root.adoptedStyleSheets).toHaveLength(0);
});
Loading