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

Change default template for React TS #18

Open
1 task done
ArnaudBarre opened this issue Aug 30, 2023 · 2 comments
Open
1 task done

Change default template for React TS #18

ArnaudBarre opened this issue Aug 30, 2023 · 2 comments

Comments

@ArnaudBarre
Copy link

Describe the bug

The default React template is using CRA instead of Vite.

Link to the blitz that caused the error

https://stackblitz.com/

Steps to reproduce

  • Click on new project
  • Click on React
  • Wait for react-scripts to load

Expected behavior

Use Vite

Parity with Local

Screenshots

No response

Platform

No response

Additional context

No response

@ArnaudBarre
Copy link
Author

ArnaudBarre commented Aug 30, 2023

Just saw the repo name, I though this was more generic feedback tracking!

@Nemikolh Nemikolh transferred this issue from stackblitz/webcontainer-core Sep 4, 2023
@fvsch
Copy link
Contributor

fvsch commented Sep 4, 2023

The default React template is compiled by EngineBlock. It does not use Create React App, nor does it use Vite.

This project's package.json does list react-scripts from CRA in its devDependencies, but these are not used when running on StackBlitz in EngineBlock (which does not install devDependencies). They're meant for use when downloading the project outside of the StackBlitz editor (as a zip archive with the “Download Project” button in the editor, or when pushing that project to a GitHub repo with the classic editor' GitHub integration).

There are two changes we could do here, but I’m not sure which one you're referring to.

Change the devDependencies to use vite instead of react-scripts

I would welcome this change. :)

The difficulties here is that EngineBlock expects specific files to exist in the project (index.html, index.js and style.css), and combines those files into one output. Create React App works similarly. But Vite uses a different convention, and expects an index.html which should reference other resources, for instance:

<!DOCTYPE html>
<html lang="en">
<head>
  <link rel="stylesheet" href="style.css" />
  <script type="module" src="index.ts"></script>
</head>
<body>
  <div id="app"></div>
</body>
</html>

If we changed the index.html of our basic React and React+TypeScript starters, these changes would lead to HTTP requests that EngineBlock is not capable of handing, and errors in DevTools that could be puzzling for end users. It would also incentivize end users to treat those EngineBlock React projects like Vite projects, but they behave differently. That would create confusion (and bug reports ^^).

Switching the basic React starters to WebContainers + Vite

We could also switch our basic React starter templates to WebContainers, and probably use Vite then. Basically we would be making https://vite.new/react and https://vite.new/react-ts our main React starter templates.

There are some downsides to this, currently:

  • UX: for users who want a simple frontend React playground, having a Terminal with output from Vite (or some other tool) taking up space in the editor can be a distraction.
  • Performance: currently EngineBlock projects boot up quicker than WebContainers + Vite.
  • Compatibility: WebContainers do not run perfectly on memory-constrained devices, especially phones and tablets.
  • Compatibility: projects using EngineBlock are much easier to embed in blog posts, docs site, etc.

We might start using WebContainers+Vite more for basic frontend playgrounds in the future, but I doubt we'll do it in 2023.

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

No branches or pull requests

2 participants