Skip to content

Fix dark mode on built site by bumping browserslist#42471

Open
mdo wants to merge 2 commits into
v6-devfrom
mdo/dark-mode-netlify-preview
Open

Fix dark mode on built site by bumping browserslist#42471
mdo wants to merge 2 commits into
v6-devfrom
mdo/dark-mode-netlify-preview

Conversation

@mdo
Copy link
Copy Markdown
Member

@mdo mdo commented Jun 5, 2026

Problem

data-bs-theme="dark" examples render in light mode on the Netlify preview while working correctly on the dev server (e.g. Dark menus).

Cause

Our color system relies on native CSS light-dark() + color-scheme. The dev server ships the un-minified bootstrap.css (native light-dark(), works), but production ships bootstrap.min.css, minified by Lightning CSS. Because our browserslist floors predated native light-dark() support, Lightning CSS lowered it to a --lightningcss-light / --lightningcss-dark custom-property toggle. That polyfill doesn't honor our data-bs-theme color modes, so dark regions resolve to light.

light-dark() is the binding feature — native support landed in Chrome 123, Safari/iOS 17.5, Firefox 120. Our floors were Chrome 120 and Safari/iOS 15.6, dragging in the polyfill.

Fix

  • Bump browserslist floors to the first versions with native light-dark(): Chrome/Edge 123, Safari/iOS 17.5 (Firefox 121 already covered). Verified against bootstrap.css that this eliminates all old-syntax lowering (no toggles, native nesting kept). Stopping exactly at the feature line — going higher drops users for zero additional CSS savings.
  • exclude: Features.LightDark in css-minify.mjs as a guard so this specific (silent, nasty) breakage can't regress if the floors ever drop again.

dist/ and config.yml SRI hashes are intentionally not committed — Netlify regenerates both via the dist + release-sri build steps.

Testing

Check the Netlify preview once it builds — the dark-mode examples (menus, navbars, etc.) should render dark.

🤖 Generated with Claude Code

…lyfill

Lightning CSS was lowering native light-dark() to a --lightningcss-light/dark
custom-property toggle because our browserslist floors predated native support.
That polyfill breaks data-bs-theme dark mode on the minified (production) CSS,
so dark examples rendered light on Netlify while working in dev.

- Bump browserslist floors to the first versions with native light-dark()
  (Chrome/Edge 123, Safari/iOS 17.5; Firefox 121 already covered)
- Exclude Features.LightDark in css-minify as a guard against regressions
@mdo mdo changed the title Fix dark mode on built site (Lightning CSS light-dark() polyfill) Fix dark mode on built site by bumping browserslist Jun 5, 2026
@mdo
Copy link
Copy Markdown
Member Author

mdo commented Jun 5, 2026

Confirmed finally—this is what's been causing issues on our preview URLs vs local for viewing dark mode. https://deploy-preview-42471--twbs-bootstrap.netlify.app/docs/6.0/components/menu/

@coliff This should fix dark menus, dark navbar, etc. Need to think on the browser support a little more though, but essentially the issue is that LIghtningCSS goes into a prod mode and dumbs down our CSS inadvertently.

@julien-deramond Honestly, I think I'm fine bumping to these versions. It's more aggressive, but hell, iOS 27 is going to come out in a few months—feel like it'd be silly to stay behind too long.

Comment thread .browserslistrc Outdated
Safari >= 15.6
iOS >= 17.5
Safari >= 17.5
not Explorer <= 11
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor thing, but no need to specify 'not Explorer <= 11' anymore since it's excluded by 'not dead'.

@coliff
Copy link
Copy Markdown
Contributor

coliff commented Jun 5, 2026

I approve of the supported browserslist update! Interesting visualisation/details of support here.
https://browserslist.dev/?q=bGFzdCAyIG1ham9yIHZlcnNpb25zLCBub3QgZGVhZCwgQ2hyb21lID49IDEyMywgRWRnZSA%2BPSAxMjMsIEZpcmVmb3ggPj0gMTIxLGlPUyA%2BPSAxNy41LCBTYWZhcmkgPj0gMTcuNSwgbm90IGthaW9zIDw9IDIuNSwgbm90IEV4cGxvcmVyIDw9IDEx

I tested on iPhone 14 with iOS 18 on BrowserStack and didn't spot any browser-related issues... there are problems with iPhone 12 on iOS 17.0 (dropdown menus are transparent), but unfortunately they don't have 17.5 available to test. I tested on a real old iPad Pro 10.5" here with iPadOS 17.7.11 and everything looked good/worked well in light and dark mode.

Removed comment about CSS light-dark polyfill and updated browser support.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants