question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Prevent unnecessary loading after SSR

See original GitHub issue

At 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:closed
  • Created 6 years ago
  • Comments:15 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
jaydensericcommented, Apr 4, 2019

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 starts true, then in a hook via useEffect updates to false. 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; otherwise loadOnMount 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. Our useGraphQL hook could try to read the IsFirstMount context, and if it exists, and is true, and there is cache available for the query, decide to bail on loading on mount.

0reactions
jaydensericcommented, Apr 15, 2019

Published in v8.2.0 🚀

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found