Skip to content

Conversation

nihgwu
Copy link

@nihgwu nihgwu commented Feb 15, 2022

PoC for #4338

Preview

@gaearon It's quite rough but should work already, haven't checked why theme is not applied for CodeMirror but it works here

@github-actions
Copy link

github-actions bot commented Feb 15, 2022

Size Changes

📦 Next.js Bundle Analysis

This analysis was generated by the next.js bundle analysis action 🤖

🎉 Global Bundle Size Decreased

Page Size (compressed)
global 93.03 KB (🟢 -12 B)
Details

The global bundle is the javascript bundle that loads alongside every page. It is in its own category because its impact is much higher - an increase to its size means that every page on your website loads slower, and a decrease means every page loads faster.

Any third party scripts you have added directly to your app using the <script> tag are not accounted for in this analysis

If you want further insight into what is behind the changes, give @next/bundle-analyzer a try!

One Hundred Eighty-five Pages Changed Size

The following pages changed size from the code in this PR compared to its base branch:

Page Size (compressed) First Load
/ 236.85 KB (🔴 +176.12 KB) 329.88 KB
/404 235.96 KB (🔴 +176.12 KB) 328.99 KB
/apis 236.51 KB (🔴 +176.12 KB) 329.54 KB
/apis/reactdom 236.66 KB (🔴 +176.12 KB) 329.69 KB
/apis/render 238.72 KB (🔴 +176.12 KB) 331.75 KB
/apis/usestate 247.53 KB (🔴 +175.98 KB) 340.56 KB
/blog 38.62 KB (🟡 +11 B) 131.65 KB
/blog/2013/06/02/jsfiddle-integration 247.23 KB (🔴 +176.12 KB) 340.26 KB
/blog/2013/06/05/why-react 248.95 KB (🔴 +176.12 KB) 341.99 KB
/blog/2013/06/12/community-roundup 248.66 KB (🔴 +176.12 KB) 341.69 KB
/blog/2013/06/19/community-roundup-2 249.33 KB (🔴 +176.12 KB) 342.36 KB
/blog/2013/06/21/react-v0-3-3 247.38 KB (🔴 +176.12 KB) 340.41 KB
/blog/2013/06/27/community-roundup-3 249.69 KB (🔴 +176.12 KB) 342.72 KB
/blog/2013/07/02/react-v0-4-autobind-by-default 247.99 KB (🔴 +176.12 KB) 341.03 KB
/blog/2013/07/03/community-roundup-4 249.06 KB (🔴 +176.12 KB) 342.09 KB
/blog/2013/07/11/react-v0-4-prop-validation-and-default-values 247.86 KB (🔴 +176.12 KB) 340.9 KB
/blog/2013/07/17/react-v0-4-0 248.58 KB (🔴 +176.12 KB) 341.61 KB
/blog/2013/07/23/community-roundup-5 249.46 KB (🔴 +176.12 KB) 342.49 KB
/blog/2013/07/26/react-v0-4-1 247.34 KB (🔴 +176.12 KB) 340.37 KB
/blog/2013/07/30/use-react-and-jsx-in-ruby-on-rails 247.94 KB (🔴 +176.12 KB) 340.97 KB
/blog/2013/08/05/community-roundup-6 248.75 KB (🔴 +176.12 KB) 341.78 KB
/blog/2013/08/19/use-react-and-jsx-in-python-applications 247.95 KB (🔴 +176.12 KB) 340.99 KB
/blog/2013/08/26/community-roundup-7 248.92 KB (🔴 +176.12 KB) 341.95 KB
/blog/2013/09/24/community-roundup-8 250.35 KB (🔴 +176.12 KB) 343.38 KB
/blog/2013/10/03/community-roundup-9 249.29 KB (🔴 +176.12 KB) 342.32 KB
/blog/2013/10/16/react-v0.5.0 248.97 KB (🔴 +176.12 KB) 342 KB
/blog/2013/10/29/react-v0-5-1 247.33 KB (🔴 +176.12 KB) 340.36 KB
/blog/2013/11/06/community-roundup-10 250.95 KB (🔴 +176.12 KB) 343.98 KB
/blog/2013/11/18/community-roundup-11 250.03 KB (🔴 +176.12 KB) 343.06 KB
/blog/2013/12/18/react-v0.5.2-v0.4.2 247.8 KB (🔴 +176.12 KB) 340.83 KB
/blog/2013/12/19/react-v0.8.0 248.22 KB (🔴 +176.12 KB) 341.25 KB
/blog/2013/12/23/community-roundup-12 249.68 KB (🔴 +176.12 KB) 342.71 KB
/blog/2013/12/30/community-roundup-13 249.46 KB (🔴 +176.12 KB) 342.5 KB
/blog/2014/01/02/react-chrome-developer-tools 247.72 KB (🔴 +176.12 KB) 340.75 KB
/blog/2014/01/06/community-roundup-14 249.06 KB (🔴 +176.12 KB) 342.09 KB
/blog/2014/02/05/community-roundup-15 250.27 KB (🔴 +176.12 KB) 343.31 KB
/blog/2014/02/15/community-roundup-16 249.98 KB (🔴 +176.12 KB) 343.02 KB
/blog/2014/02/16/react-v0.9-rc1 250.39 KB (🔴 +176.12 KB) 343.42 KB
/blog/2014/02/20/react-v0.9 250.84 KB (🔴 +176.12 KB) 343.87 KB
/blog/2014/02/24/community-roundup-17 249.7 KB (🔴 +176.12 KB) 342.73 KB
/blog/2014/03/14/community-roundup-18 250.67 KB (🔴 +176.12 KB) 343.7 KB
/blog/2014/03/19/react-v0.10-rc1 248.97 KB (🔴 +176.12 KB) 342.01 KB
/blog/2014/03/21/react-v0.10 249 KB (🔴 +176.12 KB) 342.03 KB
/blog/2014/03/28/the-road-to-1.0 249.11 KB (🔴 +176.12 KB) 342.14 KB
/blog/2014/04/04/reactnet 247.75 KB (🔴 +176.12 KB) 340.78 KB
/blog/2014/05/06/flux 247.88 KB (🔴 +176.12 KB) 340.91 KB
/blog/2014/05/29/one-year-of-open-source-react 248.1 KB (🔴 +176.12 KB) 341.13 KB
/blog/2014/06/27/community-roundup-19 249.64 KB (🔴 +176.12 KB) 342.68 KB
/blog/2014/07/13/react-v0.11-rc1 250.03 KB (🔴 +176.12 KB) 343.06 KB
/blog/2014/07/17/react-v0.11 251.29 KB (🔴 +176.12 KB) 344.32 KB
/blog/2014/07/25/react-v0.11.1 248.24 KB (🔴 +176.12 KB) 341.27 KB
/blog/2014/07/28/community-roundup-20 249.79 KB (🔴 +176.12 KB) 342.82 KB
/blog/2014/07/30/flux-actions-and-the-dispatcher 249.42 KB (🔴 +176.12 KB) 342.45 KB
/blog/2014/08/03/community-roundup-21 249.46 KB (🔴 +176.12 KB) 342.49 KB
/blog/2014/09/03/introducing-the-jsx-specification 247.46 KB (🔴 +176.12 KB) 340.49 KB
/blog/2014/09/12/community-round-up-22 249.94 KB (🔴 +176.12 KB) 342.97 KB
/blog/2014/09/16/react-v0.11.2 248.23 KB (🔴 +176.12 KB) 341.27 KB
/blog/2014/09/24/testing-flux-applications 251.41 KB (🔴 +176.12 KB) 344.45 KB
/blog/2014/10/14/introducing-react-elements 250.37 KB (🔴 +176.12 KB) 343.4 KB
/blog/2014/10/16/react-v0.12-rc1 250.33 KB (🔴 +176.12 KB) 343.36 KB
/blog/2014/10/17/community-roundup-23 250.91 KB (🔴 +176.12 KB) 343.94 KB
/blog/2014/10/27/react-js-conf 247.51 KB (🔴 +176.12 KB) 340.54 KB
/blog/2014/10/28/react-v0.12 250.27 KB (🔴 +176.12 KB) 343.31 KB
/blog/2014/11/24/react-js-conf-updates 247.89 KB (🔴 +176.12 KB) 340.92 KB
/blog/2014/11/25/community-roundup-24 251.13 KB (🔴 +176.12 KB) 344.17 KB
/blog/2014/12/18/react-v0.12.2 247.92 KB (🔴 +176.12 KB) 340.95 KB
/blog/2014/12/19/react-js-conf-diversity-scholarship 248.32 KB (🔴 +176.12 KB) 341.35 KB
/blog/2015/01/27/react-v0.13.0-beta-1 249.28 KB (🔴 +176.12 KB) 342.32 KB
/blog/2015/02/18/react-conf-roundup-2015 251.27 KB (🔴 +176.12 KB) 344.3 KB
/blog/2015/02/20/introducing-relay-and-graphql 250.42 KB (🔴 +176.12 KB) 343.45 KB
/blog/2015/02/24/react-v0.13-rc1 249.32 KB (🔴 +176.12 KB) 342.35 KB
/blog/2015/02/24/streamlining-react-elements 251.87 KB (🔴 +176.12 KB) 344.91 KB
/blog/2015/03/03/react-v0.13-rc2 248.66 KB (🔴 +176.12 KB) 341.69 KB
/blog/2015/03/04/community-roundup-25 249.62 KB (🔴 +176.12 KB) 342.65 KB
/blog/2015/03/10/react-v0.13 249.94 KB (🔴 +176.12 KB) 342.97 KB
/blog/2015/03/16/react-v0.13.1 247.75 KB (🔴 +176.12 KB) 340.79 KB
/blog/2015/03/19/building-the-facebook-news-feed-with-relay 250.51 KB (🔴 +176.12 KB) 343.55 KB
/blog/2015/03/26/introducing-react-native 247.65 KB (🔴 +176.12 KB) 340.68 KB
/blog/2015/03/30/community-roundup-26 249.58 KB (🔴 +176.12 KB) 342.62 KB
/blog/2015/04/17/react-native-v0.4 248.5 KB (🔴 +176.12 KB) 341.53 KB
/blog/2015/04/18/react-v0.13.2 247.83 KB (🔴 +176.12 KB) 340.87 KB
/blog/2015/05/01/graphql-introduction 252.32 KB (🔴 +176.12 KB) 345.36 KB
/blog/2015/05/08/react-v0.13.3 247.72 KB (🔴 +176.12 KB) 340.76 KB
/blog/2015/05/22/react-native-release-process 247.87 KB (🔴 +176.12 KB) 340.91 KB
/blog/2015/06/12/deprecating-jstransform-and-react-tools 248.32 KB (🔴 +176.12 KB) 341.36 KB
/blog/2015/07/03/react-v0.14-beta-1 249.84 KB (🔴 +176.12 KB) 342.87 KB
/blog/2015/08/03/new-react-devtools-beta 248.44 KB (🔴 +176.12 KB) 341.47 KB
/blog/2015/08/11/relay-technical-preview 248.5 KB (🔴 +176.12 KB) 341.53 KB
/blog/2015/08/13/reacteurope-roundup 250.09 KB (🔴 +176.12 KB) 343.12 KB
/blog/2015/09/02/new-react-developer-tools 247.86 KB (🔴 +176.12 KB) 340.89 KB
/blog/2015/09/10/react-v0.14-rc1 253.54 KB (🔴 +176.12 KB) 346.57 KB
/blog/2015/09/14/community-roundup-27 250.01 KB (🔴 +176.12 KB) 343.05 KB
/blog/2015/10/01/react-render-and-top-level-api 248.99 KB (🔴 +176.12 KB) 342.02 KB
/blog/2015/10/07/react-v0.14 254.03 KB (🔴 +176.12 KB) 347.06 KB
/blog/2015/10/19/reactiflux-is-moving-to-discord 249.74 KB (🔴 +176.12 KB) 342.77 KB
/blog/2015/10/28/react-v0.14.1 247.75 KB (🔴 +176.12 KB) 340.78 KB
/blog/2015/11/02/react-v0.14.2 247.78 KB (🔴 +176.12 KB) 340.81 KB
/blog/2015/11/18/react-v0.14.3 247.9 KB (🔴 +176.12 KB) 340.93 KB
/blog/2015/12/04/react-js-conf-2016-diversity-scholarship 248.77 KB (🔴 +176.12 KB) 341.81 KB
/blog/2015/12/16/ismounted-antipattern 248.37 KB (🔴 +176.12 KB) 341.41 KB
/blog/2015/12/18/react-components-elements-and-instances 252.29 KB (🔴 +176.12 KB) 345.33 KB
/blog/2015/12/29/react-v0.14.4 247.57 KB (🔴 +176.12 KB) 340.6 KB
/blog/2016/01/08/A-implies-B-does-not-imply-B-implies-A 248.58 KB (🔴 +176.12 KB) 341.62 KB
/blog/2016/01/12/discontinuing-ie8-support 247.39 KB (🔴 +176.12 KB) 340.43 KB
/blog/2016/02/19/new-versioning-scheme 248.77 KB (🔴 +176.12 KB) 341.81 KB
/blog/2016/03/07/react-v15-rc1 251.52 KB (🔴 +176.12 KB) 344.56 KB
/blog/2016/03/16/react-v15-rc2 248.39 KB (🔴 +176.12 KB) 341.42 KB
/blog/2016/03/29/react-v0.14.8 247.52 KB (🔴 +176.12 KB) 340.55 KB
/blog/2016/04/07/react-v15 255.71 KB (🔴 +176.12 KB) 348.75 KB
/blog/2016/04/08/react-v15.0.1 248.28 KB (🔴 +176.12 KB) 341.31 KB
/blog/2016/07/11/introducing-reacts-error-code-system 247.99 KB (🔴 +176.12 KB) 341.03 KB
/blog/2016/07/13/mixins-considered-harmful 256.15 KB (🔴 +176.12 KB) 349.18 KB
/blog/2016/07/22/create-apps-with-no-configuration 251.47 KB (🔴 +176.12 KB) 344.51 KB
/blog/2016/08/05/relay-state-of-the-state 251.51 KB (🔴 +176.12 KB) 344.55 KB
/blog/2016/09/28/our-first-50000-stars 252.96 KB (🔴 +176.12 KB) 345.99 KB
/blog/2016/11/16/react-v15.4.0 250.91 KB (🔴 +176.12 KB) 343.95 KB
/blog/2017/04/07/react-v15.5.0 251.48 KB (🔴 +176.12 KB) 344.51 KB
/blog/2017/05/18/whats-new-in-create-react-app 250.87 KB (🔴 +176.12 KB) 343.91 KB
/blog/2017/06/13/react-v15.6.0 249.5 KB (🔴 +176.12 KB) 342.53 KB
/blog/2017/07/26/error-handling-in-react-16 249.84 KB (🔴 +176.12 KB) 342.88 KB
/blog/2017/09/08/dom-attributes-in-react-16 250.27 KB (🔴 +176.12 KB) 343.31 KB
/blog/2017/09/25/react-v15.6.2 248.61 KB (🔴 +176.12 KB) 341.64 KB
/blog/2017/09/26/react-v16.0 253.74 KB (🔴 +176.12 KB) 346.77 KB
/blog/2017/11/28/react-v16.2.0-fragment-support 251.67 KB (🔴 +176.12 KB) 344.71 KB
/blog/2017/12/07/introducing-the-react-rfc-process 248.19 KB (🔴 +176.12 KB) 341.22 KB
/blog/2017/12/15/improving-the-repository-infrastructure 263.98 KB (🔴 +176.12 KB) 357.01 KB
/blog/2018/03/01/sneak-peek-beyond-react-16 248.15 KB (🔴 +176.12 KB) 341.18 KB
/blog/2018/03/27/update-on-async-rendering 253.39 KB (🔴 +176.12 KB) 346.42 KB
/blog/2018/03/29/react-v-16-3 250.21 KB (🔴 +176.12 KB) 343.24 KB
/blog/2018/05/23/react-v-16-4 250.35 KB (🔴 +176.12 KB) 343.38 KB
/blog/2018/06/07/you-probably-dont-need-derived-state 254.01 KB (🔴 +176.12 KB) 347.04 KB
/blog/2018/08/01/react-v-16-4-2 249 KB (🔴 +176.12 KB) 342.04 KB
/blog/2018/09/10/introducing-the-react-profiler 250.61 KB (🔴 +176.12 KB) 343.64 KB
/blog/2018/10/01/create-react-app-v2 251.09 KB (🔴 +176.12 KB) 344.12 KB
/blog/2018/10/23/react-v-16-6 250.29 KB (🔴 +176.12 KB) 343.32 KB
/blog/2018/11/13/react-conf-recap 248 KB (🔴 +176.12 KB) 341.03 KB
/blog/2018/11/27/react-16-roadmap 254.19 KB (🔴 +176.12 KB) 347.23 KB
/blog/2018/12/19/react-v-16-7 249.12 KB (🔴 +176.12 KB) 342.16 KB
/blog/2019/02/06/react-v16.8.0 251.39 KB (🔴 +176.12 KB) 344.42 KB
/blog/2019/02/23/is-react-translated-yet 250.95 KB (🔴 +176.12 KB) 343.99 KB
/blog/2019/08/08/react-v16.9.0 253.89 KB (🔴 +176.12 KB) 346.92 KB
/blog/2019/08/15/new-react-devtools 248.49 KB (🔴 +176.12 KB) 341.53 KB
/blog/2019/10/22/react-release-channels 250.3 KB (🔴 +176.12 KB) 343.33 KB
/blog/2019/11/06/building-great-user-experiences-with-concurrent-mode-and-suspense 255.01 KB (🔴 +176.12 KB) 348.04 KB
/blog/2020/02/26/react-v16.13.0 251.23 KB (🔴 +176.12 KB) 344.26 KB
/blog/2020/08/10/react-v17-rc 257.51 KB (🔴 +176.12 KB) 350.54 KB
/blog/all 54.74 KB (🟡 +11 B) 147.77 KB
/community 236.54 KB (🔴 +176.12 KB) 329.58 KB
/community/acknowledgements 237.74 KB (🔴 +176.12 KB) 330.77 KB
/community/meet-the-team 238.25 KB (🔴 +176.12 KB) 331.29 KB
/learn 241.04 KB (🔴 +176.12 KB) 334.07 KB
/learn/add-react-to-a-website 241.37 KB (🔴 +176.12 KB) 334.4 KB
/learn/adding-interactivity 243.17 KB (🔴 +176.12 KB) 336.21 KB
/learn/choosing-the-state-structure 248.91 KB (🔴 +176.12 KB) 341.94 KB
/learn/conditional-rendering 241.14 KB (🔴 +176.12 KB) 334.17 KB
/learn/describing-the-ui 240.36 KB (🔴 +176.12 KB) 333.39 KB
/learn/editor-setup 237.63 KB (🔴 +176.12 KB) 330.67 KB
/learn/escape-hatches 235.88 KB (🔴 +176.12 KB) 328.91 KB
/learn/extracting-state-logic-into-a-reducer 246.54 KB (🔴 +176.12 KB) 339.58 KB
/learn/importing-and-exporting-components 239.54 KB (🔴 +176.12 KB) 332.58 KB
/learn/installation 237.2 KB (🔴 +176.12 KB) 330.23 KB
/learn/javascript-in-jsx-with-curly-braces 239.62 KB (🔴 +176.12 KB) 332.65 KB
/learn/keeping-components-pure 243.75 KB (🔴 +176.12 KB) 336.78 KB
/learn/managing-state 242.47 KB (🔴 +176.12 KB) 335.51 KB
/learn/manipulating-the-dom-with-refs 244.38 KB (🔴 +176.12 KB) 337.41 KB
/learn/passing-data-deeply-with-context 243.89 KB (🔴 +176.12 KB) 336.92 KB
/learn/passing-props-to-a-component 243.32 KB (🔴 +176.12 KB) 336.35 KB
/learn/preserving-and-resetting-state 246.13 KB (🔴 +176.12 KB) 339.16 KB
/learn/queueing-a-series-of-state-updates 241.11 KB (🔴 +176.12 KB) 334.15 KB
/learn/react-developer-tools 237.07 KB (🔴 +176.12 KB) 330.1 KB
/learn/reacting-to-input-with-state 245.59 KB (🔴 +176.12 KB) 338.62 KB
/learn/referencing-values-with-refs 242.64 KB (🔴 +176.12 KB) 335.67 KB
/learn/render-and-commit 239.61 KB (🔴 +176.12 KB) 332.64 KB
/learn/rendering-lists 243.67 KB (🔴 +176.12 KB) 336.7 KB
/learn/responding-to-events 242.66 KB (🔴 +176.12 KB) 335.69 KB
/learn/scaling-up-with-reducer-and-context 240.68 KB (🔴 +176.12 KB) 333.72 KB
/learn/sharing-state-between-components 241.39 KB (🔴 +176.12 KB) 334.43 KB
/learn/start-a-new-react-project 238.04 KB (🔴 +176.12 KB) 331.07 KB
/learn/state-a-components-memory 246.84 KB (🔴 +176.12 KB) 339.87 KB
/learn/state-as-a-snapshot 240.66 KB (🔴 +176.12 KB) 333.69 KB
/learn/thinking-in-react 242.48 KB (🔴 +176.12 KB) 335.51 KB
/learn/updating-arrays-in-state 244.72 KB (🔴 +176.12 KB) 337.75 KB
/learn/updating-objects-in-state 244.44 KB (🔴 +176.12 KB) 337.47 KB
/learn/writing-markup-with-jsx 239.54 KB (🔴 +176.12 KB) 332.58 KB
/learn/your-first-component 240.45 KB (🔴 +176.12 KB) 333.48 KB
Details

