This afternoon I am learning "next.js". I have a question.

The point of next.js appears to be its deep integration with "React". I like "React". But when I write React apps I prefer to ship them with "Preact", as this results in smaller site blob sizes. Is it possible to use next.js with Preact?

I have a second question. This one is maybe a little weirder. It sounds like the benefit of next.js is it allows you to move React "to the server side".

Is there any point at which you can use next.js as a SSG or where you can refocus your code to turn next.js into an SSG? If I have a site generated by next.js how hard would it be to have the site simply generate itself in its entirety to static html files at rest and put them in a zip?

@mcc yes. If you run "next build" and configure the output to "export", it'll just make folders of html files https://nextjs.org/docs/pages/building-your-application/deploying/static-exports
Deploying: Static Exports | Next.js

Next.js enables starting as a static site or Single-Page Application (SPA), then later optionally upgrading to use features that require a server.

@mcc not too hard, but if you aren't already familiar with react server components, it can be a weird learning curve.

If you are interested in other, non react centric SSG tools, I'm a big fan of astro, which allows for a nice middle ground in my opinion. However, there is of course a learning curve.

@SudoCat i don't know what a react server component is but as long as i'm learning 1 thing i can learn 2 things.

i would prefer to use the most react centric tool possible unless someone can present me with something web-native which works as close to react as possible. i was actually looking at astro but if it's less react that makes me less interested

@mcc that's fair enough! React server components are, in short, react components that only execute on the server, and never send client side js. They cannot do state and effects, but can be async, so great for data fetching and what have you.

Astro allows you to use react when you need it, you can render it out pure server or client as you choose. If you want to know more, I'm happy to write essays about how much I love it and why, but I recognise that's probably not what you're looking for! 😅

@SudoCat can you use react server components without using nextjs?

when you messaged i was actually investigating astro in a different tab.

when i say "i want to use react" i think i really mean "i want to use typescript+jsx". i'd like to avoid static html whereever possible. when you're not using react in astro what are you using instead?

@mcc sorry, food took my focus.

Technically yes, currently no. They're a react feature, but next is the only major framework to support them last I checked.

@mcc Astro uses it's own jsx-like syntax. It's somewhat similar to Vue, with markup for your html with js available in it, and script tags are auto compiled into modules. There's a "front matter" section of files for meta. You can embed react components in the pages, and either choose to only SSR them, or client hydrate them, by passing a prop. Each component is rendered into an "island", which are just separate react render roots.
@mcc When I used Astro for my last contract, it was an ecommerce project. We had the majority of our pages written in Astro files for pure static content, with a react component library. You can mix and match the react and astro (astro components with react inside). When we needed complex client-side functionality, we hydrated react. When we only needed the shared components, we only server rendered them. When we needed minimal JS, we just used vanilla in a script tag.

@mcc I am a fairly old school front end guy, so I really like this paradigm for building websites. A lot less JS, a lot better experience for users, and the ability to mix-and-match tools as appropriate. Plus astro handles all the gnarly compiler jank, so I never had to think about that.

Sorry, I'm absolutely an astro fan boy 😭

@SudoCat does it integrate fully with typescript?