-
-
Notifications
You must be signed in to change notification settings - Fork 8.9k
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
chore(live-code): replace with react-runner #6589
Conversation
✅ [V2]Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify site settings. |
⚡️ Lighthouse report for the deploy preview of this PR
|
4b41560
to
b980694
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Behavior looks the same, great👍
Just one doubt: have you checked about bundle size?
@@ -6796,11 +6754,6 @@ core-js-pure@^3.20.2: | |||
resolved "https://registry.yarnpkg.com/core-js-pure/-/core-js-pure-3.21.0.tgz#819adc8dfb808205ce25b51d50591becd615db7e" | |||
integrity sha512-VaJUunCZLnxuDbo1rNOzwbet9E1K9joiXS5+DQMPtgxd24wfsZbJZMMfQLGYMlCUvSxLfsRUUhoOR2x28mFfeg== | |||
|
|||
core-js@^2.4.1: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great! 🎉
@Josh-Cena |
I pushed this PR as a PoC, if you think it's legit, I'll update other related docs, like the notes about |
Yes, that looks great! We can remove the mentions of |
Thanks, that looks like a nice POC and a good improvement over react-live I'm not 100% sure of the potential impacts yet so I'm marking this as a potential breaking change, as we are updating the underlying lib. Some random thoughts:
|
d54c501
to
04b268e
Compare
@slorber It's not a new lib, I created 3 years ago and used in a lot of projects of mine or I worked, I just migrated it to Typescript recently, and itself is tested fully, regarding the maintenance, I'm happy to invite more as admin for this package Regarding Sandpack, yes I noticed you are using it in new React docs website(you will find that the demos there could be copied to react-runner and just work out of box), and that's why I added multi files support recently, and the example is copied from there, I think for small live preview, Regarding React Runner, it's designed to be modular, so you can just use I don't think it's a breaking change as there is no change for user space but more features, and the change is actually smaller then from |
I also think that:
However, @nihgwu the test is failing and it looks related to your component |
@Josh-Cena I think builds are failing because the import config of Docusaurus after I tried to re-export |
04b268e
to
9c7893c
Compare
@@ -229,6 +229,12 @@ export function createBaseConfig( | |||
}), | |||
], | |||
}, | |||
{ | |||
test: /\.m?js$/, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will also fix other issues related to Webpack5 with ES module, here sucrase
uses esm without explicit extension
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should apply this change to docusaurus core instead, it's a very common issue for users upgrading to webpack5, I found NextJS also applied this config
I found it is docusaurus core
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain why we need this, and back this with reference to docs, Next.js prs etc?
it's a very common issue for users upgrading to webpack5
All our users are already on Webpack 5 for a while, and nobody complained 🤷♂️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/vercel/next.js/blob/main/packages/next/build/webpack-config.ts#L1002-L1012
You see I didn't complain as I googled the solution ;p, while I was searching the problem, I found there are more libraries shipped ESM support but don't follow the specification, that you have to specify the extension explicitly when using ESM, which I don't think most of the package author are ready for that
Here the case is that sucrase
(used by react-runner
to transpile code) supports ESM build, but it doesn't use import ... from './Foo.mjs
but `import ... from './Foo' which is not Node ESM compliant, so we have to add this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can find more issues linked here webpack/webpack#11467
And for CRA
facebook/create-react-app#12008
facebook/create-react-app#10356
Motion
motiondivision/motion#1307
SWR
vercel/swr#1617
I guess no one complain here as it's for documentation so user would just use what it provides, and don't import much 3rd party libraries
@@ -6,13 +6,17 @@ | |||
*/ | |||
|
|||
import React from 'react'; | |||
import * as components from './components'; | |||
import {createRequire} from 'react-runner'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or we can just define createRequire
it here, which is super simple
export const createRequire = (imports: Scope) => (module: string): Scope => {
if (!imports.hasOwnProperty(module)) {
throw new Error(`Module not found: '${module}'`)
}
return imports[module]
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a way to encapsulate this complexity so that the user just has to provide a map of components, no extra API needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did that before but discarded it nihgwu/react-runner#65, the idea is to keep the api as simple as possible, with createRequire
you can customise the error message freely, for example you can list all the available imports in the error message
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I exported this utility for convenience, but it's super tiny and and user can create their own version
@@ -6,13 +6,17 @@ | |||
*/ | |||
|
|||
import React from 'react'; | |||
import * as components from './components'; | |||
import {createRequire} from 'react-runner'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another option is ex-exporting it from '@theme-original/CodeBlock`, I tried but got error, seems it only support default export
@@ -339,13 +339,13 @@ function Clock(props) { | |||
|
|||
### Imports {#imports} | |||
|
|||
:::caution react-live and imports | |||
:::info globals and imports |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if we still need this section ;p
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why? this remains true no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I want to emphasise the difference between globals
and imports
, as now you can use import statement, do we still need to use caution
?
4cbd163
to
c78c7ea
Compare
@Josh-Cena @slorber So what's the plan |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, added my comments
@Josh-Cena @slorber So what's the plan
The plan is to ship 2.0 🤪 sorry but I can't make this PR a high priority (as it's not mandatory for landing 2.0) and neither merge it blindly, so this may take a bit more time.
I'd like to get this merged before 2.0 though, and that seems reasonable to get it merged soon considering it looks to work nicely
Note: there are still a few refs to react-live in the docs. I'd rather not mention too much the underlying lib and make it an implementation detail.
@@ -339,13 +339,13 @@ function Clock(props) { | |||
|
|||
### Imports {#imports} | |||
|
|||
:::caution react-live and imports | |||
:::info globals and imports |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why? this remains true no?
website/docs/guides/markdown-features/markdown-features-code-blocks.mdx
Outdated
Show resolved
Hide resolved
website/docs/guides/markdown-features/markdown-features-code-blocks.mdx
Outdated
Show resolved
Hide resolved
@@ -6,13 +6,17 @@ | |||
*/ | |||
|
|||
import React from 'react'; | |||
import * as components from './components'; | |||
import {createRequire} from 'react-runner'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a way to encapsulate this complexity so that the user just has to provide a map of components, no extra API needed?
@@ -229,6 +229,12 @@ export function createBaseConfig( | |||
}), | |||
], | |||
}, | |||
{ | |||
test: /\.m?js$/, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain why we need this, and back this with reference to docs, Next.js prs etc?
it's a very common issue for users upgrading to webpack5
All our users are already on Webpack 5 for a while, and nobody complained 🤷♂️
@slorber Yeah regarding there is no user space change, it would be nice to roll it out to test it in the wild |
601dbad
to
7cc9fab
Compare
014fa12
to
bf8be01
Compare
@nihgwu Checking in again as I probably lost track of this PR, for now, there's absolutely no API change and |
@Josh-Cena Yes, the only change is that I added a |
bf8be01
to
114a381
Compare
114a381
to
74dee21
Compare
Note: React-Live 3.0 is also using Sucrase now https://github.com/FormidableLabs/react-live/releases/tag/v3.0.0 |
@slorber Yes I know(I mentioned that in the description), but I'd say it's not as powerful and flexible as react-runner ;p, BTW |
@Josh-Cena we can't simply change div to span as it should be a block, we can do |
Yeah, I'm also aware of the docusaurus/packages/docusaurus-theme-classic/src/theme/CodeBlock/Line/index.tsx Lines 42 to 54 in 67faa68
|
4432d2f
to
55bb4a8
Compare
3df056d
to
3861ecc
Compare
In #9316 we upgraded both prism-react-renderer and react-live. Thanks for your work, but for now I prefer to close this PR. |
Review link: https://deploy-preview-6589--docusaurus-2.netlify.app/docs/markdown-features/code-blocks/#interactive-code-editor
Motivation
react-runner
(orreact-live-runner
as a compact layer forreact-live
) is very similar toreact-live
but support more features, it usessucrase
instead ofbuble
to transpile code(though I found they switched tosucrase
recently), more flexible and less bugs, better SSR supportComparing with
buble
,sucrase
has smaller bundle size and supports modern language features, and supports Typescript, and the compile speed is super fastSSR support of


react-runner
After
Before
Have you read the Contributing Guidelines on pull requests?
Yes
Test Plan
Related PRs