Skip to content

fix: prevent code blocks flash in dark mode (AI-assisted)#11967

Open
titojuanc wants to merge 1 commit intofacebook:mainfrom
titojuanc:main
Open

fix: prevent code blocks flash in dark mode (AI-assisted)#11967
titojuanc wants to merge 1 commit intofacebook:mainfrom
titojuanc:main

Conversation

@titojuanc
Copy link
Copy Markdown

@titojuanc titojuanc commented Apr 27, 2026

Pre-flight checklist

  • I have read the Contributing Guidelines on pull requests.
  • If this is a code change: I have written unit tests and/or added dogfooding pages to fully verify the new behavior.
  • If this is a new API or substantial change: the PR has an accompanying issue (closes #0000) and the maintainers have approved on my working plan.

Motivation

Fixes #11566

When loading a Docusaurus page in dark mode, code blocks briefly flash with light theme colors before switching to the correct dark theme. This happens because Prism theme colors were applied as inline styles via JavaScript, which only take effect after React hydration.

This PR injects CSS variables for both light and dark Prism themes directly in a <style> tag in the , leveraging the [data-theme] attribute that is already set by a blocking script. This ensures code blocks display with the correct background color from the very first paint, without waiting for hydration.

Test Plan

  1. Configure a site with different light/dark Prism themes (e.g., oneLight / oneDark)
  2. Switch to dark mode
  3. Hard-reload any page with code blocks
  4. Observe that code blocks no longer flash with light theme colors
    (AI-assisted)

Test links

Related issues/PRs

Closes #11566

@meta-cla
Copy link
Copy Markdown

meta-cla Bot commented Apr 27, 2026

Hi @titojuanc!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@netlify
Copy link
Copy Markdown

netlify Bot commented Apr 27, 2026

[V2]

Built without sensitive environment variables

Name Link
🔨 Latest commit f51b830
🔍 Latest deploy log https://app.netlify.com/projects/docusaurus-2/deploys/69ef4d64103558000809378b
😎 Deploy Preview https://deploy-preview-11967--docusaurus-2.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@meta-cla meta-cla Bot added the CLA Signed Signed Facebook CLA label Apr 27, 2026
@meta-cla
Copy link
Copy Markdown

meta-cla Bot commented Apr 27, 2026

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed Signed Facebook CLA

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Code blocks flashes in dark mode

1 participant