Only the gzipped size is provided here based on an expert tip.

First Load is the size of the global bundle plus the bundle for the individual page. If a user were to show up to your website and land on a given page, the first load size represents the amount of javascript that user would need to download. If next/link is used, subsequent page loads would only need to download that page's bundle (the number in the "Size" column), since the global bundle has already been downloaded.

Any third party scripts you have added directly to your app using the <script> tag are not accounted for in this analysis

Next to the size is how much the size has increased or decreased compared with the base branch of this PR. If this percentage has increased by 10% or more, there will be a red status indicator applied, indicating that special attention should be given to this.

@gaearon
Copy link
Member

gaearon commented Feb 15, 2022

I think this looks very promising. How much work is it to get this styled so that the editor works and we can compare 1:1? I see some sandboxes on https://beta-reactjs-org-n2pucbumf-fbopensource.vercel.app/learn/updating-objects-in-state are a bit borked.

@@ -0,0 +1,117 @@
import React, {useState, useMemo} from 'react';
import {Runner, importCode, Scope} from 'react-runner';
import * as UseImmer from 'use-immer';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not super great that we have to load everything we use in every sandbox. We might want to have "heavier" examples in the future with third party libs. They shouldn't bloat the initial editor. I guess having a list of them here is probably fine though. Maybe as dynamic imports and somehow lazy-loaded?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes lazy loading should definitely work, and we can still keep the package.json file and analyse the dependency, right now I just ignored that file

