Repository navigation
Conversation
- Generate Prism theme CSS (vars + token rules) to a file in generatedFilesDir via loadContent() and register it via getClientModules() so it is bundled once in the site CSS, not inlined in every HTML page. - Use BARE_PRISM_THEME in <Highlight> to suppress inline styles on token spans; colors are now applied via [data-theme] CSS selectors. - Remove unused getPrismCssVariables, PrismThemeEntry and related imports from codeBlockUtils and internal.ts. Fixes meta#11566
✅ [V2]Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
That looks like an interesting solution, thanks. The preview seems to work as expected. I'll review this more carefully later |
|
The latest updates on your projects. Learn more about Argos notifications ↗︎
|
|
Although maybe not that problematic, our visual regression tools reported visual diffs on code blocks: https://app.argos-ci.com/meta-open-source/docusaurus/builds/1781/overview For example, you can see that
I would expect this PR to preserve the exact same colors as before, or this means there's a bug somewhere in your logic, that may be more impactful in some cases. |

Pre-flight checklist
Motivation
Fixes #11566
When loading a page in dark mode, code blocks briefly flash with light theme colors before switching to the correct dark colors. This happens because
prism-react-renderer's<Highlight>applies syntax colors as inline styles on every token<span>(e.g.style="color: #e3116c"). Inline styles have higher specificity than any CSS selector, so the[data-theme="dark"]attribute — already set by Docusaurus's blocking inline script before hydration — could not override them.This is a follow-up to #11967, which was closed after review. This PR addresses the two issues raised by @slorber:
<style>tag viainjectHtmlTags(), adding weight to every SSR page even those without code blocks.What changed (AI-assisted)
packages/docusaurus-theme-classic/src/index.tsgeneratePrismCSS(), which produces CSS rules for both themes:--prism-background-color,--prism-color) for the container.[data-theme='light'] .token.<type>and[data-theme='dark'] .token.<type>.loadContent()togeneratedFilesDir/docusaurus-theme-classic/prism-theme.css.getClientModules()so the bundler includes it in the site CSS bundle — loaded once and cached by the browser, not repeated in every HTML page.injectHtmlTags()headTagswith the inline<style>was removed entirely.packages/docusaurus-theme-classic/src/theme/CodeBlock/Content/index.tsxBARE_PRISM_THEME = {plain: {}, styles: []}passed to<Highlight theme={BARE_PRISM_THEME}>. This suppresses all inline styles on token spans while preserving Prism's token class names (e.g.token keyword), which the generated CSS then targets.packages/docusaurus-theme-common/src/utils/codeBlockUtils.tsxandsrc/internal.tsgetPrismCssVariablesand its re-export, as it is no longer used anywhere.PrismThemeEntry,CSSProperties, andPrismThemeimports fromcodeBlockUtils.tsx.Test Plan
Test links
Deploy preview: https://deploy-preview-_____--docusaurus-2.netlify.app/
//then i'll edit this, dw
Related issues/PRs
useColorMode()cannot safely be used with SSR #9629, Need to improve the rendering mechanism of some components #11296