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

fix(theme): allow empty code blocks and live playgrounds #9704

Merged
merged 2 commits into from
Jan 5, 2024

Conversation

slorber
Copy link
Collaborator

@slorber slorber commented Jan 5, 2024

Motivation

An empty code block should render as a code block, not an inline code block

An empty code block can be a live playground

Fix #9699

Note: MDX will emit no children prop if the code block is empty or has a single line, which is kind-of surprising but we'll handle it.

CleanShot 2024-01-05 at 13 07 30@2x

Also extracts CodeInline to make it easier to swizzle and customize without ejecting <MDXCode/> (the RN website does that)
(MDX v1 used to have a spacial inlineCode component but it was removed in v2: https://mdxjs.com/migrating/v2/)

Test Plan

dogfood + deploy preview

Test links

https://deploy-preview-9704--docusaurus-2.netlify.app/tests/pages/code-block-tests#empty-code-blocks-edge-cases

@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Jan 5, 2024
@slorber slorber added pr: bug fix This PR fixes a bug in a past release. to backport This PR is planned to be backported to a stable version of Docusaurus labels Jan 5, 2024
Copy link

netlify bot commented Jan 5, 2024

[V2]

Name Link
🔨 Latest commit 19e5dad
🔍 Latest deploy log https://app.netlify.com/sites/docusaurus-2/deploys/6597f5345d374900082ee320
😎 Deploy Preview https://deploy-preview-9704--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 configuration.

@slorber
Copy link
Collaborator Author

slorber commented Jan 5, 2024

@lebalz I understand your intent was likely to create an empty react-live playground (#9699)

However, it seems that react-live does not support well an empty editor (cc @carloskelly13)
Cf the demo on react-live site: https://formidable.com/open-source/react-live/

CleanShot 2024-01-05 at 13 09 41@2x

Not sure what you would expect the empty editor to render, curious to know more about the use case you have in mind.

Copy link

github-actions bot commented Jan 5, 2024

⚡️ Lighthouse report for the deploy preview of this PR

URL Performance Accessibility Best Practices SEO PWA Report
/ 🟢 90 🟢 98 🟢 100 🟢 100 🟠 89 Report
/docs/installation 🟠 69 🟢 98 🟢 100 🟢 100 🟠 89 Report
/docs/category/getting-started 🟠 75 🟢 100 🟢 100 🟢 90 🟠 89 Report
/blog 🟠 73 🟢 100 🟢 100 🟢 90 🟠 89 Report
/blog/preparing-your-site-for-docusaurus-v3 🟠 63 🟢 97 🟢 100 🟢 100 🟠 89 Report
/blog/tags/release 🟠 74 🟢 100 🟢 100 🟠 80 🟠 89 Report
/blog/tags 🟠 76 🟢 100 🟢 100 🟢 90 🟠 89 Report

Copy link

github-actions bot commented Jan 5, 2024

Size Change: 0 B

Total Size: 927 kB

ℹ️ View Unchanged
Filename Size
website/.docusaurus/globalData.json 59.2 kB
website/build/assets/css/styles.********.css 114 kB
website/build/assets/js/main.********.js 716 kB
website/build/index.html 37.9 kB

compressed-size-action

@slorber slorber added the Argos Add this label to run UI visual regression tests. See argos.yml GH action. label Jan 5, 2024
Copy link

argos-ci bot commented Jan 5, 2024

The latest updates on your projects. Learn more about Argos notifications ↗︎

Build Status Details Updated (UTC)
default (Inspect) ✅ No change detected - Jan 5, 2024, 6:56 PM

@slorber slorber merged commit 1650043 into main Jan 5, 2024
33 checks passed
@slorber slorber deleted the slorber/fix-empty-code-block branch January 5, 2024 12:37
slorber added a commit that referenced this pull request Jan 5, 2024
Co-authored-by: Joshua Chen <sidachen2003@gmail.com>
Co-authored-by: sebastienlorber <lorber.sebastien@gmail.com>
Co-authored-by: Sébastien Lorber <slorber@users.noreply.github.com>
Co-authored-by: Ivan Mar (sOkam!) <7308253+heysokam@users.noreply.github.com>
Co-authored-by: c0h1b4 <dwidman@gmail.com>
Co-authored-by: Janessa Garrow <janessa.garrow@gmail.com>
Co-authored-by: ozaki <29860391+OzakIOne@users.noreply.github.com>
Co-authored-by: axmmisaka <6500159+axmmisaka@users.noreply.github.com>
Co-authored-by: Tatsunori Uchino <tats.u@live.jp>
Co-authored-by: Simen Bekkhus <sbekkhus91@gmail.com>
fix(i18n): complete translations for theme-common.json Brazilian Portuguese (pt-BR) (#9477)
fix(content-blog): add baseUrl for author.image_url (#9581)
fix(type-aliases): add `title` prop for imported inline SVG React components (#9612)
fix(utils): Markdown link replacement with <> but no spaces (#9617)
fix(live-codeblock): stabilize react-live transformCode callback, fix editor/preview desync (#9631)
fix(cli): output help when no conventional config + no subcommand (#9648)
fix CI job (#9604)
fix Lint Autofix workflow (#9632)
fix(pwa-plugin): upgrade workbox (#9668)
fix(create-docusaurus): fix init template code blocks, and little improvements (#9696)
fix(theme): allow empty code blocks and live playgrounds (#9704)
@slorber slorber added backported This PR has been backported to a stable version of Docusaurus and removed to backport This PR is planned to be backported to a stable version of Docusaurus labels Jan 5, 2024
@lebalz
Copy link
Contributor

lebalz commented Jan 5, 2024

Thanks @slorber for the fix 😍

Actually i'm using empty codeblocks for an education page where the students can write and execute python code in a similar manner as the live playground (with a custom python codeblock theme...). And i have a playground where the students find empty codeblocks to try stuff as turtle graphics and so on... https://ofi.gbsl.website/playground

During the upgrad to docusaurus v3 this bug popped up and i thought the reported usecase would apply for live codeblocks too, but i didn"t try out the scenario - obviously it does not make sense in that usecase... sorry for that.

slorber added a commit that referenced this pull request Jan 26, 2024
Co-authored-by: Joshua Chen <sidachen2003@gmail.com>
Co-authored-by: Joey Clover <joey@popos.local>
Co-authored-by: reece-white <93522192+reece-white@users.noreply.github.com>
Co-authored-by: Shreesh Nautiyal <114166000+Shreesh09@users.noreply.github.com>
Co-authored-by: Nick Gerleman <nick@nickgerleman.com>
Co-authored-by: Chongyi Zheng <git@zcy.dev>
Co-authored-by: MCR Studio <99176216+mcrstudio@users.noreply.github.com>
Co-authored-by: sebastienlorber <lorber.sebastien@gmail.com>
Co-authored-by: Sébastien Lorber <slorber@users.noreply.github.com>
Co-authored-by: Ivan Mar (sOkam!) <7308253+heysokam@users.noreply.github.com>
Co-authored-by: c0h1b4 <dwidman@gmail.com>
Co-authored-by: Janessa Garrow <janessa.garrow@gmail.com>
Co-authored-by: ozaki <29860391+OzakIOne@users.noreply.github.com>
Co-authored-by: axmmisaka <6500159+axmmisaka@users.noreply.github.com>
Co-authored-by: Tatsunori Uchino <tats.u@live.jp>
Co-authored-by: Simen Bekkhus <sbekkhus91@gmail.com>
Co-authored-by: Sanjaiyan Parthipan <parthipankalayini@gmail.com>
Co-authored-by: Jack Robson <143492403+jack-robson@users.noreply.github.com>
Co-authored-by: dawei-wang <dawei-wang@users.noreply.github.com>
Co-authored-by: eitsupi <50911393+eitsupi@users.noreply.github.com>
fix(create-docusaurus): fix readme docusaurus 2 ref (#9487)
fix(theme): fix firefox CSS :has() support bug (#9530)
fix(theme): docs html sidebar items should always be visible (#9531)
fix: v3 admonitions should support v2 title syntax for nested admonitions (#9535)
fix(theme-classic): fixed wrong cursor on dropdown menu in navbar, when window is small (#9398)
fix(theme): upgrade prism-react-renderer, fix html script and style tag highlighting (#9567)
fix: add v2 retrocompatible support for quoted admonitions (#9570)
fix(i18n): complete translations for theme-common.json Brazilian Portuguese (pt-BR) (#9477)
fix(content-blog): add baseUrl for author.image_url (#9581)
fix(type-aliases): add `title` prop for imported inline SVG React components (#9612)
fix(utils): Markdown link replacement with <> but no spaces (#9617)
fix(live-codeblock): stabilize react-live transformCode callback, fix editor/preview desync (#9631)
fix(cli): output help when no conventional config + no subcommand (#9648)
fix CI job (#9604)
fix Lint Autofix workflow (#9632)
fix(pwa-plugin): upgrade workbox (#9668)
fix(create-docusaurus): fix init template code blocks, and little improvements (#9696)
fix(theme): allow empty code blocks and live playgrounds (#9704)
fix(core): various broken anchor link fixes (#9732)
fix: remove old useless mdx typedefs (#9733)
fix(theme-common): fix missing code block MagicComments style in Visual Basic (.NET) 16 (#9727)
fix(core): conditionally include `hostname` parameter when using… (#9407)
fix(create-docusaurus): fix typo in init template sample docs (#9783)
fix(mdx-loader): allow spaces before `mdx-code-block` info string (#9776)
fix(core): links with target "_blank" should no be checked by the broken link checker (#9788)
fix(core): broken links optimization behaves differently than non-optimized logic (#9791)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Argos Add this label to run UI visual regression tests. See argos.yml GH action. backported This PR has been backported to a stable version of Docusaurus CLA Signed Signed Facebook CLA pr: bug fix This PR fixes a bug in a past release.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Empty Code Block not processed by theme component
3 participants