r/reactjs • • Mar 16 '23

Introducing react.dev: the new React docs site!

https://react.dev/blog/2023/03/16/introducing-react-dev
566 Upvotes

74 comments sorted by

View all comments

12

u/neg_ersson Mar 17 '23

It really is strange how they barely acknowledge Vite at the bottom of a hidden collapsible. Someone who wants to build something like Figma or Photoshop (i.e. a "true" SPA) will now be recommended to start with Next or Remix, which is kind of backwards imo.

As your data fetching needs get more complex, you are likely to encounter server-client network waterfalls that make your app feel very slow. As your audience includes more users with poor network conditions and low-end devices, you might need to generate HTML from your components to display content early—either on the server, or during the build time. Changing your setup to run some of your code on the server or during the build can be very tricky.

I swear we've all been collectively duped in to thinking that every app built with React is SEO critical and used by mountain people on poor 3G connections. When did this shift happen? So many apps can afford to be rendered by the client and cached in the browser.

Next and Remix are great but they're not the hammer for every nail.

2

u/gaearon React core team Mar 17 '23

Vite is not barely acknowledged — it's the primary way we recommend to use React for a part of your page. For new projects, we recommend more integrated solutions.

Someone who wants to build something like Figma or Photoshop (i.e. a "true" SPA) will now be recommended to start with Next or Remix, which is kind of backwards imo.

Why is it backwards? You use client rendering for the client part, and you use static generation for your marketing landing page. Next.js is a hybrid framework, it can produce a regular SPA just fine. But you're not locked out of other options when you need them.

3

u/neg_ersson Mar 18 '23 edited Mar 18 '23

No, it can't create a fully client side SPA (a single document app) without having to ship a Node server with your app. Unless you use something like next-export which generates a bunch of HTML files at build time and is not the same thing as a SPA (one HTML file).

2

u/Wooden_Progress2104 Mar 20 '23

Next is doing exactly what you are asking it to do. next-export implies that you don't want to use Next Router. So if you write multiple page files in the /pages directory, Next gives you multiple pages, exactly as you instructed. If you want to connect those pages together, you write your own router lah, because you explicitly said that you don't want Next Router.

If you want one page SPA, you make only one file in the pages directory, and write your app exactly like in vite (that one page has only the App component and the router, e.g. react-router that links to other page components from the /components directory). You get exactly what you asked for. It's not Next's fault that you don't understand what you yourself wrote.

3

u/neg_ersson Mar 20 '23

What? That is exactly why I'm saying that there is no ideal way to create a fully client-side SPA (that can be hosted on an S3 bucket) using just Next.js and why Vite provides a good intermediate solution for those uses cases.

If you're building a dynamic SPA with Next you'll probably want to run it on a Node.js server (which is totally fine) but you don't need that with a Vite-based SPA. Not every project needs the added complexity and overhead from additional infra.

2

u/gaearon React core team Mar 21 '23

A bunch of HTML files is still an SPA — just a better one. It behaves like an SPA in all other ways (and is more efficient because it splits code by route). The one trickier part is deployment (need a rewrite map) but it’s perfectly possible to host it statically: https://gist.github.com/gaearon/9d6b8eddc7f5e647a054d7b333434ef6

3

u/neg_ersson Mar 21 '23

I get that you and the React team have your reasons to push Vercel products, but a Vite-based SPA will always be easier to host and has more flexible routers for rich applications.