diff --git a/.changeset/polite-birds-rescue.md b/.changeset/polite-birds-rescue.md new file mode 100644 index 00000000000..c248b44089b --- /dev/null +++ b/.changeset/polite-birds-rescue.md @@ -0,0 +1,5 @@ +--- +'@apollo/client': patch +--- + +Silence useLayoutEffect warning when useSuspenseQuery runs on server diff --git a/.changeset/pre.json b/.changeset/pre.json index 5020041401f..1ef9f528193 100644 --- a/.changeset/pre.json +++ b/.changeset/pre.json @@ -6,6 +6,7 @@ }, "changesets": [ "early-pens-retire", + "polite-birds-rescue", "rude-mayflies-scream", "sixty-trains-sniff", "small-timers-shake" diff --git a/CHANGELOG.md b/CHANGELOG.md index 1c05ba89a8d..d217d1dc4cf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # @apollo/client +## 3.8.0-alpha.3 + +### Patch Changes + +- [#10399](https://github.com/apollographql/apollo-client/pull/10399) [`652a1ae08`](https://github.com/apollographql/apollo-client/commit/652a1ae0868e4a5b75b9ff656d26f57eeca1081a) Thanks [@alessbell](https://github.com/alessbell)! - Silence useLayoutEffect warning when useSuspenseQuery runs on server + ## 3.8.0-alpha.2 ### Minor Changes diff --git a/config/bundlesize.ts b/config/bundlesize.ts index 33b1cd94112..982d17cef85 100644 --- a/config/bundlesize.ts +++ b/config/bundlesize.ts @@ -3,7 +3,7 @@ import { join } from "path"; import { gzipSync } from "zlib"; import bytes from "bytes"; -const gzipBundleByteLengthLimit = bytes("33.17KB"); +const gzipBundleByteLengthLimit = bytes("33.19KB"); const minFile = join("dist", "apollo-client.min.cjs"); const minPath = join(__dirname, "..", minFile); const gzipByteLen = gzipSync(readFileSync(minPath)).byteLength; diff --git a/package-lock.json b/package-lock.json index 0f5b0e9c9a4..66b8c0747da 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@apollo/client", - "version": "3.8.0-alpha.2", + "version": "3.8.0-alpha.3", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@apollo/client", - "version": "3.8.0-alpha.2", + "version": "3.8.0-alpha.3", "hasInstallScript": true, "license": "MIT", "dependencies": { diff --git a/package.json b/package.json index 6a7653031aa..0c5fc73f2dc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@apollo/client", - "version": "3.8.0-alpha.2", + "version": "3.8.0-alpha.3", "description": "A fully-featured caching GraphQL client.", "private": true, "keywords": [ diff --git a/src/react/hooks/internal/index.ts b/src/react/hooks/internal/index.ts index aa70141c2c1..3db9a013096 100644 --- a/src/react/hooks/internal/index.ts +++ b/src/react/hooks/internal/index.ts @@ -1,2 +1,3 @@ // These hooks are used internally and are not exported publicly by the library export { useDeepMemo } from './useDeepMemo'; +export { useIsomorphicLayoutEffect } from './useIsomorphicLayoutEffect'; diff --git a/src/react/hooks/internal/useIsomorphicLayoutEffect.ts b/src/react/hooks/internal/useIsomorphicLayoutEffect.ts new file mode 100644 index 00000000000..7135b952e5c --- /dev/null +++ b/src/react/hooks/internal/useIsomorphicLayoutEffect.ts @@ -0,0 +1,6 @@ +import { useLayoutEffect, useEffect } from 'react'; +import { canUseLayoutEffect } from '../../../utilities/common/canUse'; + +export const useIsomorphicLayoutEffect = canUseLayoutEffect + ? useLayoutEffect + : useEffect; diff --git a/src/react/hooks/useSuspenseQuery.ts b/src/react/hooks/useSuspenseQuery.ts index c54b89dce6d..3eb12e254c2 100644 --- a/src/react/hooks/useSuspenseQuery.ts +++ b/src/react/hooks/useSuspenseQuery.ts @@ -4,7 +4,6 @@ import { useCallback, useMemo, useState, - useLayoutEffect, } from 'react'; import { equal } from '@wry/equality'; import { @@ -31,7 +30,7 @@ import { SuspenseQueryHookOptions, ObservableQueryFields, } from '../types/types'; -import { useDeepMemo } from './internal'; +import { useDeepMemo, useIsomorphicLayoutEffect } from './internal'; import { useSuspenseCache } from './useSuspenseCache'; import { useSyncExternalStore } from './useSyncExternalStore'; @@ -309,7 +308,7 @@ function useObservableQueryResult(observable: ObservableQuery) { // // Unlike useEffect, useLayoutEffect will run its cleanup and initialization // functions each time a component is suspended. - useLayoutEffect(() => { + useIsomorphicLayoutEffect(() => { isMountedRef.current = true; return () => {