Initial Render Delay with TanStack Router Compared to React Router #1765
Replies: 9 comments 11 replies
-
I have the same problem. I'm building a hybrid application, where some parts are rendered server side (django in my case), and some widgets are rendered client side (ex: Navbar). The navbar takes about half a second to display, even if all JS resources have been loaded already. There's nothing async going on in my part of the code. There are also full-screen SPA pages, where the behaviour is ok. |
Beta Was this translation helpful? Give feedback.
-
I'm encountering the same issue. It's really bad in our companies app which has routes that are 8 layers deep and aren't trivial pages either. A full page rerender takes roughly 500ms so obviously this is noticeable, even as I've only converted less than half our app. Note, this isn't just the first render, whenever you change route, all parent routes will rerender their components (defeating the purpose of the From what I can tell, none of the route components are getting Memoized which is the problem. So while this bug exists, a workaround is as follows export const MyRoute = createRoute({ /* implementation */ })
const MyRouteComponent = () => {
/* implementation */
}
const MyMemoizedRouteComponent = React.memo(MyRouteComponent)
MyRoute.update({
component: MyMemoizedRouteComponent
}) I'm not as confident at the moment to implement a PR but I do have some time over the weekend so I'll take a look if I can make out how to fix this from tanstacks end, because this is pretty much the point of using an Outlet |
Beta Was this translation helpful? Give feedback.
-
This workaround resolved the issue for me: #1929 (comment)
|
Beta Was this translation helpful? Give feedback.
-
Just for reference, it looks like this issue has been happening at least since April - #1460. I imagine it always functioned this way but hasn't had any real performance impact on smaller applications. |
Beta Was this translation helpful? Give feedback.
-
@vishal-tiwari make sure you're using the |
Beta Was this translation helpful? Give feedback.
-
I tried the snippet below, as many developers suggested removing the initial delay, but it didn’t work for me.
|
Beta Was this translation helpful? Give feedback.
-
This is especially noticeable in situations where you have a column-based flex layout with nav/header/main/footer. Generally you'd flex-grow the This is forcing me to instead write |
Beta Was this translation helpful? Give feedback.
-
TanStack/router has a 500ms pending delay on routes if you use a loader, to prevent layout shift i guess, I always remove it. did you try setting setting the following options on the root route: That solves most issues with the 500ms / slow initial load on a page |
Beta Was this translation helpful? Give feedback.
-
Having same issue, footer and header renders first, and it looks not really nice. As a solution I could use SSR but this will lead to more complexity |
Beta Was this translation helpful? Give feedback.
-
I’m experiencing an initial delay in rendering routes along with the basic app layout when using TanStack Router, even though my application does not involve any data loading. In contrast, when I use React Router, the initial render is significantly faster.
Here are the steps I've already taken to optimize performance:
Any insights or recommendations would be greatly appreciated as I’d prefer to use TanStack Router for its advanced features, but the performance difference is currently a blocker.
Beta Was this translation helpful? Give feedback.
All reactions