Mirror: The highly customizable and versatile GraphQL client with which you add on features like normalized caching as you grow.

fix(react-urql): Upgrade muted warning code for React 19 internals (#3769)

Changed files
+33 -17
.changeset
packages
react-urql
src
+5
.changeset/rich-melons-play.md
···
···
+
---
+
'urql': patch
+
---
+
+
Upgrade false-positive circumvention for internal React warning to support React 19
+23 -15
packages/react-urql/src/hooks/state.ts
···
-
import * as React from 'react';
export const initialState = {
fetching: false,
···
return false;
};
-
const reactSharedInternals = (React as any)
-
.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
-
export function deferDispatch<Dispatch extends React.Dispatch<any>>(
-
setState: Dispatch,
-
value: Dispatch extends React.Dispatch<infer State> ? State : void
-
) {
-
if (
-
process.env.NODE_ENV !== 'production' &&
-
!!reactSharedInternals &&
-
!!reactSharedInternals.ReactCurrentOwner &&
-
!!reactSharedInternals.ReactCurrentOwner.current
-
) {
-
Promise.resolve(value).then(setState);
} else {
-
setState(value);
}
}
···
+
import type { Dispatch } from 'react';
export const initialState = {
fetching: false,
···
return false;
};
+
let isDispatching = false;
+
function deferDispatch<F extends Dispatch<any>>(
+
setState: F,
+
value: F extends Dispatch<infer State> ? State : void
+
): void;
+
+
function deferDispatch<F extends Dispatch<any>>(setState: F): ReturnType<F>;
+
+
function deferDispatch<F extends Dispatch<any>>(
+
setState: F,
+
value?: F extends Dispatch<infer State> ? State : void
+
): any {
+
if (!isDispatching || value === undefined) {
+
try {
+
isDispatching = true;
+
return setState(value);
+
} finally {
+
isDispatching = false;
+
}
} else {
+
Promise.resolve(value).then(setState);
}
}
+
+
export { deferDispatch };
+5 -2
packages/react-urql/src/hooks/useQuery.ts
···
() =>
[
source,
-
computeNextState(initialState, getSnapshot(source, suspense)),
deps,
] as const
);
···
source,
(currentResult = computeNextState(
state[1],
-
getSnapshot(source, suspense)
)),
deps,
]);
···
() =>
[
source,
+
computeNextState(
+
initialState,
+
deferDispatch(() => getSnapshot(source, suspense))
+
),
deps,
] as const
);
···
source,
(currentResult = computeNextState(
state[1],
+
deferDispatch(() => getSnapshot(source, suspense))
)),
deps,
]);