-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Interactive code snippets: first draft of Klipse integration #236
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
Conversation
jsx-in-depth: one klipse snippet
Deploy preview ready! Built with commit 3b5eb3e |
Thank you for submitting this proof of concept PR. 😄 This component seems functionally similar to the interactive
But it also comes at a pretty large cost; the One the one hand, we already load Babel for the examples on the home page, but we only load it if we're actually going to use it. Scoping Klipse to load only for pages that use it would help a bit, but I think the added weight is still too much. This is a cool proof of concept. Thanks again for sharing it! I think it's best to pass on it for now though, for the reasons mentions above. Let's talk more if you have questions or if I'm misunderstood or misrepresented anything in my initial review. 😄 |
Hi @bvaughn ! Thanks for your feedback. More generally, I'd like to better understand your concern: do you think that the user experience is impacted by the time it takes to load and evaluate the script? I've tried to load the page a couple of times on my MacBook pro and I was not able to feel any page freeze or inconsistent UI. Do you have a different user experience? |
Yes, definitely. On the one hand, most people viewing this website are likely developers and so probably have pretty decent hardware. But many are still probably running on machines that are less powerful than your MacBook Pro and maybe in areas with poorer connectivity. A janky loading experience (eg content that shifts and changes after a couple of seconds as the page loads in, and JS parsing that locks the main thread and makes the browser feel unresponsive) is a super frustrating user experience. (Flowtype's REPL is a great example of the latter.) |
What about adding a button that will allow the user to make the code snippets interactive? |
Would it be possible to server-side render the interactive snippets? |
@alexkrolick interesting idea... |
I'm not convinced that there is a lot of added value in showing what JSX compiles to all throughout the docs, so long as we cover it in a few places (like the home page and dedicated sections like "React without JSX". Maybe others feel differently? If so they should weigh in! 😄 |
@bvaughn in some places it is useful to show what JSX compiles to while in other places it is more pertinent to show the result of the rendering. Klipse supports both. The added value of Klipse is that it allows the user to modify the code of the documentation and see how it affects the output. Some kind of "learning by playing" 😄 |
I understand the value of playing with the code and seeing the output. That's why we have the interactive examples on the home page. I think that the majority of our code snippets within the docs wouldn't be runnable though. They're almost always just showing small concepts. That's why I assumed the only functionality we'd actually get to use for them was the JSX-to-plain-JS transform. |
Some parts of the doc contain interesting runnable code snippets. |
Sync with reactjs.org @ 5849f60
Sync with reactjs.org @ 04f3dc5
Let's try to have interactive code snippets inside the reactjs documentation and tutorials.
It will be very helpful for newcomers.
Here is a first draft of an integration of Klipse (as it was suggested in #26) using gatsby-plugin-klipse written by @ahmedelgabri.
It looks like this:
You can see the live version here: Enjoy the interactivity!!
There are a few issues:
~~~klipse-transpile-jsx
instead of<pre><code class="gatsby-code-klipse-transpile-jsx"></code></pre>
, the snippet is embedded in a.gatsby-highlight
that has a black background<
, we have to write<'
which is quite cumnbersome