framework icon indicating copy to clipboard operation
framework copied to clipboard

Changing the page theme doesn’t update dark during preview

Open mbostock opened this issue 1 year ago • 2 comments
trafficstars

E.g., editing the front matter from

---
theme: dark
---

to

---
theme: light
---

doesn’t change the value of dark until reload.

mbostock avatar May 14 '24 15:05 mbostock

True! There was this todo comment in #1018:

// TODO: in preview, also watch for changes in the theme meta.

Fil avatar May 14 '24 16:05 Fil

This is a bit tricky to do because:

  • Any stylesheet could, in theory, change the computed value of color-scheme.
  • The color-scheme could even be defined dynamically!
  • When the theme changes, new stylesheets are loaded asynchronously.
  • When a LINK element’s href attribute is changed, it does not emit a load event.

It would be possible to detect when the (Framework-specified) stylesheet changes, and force the replacement of LINK elements rather than updating the href attribute, and then listen for load events on the added stylesheets (and check the removed ones), and finally re-evaluate the dark built-in. But it’s a bit of work, and still imperfect. Maybe this is just an acceptable bug as-is.

mbostock avatar Jun 12 '24 16:06 mbostock