useSubscription and useObservableState cause duplicate requests
See original GitHub issueWhen 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:
- Created 3 years ago
- Comments:5 (3 by maintainers)
Top 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 >
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
Updated the sandbox to the alpha and everything looks great! Thank you!
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.