[Bug] Declarations directly inside nested @media are dropped from darkreader--sync, overriding the page's values
I maintainer di solito rispondono entro 2 giorni
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 45/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- css
- Ambito
- frontend
Direzione di ricerca
Start from the code that copies style rules into the darkreader--sync sheet and check how it walks CSSNestedDeclarations inside nested @media blocks, which it currently skips. Reproduce with the self-contained HTML in the report, open it in Dynamic mode, and compare the nested and flat margin values. Done means the nested @media declaration is copied, so the nested bar also reads 72px at a 640px+ viewport.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Prerequisites
- I searched for any existing report about this bug to avoid opening a duplicate.
- I can reproduce this bug in a new, unmodified web browser profile with Dark Reader installed as the only extension.
- I understand I need to use the Broken Website Report template if this bug I am reporting occurs on a single website.
Bug Description
In Dynamic mode, Dark Reader copies a style rule into its darkreader--sync sheet (inserted after the original sheet) when the rule contains something it processes, e.g. var(). Declarations placed directly inside a nested @media (CSSOM CSSNestedDeclarations, Chrome 130+) are not copied. Because the copy comes after the original, its top-level declarations override the page's media-specific values. This changes the page layout, not just colors.
:root { --unit: 16px; }
.nested {
--w: 80vw;
--h: calc(1.5 * var(--unit));
@media (min-width: 40rem) {
--w: calc(4.5 * var(--unit));
}
}
Generated darkreader--sync:
.nested { --w: 80vw; --h: calc(1.5 * var(--unit)); }
The @media block is gone, so --w resolves to 80vw at any viewport width. The same rules written flat (@media (min-width: 40rem) { .nested { ... } }) are copied correctly and work.
Related: #14188 (nested CSS not being darkened). This report is about a different symptom: nested declarations are dropped from the copy, which then overrides the page's own values.
Website Address
Self-contained test case (save as an .html file and open it):
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Dark Reader: nested @media declarations</title>
<style>
:root { --unit: 16px; }
.nested {
--w: 80vw;
--h: calc(1.5 * var(--unit));
@media (min-width: 40rem) {
--w: calc(4.5 * var(--unit));
}
}
.flat {
--w: 80vw;
--h: calc(1.5 * var(--unit));
}
@media (min-width: 40rem) {
.flat { --w: calc(4.5 * var(--unit)); }
}
i { display: block; height: var(--h); margin-inline-start: var(--w); background: #2563eb; }
</style>
</head>
<body>
<p>Viewport ≥ 640px: both bars should start 72px from the left.</p>
<p>nested</p>
<div class="nested"><i id="nested"></i></div>
<p>flat</p>
<div class="flat"><i id="flat"></i></div>
<pre id="out"></pre>
<script>
setTimeout(() => {
const m = (id) => getComputedStyle(document.getElementById(id)).marginInlineStart;
document.getElementById('out').textContent = `innerWidth: ${innerWidth}\nnested: ${m('nested')}\nflat: ${m('flat')}`;
}, 1000);
</script>
</body>
</html>
Steps To Reproduce
- Save the test case above as an
.htmlfile and serve it (or open it with file access allowed for Dark Reader). - Use a viewport at least 640px wide.
- Enable Dark Reader in Dynamic mode for the page.
Expected Behavior
Both bars start 72px from the left, as they do with Dark Reader disabled. The page prints nested: 72px, flat: 72px.
Actual Behavior
The nested bar starts at 80vw. The page prints nested: 1491.2px (viewport 1864px) and flat: 72px.
Screenshots
No response
Operating System
macOS 27.0.1
Web Browser name and version
Chrome 155
Dark Reader version
4.9.133
Additional Context
Found via Drupal core's Navigation module, whose CSS has body { --admin-toolbar-sidebar-width: 80vw; @media (min-width: 64rem) { --admin-toolbar-sidebar-width: calc(4.5 * var(--admin-toolbar-rem)); } }. Drupal's admin theme is dark, so Dark Reader removes its styles about 200ms after load. Before that, JavaScript that measures layout on DOMContentLoaded reads the wrong value (80vw) and keeps it, so the admin page content ends up shifted 80vw to the right.
- Lingua principale
- TypeScript
- Stelle
- 22.6k
- Fork
- 2.8k
- Merge medio
- 1g 17h
- PR unite (30g)
- 82
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di darkreader/darkreader
-
Broken Website
Difficoltà 2/5 1-3 ore Idoneità per principianti 64/100
darkreader/darkreader#16259 ·
I maintainer di solito rispondono entro 2 giorni
-
Broken Website
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
darkreader/darkreader#16126 · 1 commento ·
I maintainer di solito rispondono entro 2 giorni
-
Pay to use?Aperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 66/100
darkreader/darkreader#16108 · 7 commenti ·
I maintainer di solito rispondono entro 2 giorni
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
darkreader/darkreader#16100 · 1 commento · 1 reazione ·
I maintainer di solito rispondono entro 2 giorni
-
Broken Website
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
darkreader/darkreader#15999 · 5 commenti ·
I maintainer di solito rispondono entro 2 giorni
Tutte le issue di darkreader/darkreader
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 67/100
knaw-huc/textannoviz#742 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
cloudflare/realtimekit-ui#219 ·
I maintainer di solito rispondono entro 1 giorno
-
ui
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
tui: Mermaid renderer displays <b>/<strong> tags literally and ignores \n line breaksForse già presa @argszero l’ha presa oggi. Apertaarea/tui platform/wsl status/repro-simulated type/bug version/v2
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
anomalyco/opencode#66773 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
mermaid-js/mermaid-v13#1370 ·
I maintainer di solito rispondono entro 1 giorno