Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: mitigate FOUC when applying Prism theme #7373

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

lex111
Copy link
Contributor

@lex111 lex111 commented May 8, 2022

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

This is an attempt to eliminate the flickering background of code blocks when dark mode is on, as well as the duplication of the Prism-related CSS vars. As you can see below, this does not completely fix FOUC, but the result is better than earlier.

Before

ezgif com-gif-maker

After

ezgif com-gif-maker (1)

Test Plan

Preview

Related issues/PRs

@lex111 lex111 added the pr: polish This PR adds a very minor behavior improvement that users will enjoy. label May 8, 2022
@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label May 8, 2022
@netlify
Copy link

netlify bot commented May 8, 2022

[V2]

Name Link
🔨 Latest commit 15fb0da
🔍 Latest deploy log https://app.netlify.com/sites/docusaurus-2/deploys/627fcf9aef9a07000923ba74
😎 Deploy Preview https://deploy-preview-7373--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 site settings.

@github-actions
Copy link

github-actions bot commented May 8, 2022

⚡️ Lighthouse report for the deploy preview of this PR

URL Performance Accessibility Best Practices SEO PWA Report
/ 🟠 64 🟢 100 🟢 100 🟢 100 🟢 90 Report
/docs/installation 🟠 80 🟢 99 🟢 100 🟢 100 🟢 90 Report

@github-actions
Copy link

github-actions bot commented May 8, 2022

Size Change: +157 B (0%)

Total Size: 813 kB

Filename Size Change
website/build/index.html 39.1 kB +157 B (0%)
ℹ️ View Unchanged
Filename Size
website/.docusaurus/globalData.json 52.3 kB
website/build/assets/css/styles.********.css 106 kB
website/build/assets/js/main.********.js 615 kB

compressed-size-action

@Josh-Cena
Copy link
Collaborator

cc @jpdriver since we had been talking about the state of prism-react-renderer in #6246 — Do you think if it's possible that PRR exposed these CSS variables, or even change its theming approach from inline styles to using CSS?

@armano2
Copy link
Contributor

armano2 commented May 9, 2022

this is actually really good news, and I'm glad that you guys are taking steps to address this,
if I understand this correctly, i should be able to replace my custom implementation for editor colors that i did for typescript-eslint/typescript-eslint#4324, is that correct?

@Josh-Cena
Copy link
Collaborator

@armano2 I think your approach is what we should do ultimately (i.e. what I'm talking about in my comment above). Here we are simply extracting the background color, but all token colors will be lost on SSR.

@narinluangrath narinluangrath mentioned this pull request Aug 1, 2022
3 tasks
facebook-github-bot pushed a commit to facebook/yoga that referenced this pull request Dec 19, 2023
Summary:
Pull Request resolved: #1519

See facebook/docusaurus#9629

We use prism to render the code for the inline editor. Prism renders colors to style directly, and the color chosen is dependent on a setting that may not be available at SSR time.

This adds an SSR-specific representation of the code, missing some of the nuances in token colorization (similar to facebook/docusaurus#7373). This adds a little bit of jank compared to perfect SSR, but fixes cases where the mode is incorrect, and is a lot less jank then the more generic solution used by theme-live-codeblock of keeping the rendering of the opposite color until rehydration.

Preview: https://yoga-website-next-git-fork-nickgerleman-exp-2f8171-fbopensource.vercel.app/

Reviewed By: yungsters

Differential Revision: D52163722

fbshipit-source-id: 312dc52134f0084d40f78147190151700ee10ff7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Signed Facebook CLA pr: polish This PR adds a very minor behavior improvement that users will enjoy.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants