Skip to content

Commit 10a8c0a

Browse files
authored
update canUseLayoutEffect check to also allow for layout effects in React Native (#11901)
* update `canUseLayoutEffect` check to also allow for layout effects in React Native for comparison: https://github.com/reduxjs/react-redux/blob/e05ed6840075c9cb75564cb072aa1932f46ce11f/src/utils/useIsomorphicLayoutEffect.ts * size-limits
1 parent d104759 commit 10a8c0a

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

.changeset/brave-cups-swim.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@apollo/client": patch
3+
---
4+
5+
update `canUseLayoutEffect` check to also allow for layout effects in React Native

.size-limits.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"dist/apollo-client.min.cjs": 39578,
3-
"import { ApolloClient, InMemoryCache, HttpLink } from \"dist/index.js\" (production)": 32821
2+
"dist/apollo-client.min.cjs": 39581,
3+
"import { ApolloClient, InMemoryCache, HttpLink } from \"dist/index.js\" (production)": 32830
44
}

src/utilities/common/canUse.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { maybe } from "../globals/index.js";
22

3+
const isReactNative = maybe(() => navigator.product) == "ReactNative";
4+
35
export const canUseWeakMap =
46
typeof WeakMap === "function" &&
5-
!maybe(
6-
() => navigator.product == "ReactNative" && !(global as any).HermesInternal
7-
);
7+
!(isReactNative && !(global as any).HermesInternal);
88

99
export const canUseWeakSet = typeof WeakSet === "function";
1010

@@ -33,4 +33,4 @@ const usingJSDOM: boolean =
3333
// warnings about useLayoutEffect doing nothing on the server. While these
3434
// warnings are harmless, this !usingJSDOM condition seems to be the best way to
3535
// prevent them (i.e. skipping useLayoutEffect when using jsdom).
36-
export const canUseLayoutEffect = canUseDOM && !usingJSDOM;
36+
export const canUseLayoutEffect = (canUseDOM || isReactNative) && !usingJSDOM;

0 commit comments

Comments
 (0)