In App routing page.tsx is loaded before layout.tsx #66537
Replies: 2 comments
-
|
console logs are not indicitive of code execution paths. they can often "appear" out of order. |
Beta Was this translation helpful? Give feedback.
-
|
Where it the docs does it say that layouts render before pages? In general, pages can render without layouts, which means that a layout is not a requirement for a page, and hence, do not need to render sequentially. In fact, layouts have this behavior of not re-rendering on client side navigation either, so doing auth checks, for example, within them is not a good idea. If you need some data in both layout and pages, you might want to reconsider, given the above, and the layout section of this discussion, #63775 That being said, using something like React cache or, if its a network request, you can rely on Next.js fetch's caching, to make sure you get the data, without making multiple unnecessary calls. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
As per the documentation layout.tsx file should load before page.tsx file.
But when I consoled the log it seems page.tsx is loaded before layout.tsx
So my main problem is that layout.tsx has few configuration which we get from server so in page.tsx as well we need the same configuration
Note: both layout.tsx and page.tsx are server component
Beta Was this translation helpful? Give feedback.
All reactions