Skip to content

Commit 25145fc

Browse files
committed
refactor(scrollbar): 移除自定义滚动条探测逻辑
1 parent 7300a36 commit 25145fc

2 files changed

Lines changed: 8 additions & 107 deletions

File tree

src/index.css

Lines changed: 8 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -78,22 +78,13 @@ b, strong, th,
7878
font-weight: calc(var(--font-weight, 400) + 200) !important;
7979
}
8080

81-
/*
82-
* Scrollbar styling — two tiers:
83-
*
84-
* 1. Standard properties (scrollbar-width, scrollbar-color) always apply.
85-
* These provide the baseline thin, semi-transparent scrollbar on all
86-
* platforms (Safari 17.4+, Firefox, Chrome 121+).
87-
*
88-
* 2. ::-webkit-scrollbar pseudo-elements are gated behind the
89-
* .webkit-scrollbar-ok class on <html>. A runtime probe in main.tsx
90-
* adds this class only when WebKit custom scrollbar rendering actually
91-
* works. When active, ::-webkit-scrollbar disables the standard
92-
* properties (browser behaviour), giving us border-radius, transitions,
93-
* and finer control.
94-
*/
95-
96-
/* ── Tier 1: Standard scrollbar properties (always active) ────────── */
81+
/* Scrollbar styling — standard properties only (scrollbar-width, scrollbar-color).
82+
* Works consistently across Safari 17.4+, Firefox 64+, Chrome 121+.
83+
* We intentionally avoid ::-webkit-scrollbar pseudo-elements: on macOS,
84+
* matching them activates WebKit's "custom scrollbar" mode which DISABLES
85+
* standard scrollbar-color. If the custom renderer is buggy (e.g. WKWebView
86+
* linked against an older SDK), neither path produces correct output. */
87+
9788
* {
9889
scrollbar-width: thin;
9990
scrollbar-color: transparent transparent;
@@ -105,36 +96,7 @@ html[data-theme="dark"] *:hover {
10596
scrollbar-color: rgba(255, 255, 255, 0.08) transparent;
10697
}
10798

108-
/* ── Tier 2: WebKit custom scrollbar (only when probe succeeds) ───── */
109-
.webkit-scrollbar-ok ::-webkit-scrollbar {
110-
width: 5px !important;
111-
height: 5px !important;
112-
}
113-
.webkit-scrollbar-ok ::-webkit-scrollbar-track {
114-
background: transparent !important;
115-
}
116-
.webkit-scrollbar-ok ::-webkit-scrollbar-thumb {
117-
background: transparent !important;
118-
border-radius: 3px !important;
119-
transition: background 0.3s ease;
120-
}
121-
.webkit-scrollbar-ok ::-webkit-scrollbar-corner {
122-
background: transparent !important;
123-
}
124-
.webkit-scrollbar-ok :hover::-webkit-scrollbar-thumb {
125-
background: rgba(0, 0, 0, 0.08) !important;
126-
}
127-
.webkit-scrollbar-ok :hover::-webkit-scrollbar-thumb:hover {
128-
background: rgba(0, 0, 0, 0.18) !important;
129-
}
130-
html[data-theme="dark"].webkit-scrollbar-ok :hover::-webkit-scrollbar-thumb {
131-
background: rgba(255, 255, 255, 0.08) !important;
132-
}
133-
html[data-theme="dark"].webkit-scrollbar-ok :hover::-webkit-scrollbar-thumb:hover {
134-
background: rgba(255, 255, 255, 0.18) !important;
135-
}
136-
137-
/* ── Override antd Bubble.List scrollbar ──────────────────────────── */
99+
/* Override antd Bubble.List scrollbar — it sets its own CSS-in-JS styles */
138100
.ant-bubble-list-scroll-box {
139101
scrollbar-color: transparent transparent !important;
140102
}
@@ -144,25 +106,6 @@ html[data-theme="dark"].webkit-scrollbar-ok :hover::-webkit-scrollbar-thumb:hove
144106
html[data-theme="dark"] .ant-bubble-list-scroll-box:hover {
145107
scrollbar-color: rgba(255, 255, 255, 0.08) transparent !important;
146108
}
147-
.webkit-scrollbar-ok .ant-bubble-list-scroll-box::-webkit-scrollbar {
148-
width: 5px !important;
149-
}
150-
.webkit-scrollbar-ok .ant-bubble-list-scroll-box::-webkit-scrollbar-thumb {
151-
background-color: transparent !important;
152-
border-radius: 3px !important;
153-
}
154-
.webkit-scrollbar-ok .ant-bubble-list-scroll-box:hover::-webkit-scrollbar-thumb {
155-
background-color: rgba(0, 0, 0, 0.08) !important;
156-
}
157-
.webkit-scrollbar-ok .ant-bubble-list-scroll-box:hover::-webkit-scrollbar-thumb:hover {
158-
background-color: rgba(0, 0, 0, 0.18) !important;
159-
}
160-
html[data-theme="dark"].webkit-scrollbar-ok .ant-bubble-list-scroll-box:hover::-webkit-scrollbar-thumb {
161-
background-color: rgba(255, 255, 255, 0.08) !important;
162-
}
163-
html[data-theme="dark"].webkit-scrollbar-ok .ant-bubble-list-scroll-box:hover::-webkit-scrollbar-thumb:hover {
164-
background-color: rgba(255, 255, 255, 0.18) !important;
165-
}
166109

167110
/* Custom action item hover style (for actionRender items in @ant-design/x Actions) */
168111
.aqbot-action-item {

src/main.tsx

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -3,48 +3,6 @@ import ReactDOM from 'react-dom/client';
33
import AppRoot from './App';
44
import './index.css';
55

6-
// Probe whether ::-webkit-scrollbar custom rendering actually works.
7-
// On macOS, WKWebView compiled against older SDKs may recognise the pseudo-
8-
// element (blocking standard scrollbar-color) without rendering it correctly,
9-
// producing a solid-black native scrollbar. The probe creates an off-screen
10-
// scrollable div, applies a custom scrollbar width via a scoped stylesheet,
11-
// and checks whether the layout width changes. If it does, the custom
12-
// scrollbar pipeline is functional and we enable the ::-webkit-scrollbar rules
13-
// in index.css by adding the `webkit-scrollbar-ok` class to <html>.
14-
(() => {
15-
const outer = document.createElement('div');
16-
Object.assign(outer.style, {
17-
position: 'fixed',
18-
top: '-9999px',
19-
left: '-9999px',
20-
width: '100px',
21-
height: '100px',
22-
overflow: 'scroll',
23-
visibility: 'hidden',
24-
});
25-
const inner = document.createElement('div');
26-
inner.style.height = '200px';
27-
outer.appendChild(inner);
28-
document.documentElement.appendChild(outer);
29-
30-
const defaultWidth = outer.offsetWidth - outer.clientWidth;
31-
32-
const style = document.createElement('style');
33-
style.textContent = '#__scrollbar_probe::-webkit-scrollbar { width: 1px !important; }';
34-
document.head.appendChild(style);
35-
outer.id = '__scrollbar_probe';
36-
// Force re-layout after stylesheet injection
37-
void outer.offsetWidth;
38-
const customWidth = outer.offsetWidth - outer.clientWidth;
39-
40-
outer.remove();
41-
style.remove();
42-
43-
if (customWidth !== defaultWidth) {
44-
document.documentElement.classList.add('webkit-scrollbar-ok');
45-
}
46-
})();
47-
486
// Disable native context menu (reload, inspect element, etc.) in production builds.
497
// Custom context menus (antd Dropdown with trigger={['contextMenu']}) are unaffected
508
// since they use React synthetic events, not the browser's native context menu.

0 commit comments

Comments
 (0)