Layout component in route vs using a layout route performance
Does having a layout route make it more performant to move from one page to the other compared to just having the two routes and inside each the content is wrapped by a Layout component?
I'd guess there isn't much of a difference since Tanstack Start does client side routing but maybe I'm missing something.
19 Replies
fascinating-indigoOP•8mo ago
I'm asking because I have 4 different layouts and the URL structure often doesn't reflect the way layouts are used so it seems like for me it's actually better if I just have in-route layouts instead of having thousands of groupings in the routes folder.
Wondering if there are any penalties to doing that.
foreign-sapphire•8mo ago
what kind of performance ?
fascinating-indigoOP•8mo ago
React re-rendering performance
foreign-sapphire•8mo ago
probably best to measure that yourself whether it has any impact
fascinating-indigoOP•8mo ago
@Manuel Schiller What I meant is: is there a difference between having two route pages with the same layout vs having that layout be in a layout route? Is the layout component gonna re-render in the former case vs not re-render in the latter case?
foreign-sapphire•8mo ago
rerender when what happens?
fascinating-indigoOP•8mo ago
When you navigate from one page to the other
foreign-sapphire•8mo ago
depends on your structure. can you share a concrete scenario?
fascinating-indigoOP•8mo ago
Yeah sure, give me a sec
Case 1
routes/app.tsx
routes/app/a.tsx
routes/app/b.tsx
Case 2
routes/app/a.tsx
routes/app/b.tsx
@Manuel Schiller
I guess the question is, what is the difference between these two cases and why should I prefer case 1 over case 2?foreign-sapphire•8mo ago
when navigating from /app/a to /app/b?
then /app would not re-render in case 1
(unless it subscribed to some router state that changed due to the navigation)
fascinating-indigoOP•8mo ago
And in case 2 it would re-render?
foreign-sapphire•8mo ago
the LayoutComponent?
fascinating-indigoOP•8mo ago
yes
foreign-sapphire•8mo ago
maybe! it depends if react can reconcile this or not
fascinating-indigoOP•8mo ago
So I'm guessing that in case 2 if I had in both pages this:
then it wouldn't re-render
foreign-sapphire•8mo ago
maybe
really depends on react
and the specific circumstances
fascinating-indigoOP•8mo ago
I see
foreign-sapphire•8mo ago
i would definitely go for option 1
fascinating-indigoOP•8mo ago
Ok thanks 👍