@nihgwu
Copy link
Author

nihgwu commented Feb 15, 2022

@gaearon There are some visual regressions, as previously we target the to root document but now we use a shadow DOM instead, I think it should be super easy to fix, if we decided to make the switch

@gaearon
Copy link
Member

gaearon commented Feb 15, 2022

I don't think we can decide whether to make a switch until we have a good idea of how it works end-to-end, including all the styling, having the code highlighting hooked up, etc. I know it's a bunch of work but it's hard to compare otherwise.

@nihgwu
Copy link
Author

nihgwu commented Feb 15, 2022

@gaearon I totally understand, I'll try to fix the styling issues first, it works well in my demo though, and the benefit is obvious, the demo is part of our app, so it's super fast, and can reflect user's input with no delay, no bundling, only compiling the JSX syntax

@nihgwu
Copy link
Author

nihgwu commented Feb 16, 2022

@gaearon tweaked the styling a bit, though there are still a lot of work to do

@gaearon
Copy link
Member

gaearon commented Feb 16, 2022

A few quick thoughts.

Overall approach

I think it's pretty clear this is the right direction for the tradeoffs we have today. I was hoping we can introduce a mode like this to Sandpack in longer term. The instant feedback is hard to beat. The network waterfalls and other inefficiencies in Sandpack today are unfortunate because our use case is very limited. I think it's plausible the Sandpack package will evolve to support this model as opt-in. I'd like to hear more from their perspective and I'm not saying we should necessarily switch packages to yours. But it seems clear an approach like this is promising, whether through this package or something else.

