Skip to content

Instantly share code, notes, and snippets.

@andreialecu
Created April 6, 2021 10:20
Show Gist options
  • Save andreialecu/49982426d4271773d9ff4935715fb2a6 to your computer and use it in GitHub Desktop.
Save andreialecu/49982426d4271773d9ff4935715fb2a6 to your computer and use it in GitHub Desktop.
@apollo/client patch for fast-refresh
diff --git a/node_modules/@apollo/client/react/hooks/hooks.cjs.js b/node_modules/@apollo/client/react/hooks/hooks.cjs.js
index a0acfe8..68d0b08 100644
--- a/node_modules/@apollo/client/react/hooks/hooks.cjs.js
+++ b/node_modules/@apollo/client/react/hooks/hooks.cjs.js
@@ -56,8 +56,25 @@ function useBaseQuery(query, options, lazy) {
var queryResult = lazy
? result[1]
: result;
+ var _maybeFastRefresh;
+ if (__DEV__) {
+ _maybeFastRefresh = React.useRef(false);
+ React.useEffect(function () {
+ return function () {
+ _maybeFastRefresh.current = true;
+ };
+ }, []);
+ }
React.useEffect(function () {
- return function () { return queryData.cleanup(); };
+ if (_maybeFastRefresh && _maybeFastRefresh.current) {
+ _maybeFastRefresh.current = false;
+ forceUpdate();
+ return;
+ }
+ return function () {
+ queryData.cleanup();
+ queryDataRef.current = undefined;
+ };
}, []);
React.useEffect(function () { return queryData.afterExecute({ lazy: lazy }); }, [
queryResult.loading,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment