How to hide page content before javascript execution, hydration and on_load event #2885
Replies: 3 comments 3 replies
-
We have found a way to slightly mitigate this "issue" and lower the delay between the page load and the display of the loading spinner. `class DebugMiddleware(rx.Middleware):
app.add_middleware(DebugMiddleware())` state.update_vars_internal is the first event that is fired every time we load a new page. We have also thought of an alternative solution (which is yet to be tested). |
Beta Was this translation helpful? Give feedback.
-
Interesting. Reflex calls the (relatively) new I don't think there's a way to solve this in reflex currently. It seems like something that we'll have to address within the framework itself. reflex/reflex/.templates/web/utils/state.js Lines 647 to 654 in f39c138 I think Reflex needs to set Something like // Route after the initial page hydration.
useEffect(() => {
const change_start = () => dispatch["state"]({is_hydrated": false})
const change_complete = () => addEvents(onLoadInternalEvent());
router.events.on("routeChangeStart", change_start);
router.events.on("routeChangeComplete", change_complete);
return () => {
router.events.off("routeChangeStart", change_start);
router.events.off("routeChangeComplete", change_complete);
};
}, [router]); I haven't tested it yet, but dropping here so i don't lose this thought. |
Beta Was this translation helpful? Give feedback.
-
Related to this, I only today realized that even if you guard a page with that |
Beta Was this translation helpful? Give feedback.
-
Hi,
right now, the frontend code of our application is structured like this:
Also, for each page we have defined an
on_load
event which fetches some remote content and updates the state accordingly.What's happening is that when we navigate from one page to another, first the page is immediately displayed without any loading spinner using the previous state, then after 1-2 seconds the javascript is fetched and executed (I guess), the loading spinner is displayed for a little while and finally the page is displayed again with the new updated state.
The app works just fine but this kind of flickering effect is a bit annoying.
Of course we could just remove the condition and remove the flickering effect too, but what we're trying to achieve is that the page shouldn't be interactive (or displayed at all) until we have fetched content in the on_load event.
How can we achieve that?
Thanks
Beta Was this translation helpful? Give feedback.
All reactions