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.

useSubscription and useObservableState cause duplicate requests

See original GitHub issue

When either hook is used in coordination with ajax.getJSON() (or similar observable), it acts as if 2 subscriptions are made as there are 2 XHR requests made for each hook.

Minimally reproducible example: https://codesandbox.io/s/quizzical-bassi-xcetk?file=/src/App.js

Monitor the network tab to see that 2 requests are made but only 1 state change is triggered. There are several “examples” in the one sandbox to demonstrate the issue.

When using a normal useEffect(() => stream$.subscribe()), everything works as expected.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
jeffmccormickcommented, Jun 11, 2020

Updated the sandbox to the alpha and everything looks great! Thank you!

1reaction
crimxcommented, Jun 4, 2020

Unfortunately this would be a breaking change as useEffect runs in commit phase. useMemo is intentionally used here so that synchronous values from observables can act as initial values. I think it would be best to do this after the React team releases more info about the concurrent mode.

Read more comments on GitHub >

github_iconTop Results From Across the Web

reactjs - How can I fix duplicate requests?
I'm starting to learn React, and I'm having trouble executing a request, or rather, two requests are made instead of one.
Read more >
Hooks - Apollo GraphQL Docs
Specifies how the query interacts with the Apollo Client cache during execution (for example, whether it checks the cache for results before sending...
Read more >
How to Prevent Double Requesting a Mutation in React Apollo
A quick tip on how to prevent someone from double clicking a mutation in React Apollo.----If you like cooking, checkout my side project: ......
Read more >
Performance - SWR - Vercel
SWR's built-in caching and deduplication skips unnecessary network requests, but the performance of the useSWR hook itself still matters. In a complex app, ......
Read more >
File browser filter should filter folders as well - Jupyterlab ...
Double block place sound, 6, 2021-07-03, 2022-10-31 ; A variant of `useObservableState` which uses `useLayoutSubscription` instead of `useSubscription`, 4, 2020- ...
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