RFC: Layouts #37136
Replies: 165 comments 315 replies
-
First of all, this was fantastically written and presented. It provided adequate context without being overly verbose or complex and the example images are great. At the risk of bike shedding, I'm not sure that the |
Beta Was this translation helpful? Give feedback.
-
As mentioned by @baiirun , this is really well written and presented and the drawings are perfect for a good comprehension about the changes. Is there a reason to not keep the naming conventions with prefixed |
Beta Was this translation helpful? Give feedback.
-
The answer to this is almost definitely a "yes", but just to confirm: I assume that anywhere it references a name like |
Beta Was this translation helpful? Give feedback.
-
This looks incredible. Will |
Beta Was this translation helpful? Give feedback.
-
First of all, congratulations on the proposal. I believe this will greatly improve responsiveness and the developer experience. That being said, I have a few questions:
Again, great work! |
Beta Was this translation helpful? Give feedback.
-
Great job on the RFC and this is very exciting! One thing jumps out as a potential pain-point with the naming convention here. If one of the stated benefits that this enables is colocating code with your routes, I foresee many applications with hundreds of files named Would it be possible to allow engineers to define layout vs page by filename pattern? ie)
|
Beta Was this translation helpful? Give feedback.
-
Congratulations on the really well written posts. But can we talk about the naming of page.js/tsx? Edit: another question that came into my mind: how would you change layouts based on a user prop? Let's say the user is a paid member or admin or moderator? With this new RFC, would you need to implement the differences on all layout.tsx files? |
Beta Was this translation helpful? Give feedback.
-
Is getInitialProps still supported with layout.js? Otherwise it could become a bit of an hassle maintaining a clientside GraphQL cache (as mentioned here #19611) I know GraphQL is not first-class, but the same issue exists for any request that can be skipped and until now this was one of the reasons why Next.js was the only reasonable choice for GraphQL APIs. This obviously contradicts with the direction towards server components but there's still a lot of merit for shipping the bundles to the client and having an simple stateless backend after the first render and the "rendering runtime" on the client (offloading future work) |
Beta Was this translation helpful? Give feedback.
-
According to the RFC, "by default, files inside app will be rendered on the server as React Server Components". And in server components we will be able to directly fetch data and interact with a db or any external API directly from the React code (as showcased in the original RSC demo with the react-pg or react-fs example libraries). However, instead of fetching data in the component itself (either a layout or a page), in the RFC it looks like the recommendation would still be to use getServerSideProps as in the current SSR pages. Would there be a difference between choosing one method or the other? Will the "use server code directly in React" be discouraged in Next? If we choose to directly call server code in React, how can we tell Next that it should or shouldn't make it a static route? Will the server code defined in the component be able to run statically too (without using getStaticProps)? If we call server code in the component level, can we still share it with parent/children segment layouts? Will there be a route context or similar that can be used to read/refresh data from any part of the tree (including a client component)? I definitely see a window for database providers and APIs publish React utilities either in the form of hooks (like Hydrogen's useShopQuery) or components (like the experimental proof of concept from prisma). At this early stage and without having read the second post yet, it looks like building this kind of tooling on top of React RSC will probably be limited and adoption reduced if getServerSideProps/getStaticProps are still the recommended way of providing data to a route. Note: Before reading the RFC I had naively thought that getServerSideProps would be deprecated in favor of data fetching in RSC, so I might be a little biased against it with my "how would I do it" expectations. |
Beta Was this translation helpful? Give feedback.
-
Great article. Did not see any information about error boundary and using layouts to restrict errors. |
Beta Was this translation helpful? Give feedback.
-
How committed are we to the In Nx monorepos, Next.js apps are already within an If you replace the usages of
vs
and
vs
These new files are lifting away from the Pages paradigm to be backwards compatible, but they are still responsible for routing (and "routing" is a common naming concept of React in general). Thoughts? |
Beta Was this translation helpful? Give feedback.
-
Great work on this RFC. I do want to start a topic of discussion based on my experience with... another framework :). I like the concept of parallel fetching. However, there are some cases where it simply makes more sense for a parent route to provide data to child routes when fetching server props. For instance, you might have routes that use a common Is there a way to somehow serially load some data and load other bits of data in parallel? In particular, there was a situation where I wanted to redirect all child routes based on a result from a |
Beta Was this translation helpful? Give feedback.
-
I'm very excited for what Layouts will enable!!! I have many questions. It's unclear to me how I saw that _app was mentioned; however, I saw no reference of _error, _404, and _500. Will there be equivalent files per segment? Since we can potentially expect error responses from multiple data fetching methods, will either the methods OR the custom components be getting an updated API to allow developers insight into which data fetch caused the issue?
Is it possible for a segment to have a Lastly, I was disappointed to see this:
What I can't ignore is that it feels like Server Components are not around the corner. Layouts has been a big need in Next.js for a long time, and I feel like connecting this to multiple React features that are still in RFC and/or unreleased may lead to this taking way longer than necessary. At the very least |
Beta Was this translation helpful? Give feedback.
-
I could be missing something, but what if we need to pass Maybe a layout.js component should accept a |
Beta Was this translation helpful? Give feedback.
-
This is absolutely so exciting! So happy to see support for this finally, and I cant' wait to see it roll out... speaking of which, any ETAs on when we could see this hit Next? This is truly a game-changer for Next and will make development so much better on larger, complex sites. |
Beta Was this translation helpful? Give feedback.
-
How will passing data from the page level up to the root layout work? |
Beta Was this translation helpful? Give feedback.
-
Great write up, and layout RFC makes nextjs finally on par with CSR in the shared layout use case. Just 1 quick question, does it ditch the client-side caching? Which means, there is no concept of client-side caching anymore, and onServerSideProps will always "send" a request since it's on the server and has no knowledge of client-side caching? What about I want to cache certain requests for a certain times or certain conditions? Also, on a CSR app, for subsequent requests for a request X, libs like react-query would return the old cache first, then doing a refetch underneath, so the page will render instantly but only re-renders when there is new data from server. This leads to a smooth UX, is it still possible with this RFC? How does layout RFC play with this use case plz? 😃 |
Beta Was this translation helpful? Give feedback.
-
any news on when they gonna release it? |
Beta Was this translation helpful? Give feedback.
-
It would be nice to have a way to return only the components without any wrappers (headers, scripts ...), something similar could be done before with |
Beta Was this translation helpful? Give feedback.
-
super excited for this 😄 |
Beta Was this translation helpful? Give feedback.
-
trying to implement the rfc app directory. i encounter this error "Error: > Couldn't find a |
Beta Was this translation helpful? Give feedback.
-
Hello. |
Beta Was this translation helpful? Give feedback.
-
Looks good but I'm curious about storing API logic along side each conceptual group of code. Right now it's a bit weird to store client side things and API utility code in /app/thing — then have to also maintain a /pages/api/thing directory. Will it be possible to store API routes along side their client side friends in the /app directory? |
Beta Was this translation helpful? Give feedback.
-
This seems like it will work very well for "apps" where the layout is often defined by the path and known in advance. I'm not clear on how this will work for sites where the layout is dynamic and based on the page or "slug". On our site, we need to fetch layout data from our CMS on a per-page basis. Most of the time this data is the same from page to page, but it could potentially change even within the same dynamic route. Layouts can also be variable within the same page if an A/B test is active. It seems like we would need a way to access page props within the Layout component. |
Beta Was this translation helpful? Give feedback.
-
Wanted to follow up here with another update: we will be sharing more about this next week at Next.js Conf. |
Beta Was this translation helpful? Give feedback.
-
Any examples with RFC layouts? Also can we safely use this for auth pages too? Or it is meant only for non-auth pages? |
Beta Was this translation helpful? Give feedback.
-
With the current state of the RFC, we’ll have to remember which file names are special to Next.js. Here’s a quick quiz: Which of these files are special to Next.js and which files are custom components that are colocated within the route folder? Did you get the correct answer? Also, with the current naming scheme, any new special files that gets added in the future can become a breaking change, if it clashes with pre-existing colocated files. SvelteKit resolves this issue by designating a reserved prefix for files that are treated specially by the framework. This way that it’s easier for humans to easily tell the difference between colocated files and special files, as text editors will display files with a prefix separately from files without prefix. Here’s what the editor file tree will look like if Next.js special files are prefix with |
Beta Was this translation helpful? Give feedback.
-
In Next 13, will all components be Server Components by default or only the ones that are in the "app" directory? |
Beta Was this translation helpful? Give feedback.
-
Congrats on the release of next 13! 🙌 No love for named exports? |
Beta Was this translation helpful? Give feedback.
-
Update: We’re excited to announce Next.js 13, which includes the new Inside the You can leave feedback here: #41745 |
Beta Was this translation helpful? Give feedback.
-
Update: #37136 (comment)
This RFC outlines the biggest update to Next.js since it was introduced in 2016:
👉 Read the RFC – we'd love to hear your feedback and comments.
Beta Was this translation helpful? Give feedback.
All reactions