DEV Community

Cover image for Introducing an Alternative to NEXT.js

Introducing an Alternative to NEXT.js

Shiono Yoshihide on December 16, 2019

Introduction When we develop React apps, it is one of the best choices to separate a server and a client. But in those cases, we must i...
Collapse
 
adam_cyclones profile image
Adam Crockett 🌀

I admire the post thanks for sharing!
On the subject, I have a framework agnostic alternative this should work with just about anything. send in a headless browser like chrome headless (puppeteer) to render the requested page, toString the output and send that as the response. In other words a much faster browser with no UI does the heavy lifting ahead of time and does cache for the next visitor which is even faster.

Collapse
 
saltyshiomix profile image
Shiono Yoshihide

Oh, thank you for your sharing that!
The idea of intermediate puppeteer server is awesome :)

If you are OK, please let me know your framework!

Collapse
 
adam_cyclones profile image
Adam Crockett 🌀

Just download puppeteer to get started with headless chrome controlled by JavaScript. Then no matter what framework, given I use express, on route, point the browser here, get the rendered page as a string, store as a variable then serve that string. Not much else to it.

Like I say, no framework required just puppeteer and any http server.

Thread Thread
 
saltyshiomix profile image
Shiono Yoshihide

Thank you letting me know!

It may be similar to react-native-dom, right? (If wrong, I'm sorry.)

I will try puppeteer later :)

Thread Thread
 
adam_cyclones profile image
Adam Crockett 🌀

Potentially? I am not a react specialist. Puppeteer is fantasticly useful, I have used it within a unit testing framework to create acceptance tests.

Collapse
 
bbarbour profile image
Brian Barbour

Does it rehydrate the JS on the client side?

Collapse
 
saltyshiomix profile image
Shiono Yoshihide • Edited

Thank you for your comment!

It hydrates id="react-ssr-root" once :)

Collapse
 
mxrcochxvez profile image
Marco Chavez

I am interested in finding out what you mean by this? I am fairly new to development seeking out as much information as possible and this commend interested me since it seems like it pertains to performance.

Collapse
 
bbarbour profile image
Brian Barbour

So when you render javascript on the server, it just sends the markup and content to the browser. Rehydration means that the client side javascript "comes to life" and can function, rather than being static as was sent. It's not really related to performance, as far as I'm aware.

Thread Thread
 
saltyshiomix profile image
Shiono Yoshihide

Thank you for your explanation!

In this point, react-ssr rehydrates DOM so we can use full React features like hooks :)

Collapse
 
saltyshiomix profile image
Shiono Yoshihide

I'm interested in the meaning of rehydrate, too.

Anyway, react-ssr hydrates a DOM target once :)

Collapse
 
lawrencejohnson profile image
Lawrence • Edited

What you made is pretty cool. I just spent the last few hours playing with it, but I think you need to point out in your documentation that this does not support client-side routing. This may be obvious to some people, but it wasn't for me. I won't say it was a waste of time because overall I like what you built, but I feel like when we come across a tool named react-ssr we're going to assume that it's not purely server-side rendering unless otherwise noted.

Collapse
 
saltyshiomix profile image
Shiono Yoshihide

Thank you for your comment!

I totally agree with what you pointed out. I'll improve README until next minor release :)

If you have any troubles, feel free to open issues like this comment!

Collapse
 
wnemencha profile image
William Nemencha

Hey, thanks for sharing!
You said it can replace NextJS, so what about client side routing ? Do you need to add smth like react-router/reach-router and then bind on the same routes you already declared in Express?

Collapse
 
saltyshiomix profile image
Shiono Yoshihide

Thank you for pointing it out!

It may be too much to say alternative, because I don't think it can replace all roles of NEXT.js.

But it may be or can be a choice to use react-ssr for small projects.

This project aims to make the new way to use React, as a view template engine. It renders views and passes server data to the client like ejs or handlebars, so we should not use this library if we have to use client side routing so many.

I think the practical usage is one of the blows:

  • Simple Blogging Site
  • Documentation Site
  • Test React without a webpack config
Collapse
 
jcarlosweb profile image
Carlos Campos

Another option for backend is tsed.io/

Collapse
 
dance2die profile image
Sung M. Kim

Cool stuff, Shiono!

For some reason it looks familiar as it seems close to ASP.NET, where React is being used in place of Razor. Would such an association be an accident? 😉

Collapse
 
saltyshiomix profile image
Shiono Yoshihide

I'm a .NET developer too, so I know Razor but I made a similar project accidentally :)

For React, server side rendering is mainly for Node.js. I think Razor made a big thing to use SSR React applications with not Node.js. I admire.

Collapse
 
dance2die profile image
Sung M. Kim

You've created something fun "accidentally" in a good way :)

Collapse
 
saurabhdaware profile image
Saurabh Daware 🌻

This is so cool! thank you for sharing and great project 🦄

Collapse
 
saltyshiomix profile image
Shiono Yoshihide

Thank you very much, Saurabh!

I just published v0.19.0 and added @react-ssr/static which can generate static files.

If you like, feel free to send me feedbacks :)

Collapse
 
joshuaamaju profile image
Joshua Amaju

🙌🏾🙌🏾🙌🏾. You're a life saver. Been looking for something like this, almost gave to start something similar on my own.

Collapse
 
mxrcochxvez profile image
Marco Chavez

What a great article covering an amazing new technology. I am going to give this a try today!

Collapse
 
saltyshiomix profile image
Shiono Yoshihide

Thank you very much, Macro!

Please check out this "good old way" server rendered view technology :)

Collapse
 
kumard3 profile image
Kumar Deepanshu

Bro I have seen your nextron project and it is dope, can you tell me how you make a cli tool, create-nextron-app .