leptos icon indicating copy to clipboard operation
leptos copied to clipboard

Route component without re-render its view

Open ycuk opened this issue 1 year ago • 2 comments

Describe the solution you'd like a. A new property in existing <Route> to disable cleanup (dispose) after first render. b. A new component that never cleanups (disposes) after first render. c. I'm not sure if new property is suitable for <StaticRoute>

Additional context I have dashboard index page with statistic loading from create_action and don't want to reload data every time when I back to that page. It doesn't matter resource or action, I have buttons to reload data manually or change date range, so action.dispatch() more useful. So server-side cache is not really what I need. For now my data is small and its ok with re-render, so it looks like a flash. In future will be more data and more pages like this. Also in my other project, index page too, it is photo album root if tree page, many thumbnails.

ycuk avatar Feb 22 '24 09:02 ycuk

The current way to do this, IMO, would be to put the create_action in the root of the app and pass it via context or props to the route. (You can define that in a function that lives with the route code, I'm not saying you need to put all the business logic in the wrong place.)

I think this is actually better than the idea of something like a <LeakRoute/>. I don't mean that sarcastically: I would genuinely want to name it something like that so it was clear that it's the same as a Box::leak() or something; you're making a one-time memory leak in exchange for static access. The logic to add the special case to the router does not seem worth it to me in exchange for the benefit, when this can already be accomplished.

gbj avatar Feb 22 '24 11:02 gbj

Your way is working, but I added pagination or infinite scroll and it resets pagination or scroll position.

ycuk avatar Feb 27 '24 12:02 ycuk