stackblitz / starters

StackBlitz Starter Project
MIT License
40 stars 18 forks source link

Change default template for React TS #18

Open ArnaudBarre opened 1 year ago

ArnaudBarre commented 1 year ago

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

Expected behavior

Use Vite

Parity with Local

Screenshots

No response

Platform

No response

Additional context

No response

ArnaudBarre commented 1 year ago

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

fvsch commented 1 year ago

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:

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