Skip to content

Commit 3a20bbe

Browse files
amdevzpaskal
authored andcommitted
fix(embed): set color-scheme on iframe to fix Firefox dark mode
Firefox renders a white background in dark mode when color-scheme is 'none' on the iframe. Set color-scheme to match the active theme on both the outer iframe element and the inner document root, so Firefox uses the correct rendering mode from the start and on theme changes.
1 parent 06436ff commit 3a20bbe

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

frontend/apps/remark42/app/embed.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ function createInstance(config: typeof window.remark_config) {
116116

117117
function changeTheme(theme: Theme) {
118118
window.remark_config.theme = theme;
119+
iframe.style.colorScheme = theme;
119120
postMessageToIframe(iframe, { theme });
120121
}
121122

frontend/apps/remark42/app/remark.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,20 @@ async function init(): Promise<void> {
4040

4141
if (data.theme === 'light') {
4242
document.body.classList.remove('dark');
43+
document.documentElement.style.colorScheme = 'light';
4344
}
4445

4546
if (data.theme === 'dark') {
4647
document.body.classList.add('dark');
48+
document.documentElement.style.colorScheme = 'dark';
4749
}
4850
});
4951

5052
if (theme === 'dark') {
5153
document.body.classList.add('dark');
54+
document.documentElement.style.colorScheme = 'dark';
55+
} else {
56+
document.documentElement.style.colorScheme = 'light';
5257
}
5358

5459
boundActions.fetchHiddenUsers();

frontend/apps/remark42/app/utils/create-iframe.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export function createIframe({ __colors__, styles, ...params }: Params) {
2020
padding: 0,
2121
margin: 0,
2222
overflow: 'hidden',
23-
colorScheme: 'none',
23+
colorScheme: params.theme === 'dark' ? 'dark' : params.theme === 'light' ? 'light' : 'light dark',
2424
...styles,
2525
});
2626

0 commit comments

Comments
 (0)