Production vs Development

One thing that seems unfortunate with this approach is that errors are minified.
E.g. try adding {{}} into some JSX. You'll get:

Minified React error #31; visit https://reactjs.org/docs/error-decoder.html?invariant=31&args[]=object%20with%20keys%20%7B%7D for the full message or use the non-minified dev environment for full errors and additional helpful warnings.

But since we're on the docs site, it seems confusing. It also means we'd miss console.errors. (I don't think Sandpack currently displays them, but ideally, I think we'd like to do that for key warning etc.)

One option would be to make the docs site use a development build of React. Seems bad.

Another option would be to load development build of React, but just for sandboxes. Seems okay-ish. Though also feels a bit silly if we just want to render a few examples. I'm not sure about the best approach.

There could be some middle ground. Like use prod build until dev builds loads lazily. Though might be confusing if a sandbox has an error initially.

Fast Refresh

It's not great that sandboxes lose state on edits. Sandpack implements a simple Fast Refresh integration to avoid that. I think you can't do this very easily because you don't have Babel though and can't run the Fast Refresh transform. Maybe some simplified version could be written. It's thorny with multi-file edits though.

Maybe it's ok that it doesn't work. But feels like a regression.

Server Components

We'll likely have some movement towards server-driven examples in the future. Like showcasing Server Components. That may require a Node.js environment (like the emulation StackBlitz is doing). But that's really heavy. Alternatively, it may be approximated with a Worker environment. We were thinking this would be the likely "local debugging" story for Server Components anyway. From this perspective, Sandpack might already have some infrastructure that would be easier to reuse than to build. But I don't know about this. It's just something else to keep in mind.

