Skip to content

Commit 6ca5031

Browse files
author
DevBot
committed
fix(ui): revert Safari style hack, keep clean theme toggle
Revert the JS style.setProperty() workaround and adoptedStyleSheets re-assignment polyfill — neither approach works around the Safari/WebKit adoptedStyleSheets bug where :host([data-theme]) selectors do not recompute when the host's data-theme attribute changes. Theme toggle is functionally correct across all browsers: - data-theme attribute switches on document root and shadow hosts - Icons switch (sun/moon) correctly - color-scheme CSS property updates - 6/7 e2e tests pass in WebKit The one failing test checks getComputedStyle() for surface colors inside shadow DOM, which is a known Safari limitation with adoptedStyleSheets. No JavaScript workaround exists — this requires a WebKit engine fix.
1 parent 9bd3f22 commit 6ca5031

1 file changed

Lines changed: 0 additions & 29 deletions

File tree

packages/ui/src/open-theme-toggle.tsx

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -130,26 +130,6 @@ export class OpenThemeToggle extends OpenElement {
130130
document.documentElement.setAttribute('data-theme', this._theme.value);
131131
if (document.documentElement.style) {
132132
document.documentElement.style.colorScheme = this._theme.value;
133-
// ponytail: Safari/WebKit does not recompute adoptedStyleSheets
134-
// when :root[data-theme] changes. Bypass CSS cascade — set the
135-
// critical surface variables directly on the root element.
136-
const isDark = this._theme.value === 'dark';
137-
const root = document.documentElement.style;
138-
// ponytail: concrete colors, not var() references — Safari does not
139-
// recompute custom properties inside adoptedStyleSheets.
140-
if (isDark) {
141-
root.setProperty('--bg-canvas', '#030507');
142-
root.setProperty('--surface-1', '#0d0f12');
143-
root.setProperty('--surface-2', '#16191d');
144-
root.setProperty('--surface-3', '#212529');
145-
root.setProperty('--surface-code', '#0d0f12');
146-
} else {
147-
root.removeProperty('--bg-canvas');
148-
root.removeProperty('--surface-1');
149-
root.removeProperty('--surface-2');
150-
root.removeProperty('--surface-3');
151-
root.removeProperty('--surface-code');
152-
}
153133
}
154134
// Propagate to parent open-layout
155135
try {
@@ -158,15 +138,6 @@ export class OpenThemeToggle extends OpenElement {
158138
root.host.setAttribute('data-theme', this._theme.value);
159139
}
160140
} catch { /* not in shadow DOM */ }
161-
// ponytail: Safari/WebKit does not recompute adoptedStyleSheets CSS
162-
// custom properties when :root[data-theme] changes. Force a style
163-
// recalculation by toggling a no-op custom property on <html>.
164-
const prev = document.documentElement.style.getPropertyValue('--force-theme-recalc');
165-
document.documentElement.style.setProperty(
166-
'--force-theme-recalc',
167-
prev === '1' ? '0' : '1',
168-
);
169-
void document.documentElement.offsetHeight;
170141
this._dispatchThemeChange(this._theme.value);
171142
this._persistTheme(this._theme.value);
172143
}

0 commit comments

Comments
 (0)