Prevent unnecessary loading after SSR
See original GitHub issueAt the moment, Query
components with the loadOnMount
prop automatically fetch fresh data when mounted on the initial page load. This is unnecessary after SSR as the hydrated cache can be assumed to be fresh.
While harmless, and in some cases useful (if data becomes stale in the time it takes the page to load), it would be nice to work out how to prevent this to reduce the burden on servers and reduce client network traffic.
Issue Analytics
- State:
- Created 6 years ago
- Comments:15 (9 by maintainers)
Top Results From Across the Web
How to disable loading a component in SSR · Issue #47 - GitHub
One reason to do it in Component.js might be to add the ssr: false component to the marks but not load it on...
Read more >Keeping Server-Side Rendering Cool With React Hydration
Generally, you should avoid unnecessary layout shifts during page load by implementing layouts with placeholder/gap for expected client-side ...
Read more >How to Disable Server-Side Rendering (SSR) in Next.js
Step 1: Rewrite All Requests to pages/index.js · Step 2: Disable SSR for Page Content · Step 3: Check that Everything Works with...
Read more >Improve app performance with React server-side rendering
SSR means there is no need for loaders or spinners for the initial load. This means that, generally speaking, SSR will outperform CSR....
Read more >Next js - disable server side rendering on some pages
Lazy load the component and disable SSR: https://nextjs.org/docs/advanced-features/dynamic-import#with-no-ssr
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
You’re just describing the original issue.
I’ve had an idea though.
As a standalone context and hook (could even be published separately), there could be a context called something like
IsFirstMount
that startstrue
, then in a hook viauseEffect
updates tofalse
. I’m don’t think it needs to be state, as when it changes we don’t want to trigger the app to re-render. This context and hook needs to be used at the top app level, above any route components; otherwiseloadOnMount
won’t work when navigating back and forth between routes.I’m pretty sure child components mount before their parents do, so if they read from the
IsFirstMount
context they can tell if it’s the first mount or not. OuruseGraphQL
hook could try to read theIsFirstMount
context, and if it exists, and istrue
, and there is cache available for the query, decide to bail on loading on mount.Published in v8.2.0 🚀