News for hackers. Stuff that matters.
Re:Next.js 11 by myth_drannon on Tuesday June 15, 2021 @02:03PM (#27519144)
I see Next.js being pushed into areas where is shouldn't be used. And I mean like data heavy enterprise web apps. Probably in a year or two these projects will collapse under the heavy maintenance burden and will start seeing a lot of unearned negativity towards Next.JS
Re:Next.js 11 by striking on Tuesday June 15, 2021 @02:17PM (#27519366)
I use it without SSR, just because it's a well-known and very well-maintained set of configs. Having to upgrade webpack et al. up major versions sucks.
Re:Next.js 11 by dinkleberg on Tuesday June 15, 2021 @02:39PM (#27519662)
I’m doing the same, it is the easiest out of the box react setup I’ve encountered.

The nice thing is on a current project I found there was one view where SSR made my life a lot easier and since everything was in place for it all I had to do was chuck in an extra function.

Re:Next.js 11 by MrSaints on Tuesday June 15, 2021 @02:40PM (#27519682)
+1 for this. The great thing is you still have the option to incrementally opt for SSR and/or enriching statically generated pages with build-time data.
Re:Next.js 11 by koonsolo on Tuesday June 15, 2021 @03:29PM (#27520307)
Tell me about it.

Some of my colleagues are pushing hard for it. It seems like nice tech, but when you build an enterprise web app behind a login page, I see no need for server side rendering.

Our users open up the app in the morning, work on it a whole day, and do the same thing the next day.

I absolutely see no point in trying to optimize this with server side rendering.

But it seems some front-enders want to use the latest best thing, even when it's not really necessary.

But what do you do? Do you make these developers unhappy because they are not using the latest cool thing, or do you make them happy but end up with an inferior solution?

Oh boy, these youngsters... ;)

Re:Next.js 11 by lucasmullens on Tuesday June 15, 2021 @04:45PM (#27521256)
You can disable SSR and still use Next.js. Most people don't use Next.js because of SSR, they use it because it's easy to use and has an amazing developer environment. SSR works out of the box usually so it's a nice perk.

If you're using React, Next.js is a pretty excellent choice for pretty much any website.

Appeal to Tradition is just as much a logical fallacy as Appeal to Novelty.

Re:Next.js 11 by lucis on Tuesday June 15, 2021 @03:31PM (#27520346)
"Next.js has two forms of pre-rendering: Static Generation and Server-side Rendering. The difference is in when it generates the HTML for a page."

https://nextjs.org/docs/basic-features/pages

Re:Next.js 11 by koonsolo on Tuesday June 15, 2021 @03:37PM (#27520433)
Yeah, so why would you need a custom web server when you do CSR?

Edit: next.js is a web server, right? Because how else can it do SSR?

Re:Next.js 11 by louissm_it on Tuesday June 15, 2021 @03:43PM (#27520509)
Why would you need a custom web server to run Next.js in CSR mode?

Edit: Unintentional sarcastic reply from my side, it was a good question.

Re:Next.js 11 by louissm_it on Tuesday June 15, 2021 @03:43PM (#27520494)
I'd argue most Next sites use only client side rendering.
Re:Next.js 11 by koonsolo on Tuesday June 15, 2021 @03:57PM (#27520678)
So using the export function? Or do they still run the next.js server without having the real benefit of it?

In other words: what is the benefit of next.js when you only do CSR?

Re:Next.js 11 by louissm_it on Tuesday June 15, 2021 @05:31PM (#27521776)
Great question! If you're interested, I'd recommend reading up a bit on all the different rendering and deployment modes Next offers with and without Vercel/Netlify.

If you use Next.js only for CSR, as I'm sure most people do, the benefits are great defaults, easy upgrades, fantastic routing, page prefetching, and easy upgrading to any of the other rendering modes if you ever need them.

You don't run any kind of server if you just use CSR - you bundle your code and push it to anywhere you'd push your normal React SPA (CDN, Vercel, Netlify, etc). I you decide you need to server side render or pre render a page, you can of course run a full node server - but the far easier route is to use the Vercel/Netlify lambda functions(which work out of the box with Next).

I find thinking of Next pages as separate little apps composing the same layout component to be far more maintainable than the more traditional SPA single layout swapping the contents to simulate a page transition.

Re:Next.js 11 by crooked-v on Tuesday June 15, 2021 @05:09PM (#27521541)
It's easier, faster, and has more default features than setting up Webpack by yourself.
Re:Next.js 11 by midrus on Tuesday June 15, 2021 @03:30PM (#27520334)
You hire non hipsters.
Re:Next.js 11 by TechBro8615 on Tuesday June 15, 2021 @02:45PM (#27519759)
Why shouldn't Next.js be used in "data heavy enterprise web apps?" Keep in mind that it's trivial to write code that only executes during CSR: if (typeof window !== "undefined") { fetchExpensiveExternalData(); }
Re:Next.js 11 by tmp_anon_22 on Tuesday June 15, 2021 @02:59PM (#27519930)
Not OP but i'll take a stab at this. Many frameworks struggle to allow you to utilize a small subset of their features at full utility without producing additional overhead from features you aren't even using.

Further frameworks can be deceptive by making complex problem sets seem easy to deal with but later involve complex refactoring over time as the problem set is better understood and evidently less trivial for your organizations particular wants and needs.

These problems aren't highlighting any implicit fault of next.js. Just predicting incorrect ways developers will use it and suffer from. There is an argument to be made these problems would be made less severe if they were approached from the ground up without a framework and what opinions it brings.

Also FWIW I like next.js the project a lot. Hopefully Vercel proves a good steward for it.

Re:Next.js 11 by koonsolo on Tuesday June 15, 2021 @03:36PM (#27520415)
Some people here seem confused why SSR is not the optimal solution for heavy web apps, so let me explain.

Such web apps can be downloaded to the client the first time you open the page, and after that (basically every day), caching strategy makes sure you don't have to download that thing again.

Which means you only need to transfer pure data at that point, and you can have a very responsive web page.

SSR rendering on the other hand, you will get some kind of PHP website (OK, this is exaggerated, but you get the point). Requests go back to the server, and the server renders the page. Totally ludicrous.

SSR: for landing pages, SEO optimization, showing the same page to a lot of users, etc.

CSR: for heavy apps that you use regularly, basically "real" applications, not web pages.

Re:Next.js 11 by ihuman on Tuesday June 15, 2021 @04:16PM (#27520928)
> SSR rendering on the other hand, you will get some kind of PHP website (OK, this is exaggerated, but you get the point). Requests go back to the server, and the server renders the page. Totally ludicrous.

NextJS only renders (or gets the static HTML) and sends you the HTML for the first page you navigate to. When you click a link on that page, it just sends you the data (and JS if needed).

Re:Next.js 11 by underwater on Tuesday June 15, 2021 @04:00PM (#27520719)
In theory, yes. But is anyone actually effectively writing apps in that way? I can't think of a single good example I've seen in the wild.

Most of the time the app is either large and sprawling, updated frequently, or XHR fetches are written in an inefficient way. All of these nullify the benefits from the model of having cached application code. For example if you're waiting for your JS app to initialise, then fetching XHR in a serial way you're probably slower than an SSR page that is sending a data blob down inline.

I'd say SSR is a good rule of thumb, and the few people who build SPAs who can make use of this will know when to break that rule.

Re:Next.js 11 by TechBro8615 on Tuesday June 15, 2021 @08:09PM (#27523244)
This comment is highly misleading. It implies that SSR vs CSR is an “either or” proposition:

> SSR rendering on the other hand... Requests go back to the server... Totally ludicrous.

For Next.js, this description of routing and rendering is “Totally” incorrect. I don’t know about other SSR frameworks (except maybe PHP, which does actually work as the parent comment describes), but with Next.js, you get SSR on first page load and CSR on subsequent clicks.

Thats the whole point of next/router and the <Link> component. Hovering a <Link> will download (“pre-load”) the tiny JS file required to render the next page. Clicking it will trigger client side rendering, without any new server side page load.

The complexity that causes this kind of misunderstanding is the best argument against SSR.

Re:Next.js 11 by stewartmcgown on Tuesday June 15, 2021 @02:49PM (#27519807)
in our teams experience NextJS is pretty much a silver bullet for data heavy enterprise apps
Re:Next.js 11 by myth_drannon on Tuesday June 15, 2021 @02:58PM (#27519917)
Can you elaborate? My understanding is that SSR and NextJS are good for SEO and low powered devices with a slow connection. You load the content before the interactive js ...etc. Why would enterprise apps care about SEO, slow connection speeds. If it's data heavy, it means you still need to fetch data from db before you return html, so SSR is pointless.
Re:Next.js 11 by SamBam on Tuesday June 15, 2021 @03:13PM (#27520110)
> If it's data heavy, it means you still need to fetch data from db before you return html, so SSR is pointless.

I'm very confused by this statement. Maybe I'm just being slow. If you want to fetch data from the db before returning html, then SSR is exactly what you want.

Re:Next.js 11 by chatmasta on Tuesday June 15, 2021 @03:22PM (#27520232)
He's not wrong in some cases. If bandwidth cost from Next->Client exceeds cost from DataSource->Client, then you want to opt out of SSR, to avoid DataSource->Next->Client in favor of direct DataSource->Client during CSR.

Example: Next deployed to AWS (metered bandwidth), with DataSource deployed to colocation (unmetered bandwidth). Page fetches 1GB CSV from DataSource in order to render an HTML Table. In this case, you likely prefer the client to fetch directly from DataSource and render the HTML table during CSR. An exception might be if you care about the table for SEO purposes (e.g. structured data) – but in that case, you should find a way to fetch the first 10 rows instead of 1GB.

It's a fairly niche use-case, though, and it's easy to opt out of SSR for specific code/requests (check if window is defined) or pages (use Next getServerProps vs. getStaticProps).

As an aside... this convoluted scenario highlights one criticism I have with Next.js: It is NOT a friendly mental model for junior engineers. You cannot write a robust Next app without a thorough understanding of the HTTP request lifecycle, network architectures, closures, database/HTTP pools, caching, cookies, etc. If you stay within the lines, you can avoid worrying about most of this stuff, but it's impossible to fully grok Next without a strong background in web fundamentals. If I were advising a beginner on the best stack for practicing React, I would suggest starting with create-react-app, even though I think Next is ultimately the best production framework.

Re:Next.js 11 by koonsolo on Tuesday June 15, 2021 @03:51PM (#27520611)
When you do a proper REST call, your data is always going to be smaller than your html+data.

If you don't show it, you don't need to query it.

Re:Next.js 11 by azangru on Tuesday June 15, 2021 @04:43PM (#27521239)
> low powered devices with a slow connection

Some would argue that React in general isn't a good fit for low-powered devices with a slow connection, because of its bundle size, long first input delay and a rather high cost of heavy javascript usage during re-rendering.

Re:Next.js 11 by brailsafe on Tuesday June 15, 2021 @04:06PM (#27520793)
In many cases SSR is automatically better, including the ones you're talking about, because page rendering errors get thrown in an environment you have more control over, as well as faster devices rendering your already fast pages even faster. In my experience, enterprise work stations are clunky abominations, and if you can save someone some ram and battery why not? It also gives you a platform for building other kinds of non-gated apps that inherit the same benefits.

You might think you have control over the environment someone accesses the app in, but you don't, at least not entirely, and why not just make it as easy as possible to get their work done however they want?

Of course, this doesn't make your thing automatically better all around. That's a design and implementation problem. But you do potentially help everyone by starting at the bottom

Re:Next.js 11 by koonsolo on Tuesday June 15, 2021 @04:37PM (#27521177)
Round trip to the server to compose your HTML feels less responsive. Else you could just do it in PHP anyway.
Re:Next.js 11 by brailsafe on Tuesday June 15, 2021 @07:39PM (#27523037)
Surely you wouldn't just be server side rendering though. Nobody needs a page load for every route change necessarily. These are implementation details.
Re:Next.js 11 by azangru on Tuesday June 15, 2021 @04:45PM (#27521271)
> you could just do it in PHP

That's two languages: javascript and php. Many frontend developers would prefer to just work with one — javascript.

Re:Next.js 11 by ironmagma on Tuesday June 15, 2021 @02:35PM (#27519610)
Why should Next.js not be used for this use case?
Re:Next.js 11 by Marciplan on Tuesday June 15, 2021 @02:33PM (#27519585)
Isnt that what happened to Gatsby oO
Re:Next.js 11 by BoumTAC on Tuesday June 15, 2021 @02:39PM (#27519669)
isn't that what happened with every js framework ?

99% of all js project would have been better with an old school framework (Rails/Symfony/Django/laravel, and any other framework I forgot the name)

Re:Next.js 11 by jstummbillig on Tuesday June 15, 2021 @02:52PM (#27519840)
Next excels in frontend grease, a place where the ssr frameworks do not venture.

I so agree that next is not the ultimate answer. Still waiting for the absolute best of both worlds.

Re:Next.js 11 by CraigJPerry on Tuesday June 15, 2021 @04:28PM (#27521077)
Maybe something like Phoenix liveview? (or htmx / livewire / hotwire/ etc.)

Write SSR, but have the ability to render partials and swap html chunks into the DOM directly rather than running json through a CSR library.

You still get client originated events (user clicks a button) or server originated events, e.g. server wants to proactively push a change - at least for liveview and htmx.

Re:Next.js 11 by aabbcc1241 on Thursday June 17, 2021 @11:08AM (#27540392)
Phoenix Liveview shows great idea, but I prefer to develop in typed environment so I'm working on ts-liveview (TSX+SSR+live-update)
Re:Next.js 11 by kgin on Wednesday June 16, 2021 @08:58AM (#27527994)
The great thing about Next.js is that it’s simple to choose exactly how much of a page is ssr. You can have 0% to 100%.