Next.js Layouts RFC: Nested routes and layouts, designed for Server Components
nextjs.org
nextjs.org
We're using a version of the persistent layout pattern Adam Wathan [blogged about](https://adamwathan.me/2019/10/17/persistent-layout-patterns-...) but having first-class support for this paradigm will be awesome.
Not really sure what the problem is here.
IMO it's really just a matter of time before good ideas end up in other projects. It's inevitable. Obviously everyone wants their framework to be as good and popular as possible.
However, this is why I don't use Twitter. Remix is not just "an open-source project", it's a full-fledged company. This is definitely not the time (or the forum) to lay your cards out on the table...
If you can't charge money for the software, selling courses is the next best thing. Why is it yucky?
Also using OSS as a funnel for your business and then use your training to hype up your OSS projects
> No shame in copying but the first prototype of this started before Remix was available. It was more inspired by traditional server routing techniques (like FB used) with React Router locality with Next.js file conventions. So it's more about convergent evolution in this case.
The fact that the APIs looks similar seems largely inevitable based on the fact that everyone seems to be converging around defining routes using folder and file name conventions.
Well, Remix and react-router are by the same people.
The fundamental approach Remix (and now Vercel) takes to nested routing with React SSR is fairly straightforward. It's how everyone else (not using a framework) has been doing nested routing with React SSR for, what, at least 5 years? Granted, most of us have been using React Router for our React SSR setups, and credit very deservingly goes to the React Router guys (who are now the Remix guys) for that. Remix did a great job of delivering a framework that (via a nice compiler and file structure conventions) makes this React SSR routing architecture very easy to use! But that doesn't mean that anyone else who takes this same fundamental approach is somehow copying Remix. The home-grown React SSR setup I've worked on for the last 4+ years has been doing the same thing this whole time, and while we might be "copying what the React Router community was doing 4-5 years ago," and that might even include demos or articles written by someone who went on to found or work at Remix (again, really, thanks!), I don't think we're in any sense "copying Remix."
edit: Well, I just noticed on Twitter than the cofounder of Remix (also co-creator of React Router) is, contrary to the opinion I expressed in the paragraph above, clearly claiming that he believes Remix deserves attribution for any usage of concepts which ever existed previously in React Router. I don't agree with this. https://twitter.com/ryanflorence/status/1528862791490105344
A while ago he had a Twitter series “spot a React app” where he just shits on other peoples work.
Such an odd way to promote his work.
Like get on with it, are there are other things in remix? I'd like to hear about them too!
That is so true. It's been driving me insane since Remix was announced/opened but I couldn't quite put my finger on why. It's because overnight there was an army of people preaching the new religion of Remix all over the place, and not a single one I asked could (at the time at least) tell me why it was better/different than Next.js (a project which IMHO rose on its merit and had to fight for every inch). They had clearly never looked seriously at Next.js before because every "feature" of Remix they were excited about was something Next.js already did. After a bit they started linking to a very long blog post from the Remix creator that supposedly explained why they were different, but after 10 minutes of looking through a post that was supposed to answer my question, all I had was anecdotal performance numbers about how Remix is "faster."
In software we definitely do tend to cargo cult and worship good languages/frameworks, but the Remix "love" is (or was at least) over the top even for us.
Not only in software. Remember the "Don't worry, they'll tell you" jokes about vegans and crossfit?
I think it must be some sort of evolutionary strategy to justify the risk/anxiety of going against the group.
Additionally, I wouldn't trust ever again the guys that rewrote and broke react-router with incompatible changes like... 6 times already? And now bragging on podcasts "Remix is 10 years old because is just built on top of react-router". Bullshit, it's just the npm package name that is this old. It is so deceptive all the ugly marketing they're doing.
I specifically want the parent data to perform redirects in child routes. The only solution is to manually add the redirects at the parent level (like a whitelist).
What sets Remix apart is how it handles network requests through its own <Form /> wrapper, which anecdotally leads to incredibly simple data handling. Even cooler, if you restrict yourself to GET and POST, your app will work without JS. Nifty, if you ask me.
At that point dedicated frontend hosting infrastructures like Netlify, Vercel, Cloudflare Pages and others seems like a better choice.
I mean for SSR they have to run on the backend, but even that I could imagine running parallel to the main backend. I'm just not sure if you get much benefits out of these frameworks without the tight integration on the backend.
Are next.js and other similar React frameworks worth looking at if you don't use node.js on the backend?
And then you already have a backend so it's an easy jump to just using Nodejs on your backend as well.
But a lot of people also just use NextJS as is and never build any server side code and just run their own API beside it.
Or use other frameworks that don't include any SSR features, such as Create-React-App
It depends on why you’re doing so. We’ve recently moved from a C# .net backend to a TypeScript node backend and in such a case it (well obviously) makes perfect sense to utilise next.js.
In other cases where you split your front end and backend quite clearly, like using .net APIs and a JS front end it can make sense to use some degree of nextjs if you need to integrate some compiled parts into your react, maybe you need a fast loading and/or front page then it can be valuable to mix it.
If you don’t know why you’d need it, you probably don’t, however.
create-react-app is just a bunch of oppinions on how to config your app that dont really add much productivity if you are already familiar with webpack. Depending on the need I'd either go with react and my webpack config copied from last project or nextjs. Don't see the point of cra
You can also not use Next.js without a Node.js runtime at all and just compile your whole app to static files to be served by a static file server like S3, nginx, etc. The advantage of this over CRA is that you get statically-rendered html (as well as normal client-rendered React interactivity) which is good for SEO and FCP[1]
[1]: https://web.dev/fcp/
The main benefits of such a framework for us in our use case:
- 90% of the content is essentially static and can be pre-rendered, the rest is dynamic. With NextJS we can easily mix and match these cases, re-using the same code
- We use the backend part to act as a gateway to fetch content from different APIs like the CMS, HR tool, email service, etc. The very little custom backend code required we put into nextjs api functions
- It comes with a couple of niceties built-in for page speed like image optimization.
- Any frontend dev with some react knowledge can work on it. This is my problem with say WordPress, you fairly quickly hit the point where you need specialized knowledge that you can't re-use that much for other projects in the company.
Of course, the same and more can be achieved by selecting libraries to build a bespoke stack, but don't think a fairly standard website that doesn't need to change a whole lot warrants the upfront effort.
There's some obvious inspiration from other frameworks, as Remix and Angular 2.x have had nested routing for years.
Hopefully this will allow for less repetition in pages and a more elegant structure to projects.
If it's in an `index` folder (e.g. `/app/index/page.js`), how would one create a route for `example.com/index`?
Daily user, very excited!
Would love to hear about the parts of the RFC where you guys took some inspiration from Remix!
Also, does this mean you cannot have a page named "layout" anymore?
Lastly, I appreciate all the hard work that goes into nextjs, it's a great developer experience and my goto framework.
That's a good point about having a route `/layout` – I will check with the team about that.
Am I correct about SSG's future?
This is what I meant when I said "second-class citizen at best".
Localized path segments like "/books" or "/libros" could be supported with a path segment mapping configuration.
It should work fine in theory. I guess those configs don't exist yet. Or is there something else that route localization requires?
On the other hand, what I see in practice is adding or removing context providers and layout components in the react router file, it becomes huge, and all the diffs change all of the lines with new indentation.
An option would be to add a catch-all route [1] at the root and implement your own code-based routing. You can still define the desired paths using getStaticPaths [2] but my guess is that some functionality like route-based code splitting will stop working.
0 - https://nextjs.org/docs/advanced-features/middleware
1 - https://nextjs.org/docs/routing/dynamic-routes#catch-all-rou...
2 - https://nextjs.org/docs/basic-features/data-fetching/get-sta...
Edit: welp, seems i glanced over too quickly, it's literally written there:
> The layout.js file convention was inspired by the work done in SvelteKit
But it’s not nested currently, you only get one layout - so if you want some pages to have a sidebar or something then you’re not getting the benefit of the layout system for that.
Next.js routing was wrong from the start, and now it introduces a tons of new concepts that will inevitably require the rewriting of entire apps in a far future, since it will be "the new way to do routing in Next.js".
What I really don't like is the coupling between the filesystem hierarchy and the actual routes, that is difficult to reason about when you have non english routes names with multiple route parameters.
I mean, the routing problem for server side applications was solved a lot of time ago: a simple regex for the route definition, and the related handler that will responde to that route.
I never understood why Next.js guys went with this inconvenient approach of the file system routing.
Nested layouts was the one stumbling block we had with next and felt very odd that we had to invent our own TabPane component to handle this pretty common use case.
Like so: https://www.typescriptlang.org/play?jsx=4#code/C4TwDgpgBASg9...
TS' string literal types are powerful.
https://www.typescriptlang.org/docs/handbook/2/everyday-type...
edit: I did implement this a while back but found it gave me only so much additional value. Though I can imagine that large applications with dozens of developers might indeed benefit from type-safe routes to avoid dead links.
No weirdness or magic API, the useRoute hook just return a discriminating union with typed params. It's fully-featured and used in prod.
The API is quite simple:
const Router = createRouter({ UserDetail: "/users/:userId" });
Router.UserDetail({ userId: "xxx" }); // safe
https://github.com/vercel/next.js/discussions/32216
previously: https://github.com/vercel/next.js/issues/2581
Luckily that level of deep linking hasn’t been asked for, but this sounds really promising for adding some flexibility
With the rise of server side front end practices, it dawns on me that there may be opportunities for integration with other server side runtimes? Asked naively, is there any possibility of an "FFI" integration for Next APIs? Anything more sophisticated than running a subprocess javascript VM?
Screenshots: https://twitter.com/BennettDams/status/1529051702351085568
I’m guessing this should say React 18 instead?
What the industry needs is not more breaking changes, but solidified frameworks that companies can rely on. Every major release adds another wave of technical debt as things become deprecated.
I appreciate updates, but to me this particular proposal shows a lack of long term vision for the framework, attempting to throw in all the exciting bells and whistles from competing frameworks.
This philosophy of “lets stay relevant” will ultimately cost businesses.