Skip to content

Commit c6ab364

Browse files
authored
Temporarily revert useSyncExternalStore changes (#8785). (#9393)
This reverts commit 7f0d459 (#8785) and follow-up commit 5328dae (move onCompleted and onError to the snapshot function).
1 parent cefd24c commit c6ab364

26 files changed

+773
-379
lines changed

package-lock.json

Lines changed: 2 additions & 36 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,8 @@
6565
"peerDependencies": {
6666
"graphql": "^14.0.0 || ^15.0.0 || ^16.0.0",
6767
"graphql-ws": "^5.5.5",
68-
"react": "^16.8.0 || ^17.0.0 || ^18.0.0-beta",
69-
"subscriptions-transport-ws": "^0.9.0 || ^0.11.0",
70-
"use-sync-external-store": "^1.0.0 || ^1.0.0-rc || ^1.0.0-beta"
68+
"react": "^16.8.0 || ^17.0.0",
69+
"subscriptions-transport-ws": "^0.9.0 || ^0.11.0"
7170
},
7271
"peerDependenciesMeta": {
7372
"graphql-ws": {
@@ -78,9 +77,6 @@
7877
},
7978
"subscriptions-transport-ws": {
8079
"optional": true
81-
},
82-
"use-sync-external-store": {
83-
"optional": true
8480
}
8581
},
8682
"dependencies": {
@@ -112,7 +108,6 @@
112108
"@types/node": "16.11.19",
113109
"@types/react": "17.0.34",
114110
"@types/react-dom": "17.0.2",
115-
"@types/use-sync-external-store": "^0.0.3",
116111
"acorn": "8.6.0",
117112
"bundlesize": "0.18.1",
118113
"cross-fetch": "3.1.4",
@@ -138,7 +133,6 @@
138133
"ts-jest": "27.1.2",
139134
"ts-node": "10.4.0",
140135
"typescript": "4.5.2",
141-
"use-sync-external-store": "1.0.0-rc.0",
142136
"wait-for-observables": "1.0.3",
143137
"whatwg-fetch": "3.6.2"
144138
},

src/core/ObservableQuery.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -285,9 +285,11 @@ export class ObservableQuery<
285285
variablesMustMatch?: boolean,
286286
) {
287287
const last = this.last;
288-
if (last &&
289-
last[key] &&
290-
(!variablesMustMatch || equal(last!.variables, this.variables))) {
288+
if (
289+
last &&
290+
last[key] &&
291+
(!variablesMustMatch || equal(last.variables, this.variables))
292+
) {
291293
return last[key];
292294
}
293295
}
@@ -326,7 +328,7 @@ export class ObservableQuery<
326328
// (no-cache, network-only, or cache-and-network), override it with
327329
// network-only to force the refetch for this fetchQuery call.
328330
const { fetchPolicy } = this.options;
329-
if (fetchPolicy === 'standby' || fetchPolicy === 'cache-and-network') {
331+
if (fetchPolicy === 'cache-and-network') {
330332
reobserveOptions.fetchPolicy = fetchPolicy;
331333
} else if (fetchPolicy === 'no-cache') {
332334
reobserveOptions.fetchPolicy = 'no-cache';
@@ -761,8 +763,12 @@ once, rather than every time you call fetchMore.`);
761763
result: ApolloQueryResult<TData>,
762764
variables: TVariables | undefined,
763765
) {
764-
if (this.getLastError() || this.isDifferentFromLastResult(result)) {
765-
this.updateLastResult(result, variables);
766+
const lastError = this.getLastError();
767+
if (lastError || this.isDifferentFromLastResult(result)) {
768+
if (lastError || !result.partial || this.options.returnPartialData) {
769+
this.updateLastResult(result, variables);
770+
}
771+
766772
iterateObserversSafely(this.observers, 'next', result);
767773
}
768774
}

src/react/components/__tests__/client/Mutation.test.tsx

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,11 +1021,7 @@ describe('General Mutation testing', () => {
10211021
return (
10221022
<Mutation mutation={mutation} refetchQueries={refetchQueries}>
10231023
{(createTodo: any, resultMutation: any) => (
1024-
<Query
1025-
query={query}
1026-
variables={variables}
1027-
notifyOnNetworkStatusChange={true}
1028-
>
1024+
<Query query={query} variables={variables}>
10291025
{(resultQuery: any) => {
10301026
try {
10311027
if (count === 0) {
@@ -1051,16 +1047,13 @@ describe('General Mutation testing', () => {
10511047
// mutation loading
10521048
expect(resultMutation.loading).toBe(true);
10531049
} else if (count === 6) {
1054-
// mutation still loading???
1055-
expect(resultMutation.loading).toBe(true);
1056-
} else if (count === 7) {
1057-
expect(resultQuery.loading).toBe(true);
1050+
// mutation loaded
10581051
expect(resultMutation.loading).toBe(false);
1059-
} else if (count === 8) {
1052+
} else if (count === 7) {
10601053
// query refetched
1061-
expect(resultQuery.data).toEqual(peopleData3);
10621054
expect(resultQuery.loading).toBe(false);
10631055
expect(resultMutation.loading).toBe(false);
1056+
expect(resultQuery.data).toEqual(peopleData3);
10641057
}
10651058
count++;
10661059
} catch (err) {
@@ -1081,7 +1074,7 @@ describe('General Mutation testing', () => {
10811074
);
10821075

10831076
waitFor(() => {
1084-
expect(count).toBe(9);
1077+
expect(count).toEqual(8);
10851078
}).then(resolve, reject);
10861079
}));
10871080

src/react/components/__tests__/client/Query.test.tsx

Lines changed: 27 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1229,11 +1229,7 @@ describe('Query component', () => {
12291229
const { variables } = this.state;
12301230

12311231
return (
1232-
<AllPeopleQuery
1233-
query={query}
1234-
variables={variables}
1235-
notifyOnNetworkStatusChange={true}
1236-
>
1232+
<AllPeopleQuery query={query} variables={variables}>
12371233
{(result: any) => {
12381234
try {
12391235
switch (count) {
@@ -1721,40 +1717,35 @@ describe('Query component', () => {
17211717
<AllPeopleQuery
17221718
query={query}
17231719
variables={variables}
1724-
notifyOnNetworkStatusChange={true}
17251720
onCompleted={this.onCompleted}
17261721
>
17271722
{({ loading, data }: any) => {
1728-
try {
1729-
switch (renderCount) {
1730-
case 0:
1731-
expect(loading).toBe(true);
1732-
break;
1733-
case 1:
1734-
case 2:
1735-
expect(loading).toBe(false);
1736-
expect(data).toEqual(data1);
1737-
break;
1738-
case 3:
1739-
expect(loading).toBe(true);
1740-
break;
1741-
case 4:
1742-
expect(loading).toBe(false);
1743-
expect(data).toEqual(data2);
1744-
setTimeout(() => {
1745-
this.setState({ variables: { first: 1 } });
1746-
});
1747-
case 5:
1748-
expect(loading).toBe(false);
1749-
expect(data).toEqual(data2);
1750-
break;
1751-
case 6:
1752-
expect(loading).toBe(false);
1753-
expect(data).toEqual(data1);
1754-
break;
1755-
}
1756-
} catch (err) {
1757-
reject(err);
1723+
switch (renderCount) {
1724+
case 0:
1725+
expect(loading).toBe(true);
1726+
break;
1727+
case 1:
1728+
case 2:
1729+
expect(loading).toBe(false);
1730+
expect(data).toEqual(data1);
1731+
break;
1732+
case 3:
1733+
expect(loading).toBe(true);
1734+
break;
1735+
case 4:
1736+
expect(loading).toBe(false);
1737+
expect(data).toEqual(data2);
1738+
setTimeout(() => {
1739+
this.setState({ variables: { first: 1 } });
1740+
});
1741+
case 5:
1742+
expect(loading).toBe(false);
1743+
expect(data).toEqual(data2);
1744+
break;
1745+
case 6:
1746+
expect(loading).toBe(false);
1747+
expect(data).toEqual(data1);
1748+
break;
17581749
}
17591750
renderCount += 1;
17601751
return null;
@@ -1771,7 +1762,6 @@ describe('Query component', () => {
17711762
);
17721763

17731764
waitFor(() => {
1774-
expect(renderCount).toBe(7);
17751765
expect(onCompletedCallCount).toBe(3);
17761766
}).then(resolve, reject);
17771767
});

src/react/components/__tests__/ssr/getDataFromTree.test.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/** @jest-environment node */
21
import React from 'react';
32
import gql from 'graphql-tag';
43
import { DocumentNode } from 'graphql';

src/react/components/__tests__/ssr/server.test.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/** @jest-environment node */
21
import React from 'react';
32
import {
43
print,

src/react/hoc/__tests__/queries/errors.test.tsx

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -216,10 +216,7 @@ describe('[queries] errors', () => {
216216
let iteration = 0;
217217
let done = false;
218218
const ErrorContainer = withState('var', 'setVar', 1)(
219-
graphql<Props, Data, Vars>(
220-
query,
221-
{ options: { notifyOnNetworkStatusChange: true }},
222-
)(
219+
graphql<Props, Data, Vars>(query)(
223220
class extends React.Component<ChildProps<Props, Data, Vars>> {
224221
componentDidUpdate() {
225222
const { props } = this;
@@ -237,7 +234,7 @@ describe('[queries] errors', () => {
237234
);
238235
} else if (iteration === 3) {
239236
// variables have changed, wee are loading again but also have data
240-
expect(props.data!.loading).toBe(true);
237+
expect(props.data!.loading).toBeTruthy();
241238
} else if (iteration === 4) {
242239
// the second request had an error!
243240
expect(props.data!.error).toBeTruthy();
@@ -259,8 +256,8 @@ describe('[queries] errors', () => {
259256
render() {
260257
return null;
261258
}
262-
},
263-
),
259+
}
260+
)
264261
);
265262

266263
render(
@@ -473,11 +470,9 @@ describe('[queries] errors', () => {
473470
});
474471
break;
475472
case 3:
476-
// Second render was added by useSyncExternalStore changes...
477-
case 4:
478473
expect(props.data!.loading).toBeTruthy();
479474
break;
480-
case 5:
475+
case 4:
481476
expect(props.data!.loading).toBeFalsy();
482477
expect(props.data!.error).toBeFalsy();
483478
expect(props.data!.allPeople).toEqual(
@@ -504,7 +499,7 @@ describe('[queries] errors', () => {
504499
</ApolloProvider>
505500
);
506501

507-
waitFor(() => expect(count).toBe(6)).then(resolve, reject);
502+
waitFor(() => expect(count).toBe(5)).then(resolve, reject);
508503
});
509504

510505
itAsync('does not throw/console.err an error after a component that received a network error is unmounted', (resolve, reject) => {

0 commit comments

Comments
 (0)