Third Party Libs/Transforms

It's plausible we'd want to show some other third party libraries. Or something that requires transforms. E.g. if we ever have an official CSS-in-JS solution. Then if it's on top of Babel, we need some way to run it. So I wonder how avoidable Babel is in long term anyway.

@nihgwu
Copy link
Author

nihgwu commented Feb 16, 2022

@gaearon Thanks for your thorough feedbacks, here are my rough answers:

Production vs Development

One possible solution is map error message back to decoded one, since the data will be stored in the same app, I think it should not be that hard

Fast Refresh

I haven't tested yet but the transpiler React Runner uses is sucrase, which supports react-hot-loader, not sure if that would work in this case, but again I think that's not a big problem as we can also use Babel to compile the code, then we can use the plugin ecosystem of Babel. The only reason I chose sucrase is the much smaller bundle size, but if we want provide more versatile functionalists, we can use Babel in this case and lazy load it in a worker like some other solutions do

Server Components

This website it built with Next.js which also supports Server Components, probably we can just use it? Or for this case we can just other solutions like Sandpack or CodeSandbox or StackBlitz, we are not bonded to use only one tool for all scenarios

Third Party Libs/Transforms

If we do need babel plugins, we can use Babel as the transplier instead of sucrase, BTW it's works well with styled-components and emotion without any babel plugins

I think it's plausible the Sandpack package will evolve to support this model as opt-in

I'm not sure about that, as we have totally different direction, Sandpack is framework agnostic, and provides a full dev environment, while React Runner is designed for React only, it's super lightweight and fast, and it will be integrated to your app as a part of it, so it's perfect if you only want to demo your own components, React Docs is a bit complicated here as we also want some dev environment experience

BTW I also made some improvements on the editor comparing to Sandpack's editor(we both use CodeMirror6), e.g. your editing history will be kept on switching files, I only spent some spare time on that, I believe with wider adoption we can make it better together.

@BartoszKlonowski
Copy link
Collaborator

Closing as per comment in the issue, but thank you very much, @nihgwu for taking the time to contribute! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants