question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItĀ collects links to all the places you might be looking at while hunting down a tough bug.

And, if youā€™re still stuck at the end, weā€™re happy to hop on a call to see how we can help out.

Import files to `theme-live-codeblock` scope

See original GitHub issue

šŸ› Bug Report

Import statements in theme-live-codeblock not working. I read the react-live docs and it does look like they do support importing modules - does docusaurus expose the needed scope?

Have you read the Contributing Guidelines on issues?

Yes

To Reproduce

  1. Configure theme-live-codeblock according to these instructions
  2. Install @material-ui/core
  3. Create file.mdx attempt to import components from @material-ui/core
  4. Attempted to import within .mdx file as well as the ``` jsx live block

Expected behavior

Render the imported component

Actual Behavior

  • When the import statement is at the top of .mdx (keep in mind I can use the imported component within the .mdx file just fine, just canā€™t use it within the ```jsx live blockā€¦):

image

  • When the import statement is inside the ```jsx live block:

image

Your Environment

  • Docusaurus version used: 2.0.0-alpha.55
  • Environment name and version (e.g. Chrome 78.0.3904.108, Node.js 10.17.0): Node: v13.12.0, Firefox: 76.0.1
  • Operating system and version (desktop or mobile): Catalina 10.15.4
// from package.json
"dependencies": {
  "@docusaurus/core": "^2.0.0-alpha.55",
  "@docusaurus/preset-classic": "^2.0.0-alpha.55",
  "@docusaurus/theme-live-codeblock": "^2.0.0-alpha.39",
  "@material-ui/core": "^4.10.0",
  "@material-ui/icons": "^4.9.1",
  "classnames": "^2.2.6",
},

Reproducible Demo

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:14 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
oze4commented, May 29, 2020

Yes sir. Thank you!

1reaction
slorbercommented, May 28, 2020

@oze4 Iā€™ve made a PR to support more officially a workflow to provide some components to the react-live scope. Itā€™s not as good as the gatsby integration as I hoped (as you have to configure available scope globally) but I think itā€™s good enough.

Can you tell me if this solves your usecase?

I think it would permit you to swizzle a ā€œsmallerā€ part of the live editor plugin

https://github.com/facebook/docusaurus/pull/2826

Read more comments on GitHub >

github_iconTop Results From Across the Web

Live CodeBlock Theme | hm - GitHub Pages
If you need more imports available, swizzle the react-live scope: npm; Yarn. npm run swizzle @docusaurus/theme-live-codeblock ReactLiveScope.
Read more >
theme-live-codeblock | Docusaurus
This theme provides a @theme/CodeBlock component that is powered by react-live. You can read more on interactive code editor documentation.
Read more >
Live code editing in docusaurus - UX at its best
There is an official plugin to enable live code editing in your website, i.e. @docusaurus/theme-live-codeblock. This theme provides a @theme/Ā ...
Read more >
@docusaurus/theme-live-codeblock - npm
Docusaurus live code block component.. Latest version: 2.2.0, last published: 2 months ago. Start using @docusaurus/theme-live-codeblock inĀ ...
Read more >
1 Code::Blocks Project Management
can be displayed via the menu 'View' ā†’'CodeSnippets' . Here you can manage text modules, links to files and links to urls. Logs...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found