Skip to content

Commit 402fbad

Browse files
committed
Fix dirty mid-computation when truncate was changed causing stale refs
1 parent ad30c99 commit 402fbad

2 files changed

Lines changed: 16 additions & 34 deletions

File tree

src/cache/inmemory/__tests__/cache.diff/incremental.test.ts

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2985,7 +2985,7 @@ test("returns the truncated stream array with complete items when truncation is
29852985
});
29862986
});
29872987

2988-
test("invalidates a pruned stream array when truncation state changes", () => {
2988+
test("invalidates a pruned stream array when the stream position changes", () => {
29892989
const cache = new InMemoryCache();
29902990
const query = gql`
29912991
query {
@@ -2999,16 +2999,19 @@ test("invalidates a pruned stream array when truncation state changes", () => {
29992999
const streamEntry = streamInfo.lookupArray(["friendList"]);
30003000
streamEntry.state.streamPosition = 1;
30013001

3002-
cache.writeQuery({
3003-
query,
3004-
data: {
3005-
friendList: [
3006-
{ __typename: "Friend", id: "1", name: "Luke" },
3007-
{ __typename: "Friend", id: "2", name: "Han" },
3008-
{ __typename: "Friend", id: "3", name: "Leia" },
3009-
],
3010-
},
3011-
});
3002+
{
3003+
using _ = spyOnConsole("error");
3004+
cache.writeQuery({
3005+
query,
3006+
data: {
3007+
friendList: [
3008+
{ __typename: "Friend", id: "1", name: "Luke" },
3009+
{ __typename: "Friend", id: "2", name: "Han" },
3010+
{ __typename: "Friend", id: "3" },
3011+
],
3012+
},
3013+
});
3014+
}
30123015

30133016
const diff = () =>
30143017
cache.diff({
@@ -3018,16 +3021,6 @@ test("invalidates a pruned stream array when truncation state changes", () => {
30183021
[handleIncrementalSymbol]: { streamInfo },
30193022
});
30203023

3021-
expect(diff().result).toStrictEqualTyped({
3022-
friendList: [
3023-
{ __typename: "Friend", id: "1", name: "Luke" },
3024-
{ __typename: "Friend", id: "2", name: "Han" },
3025-
{ __typename: "Friend", id: "3", name: "Leia" },
3026-
],
3027-
});
3028-
3029-
streamEntry.state.truncate = true;
3030-
30313024
expect(diff().result).toStrictEqualTyped({
30323025
friendList: [{ __typename: "Friend", id: "1", name: "Luke" }],
30333026
});

src/utilities/internal/StreamArrayState.ts

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import { dep } from "optimism";
33
import type { Incremental } from "@apollo/client/incremental";
44

55
export class StreamArrayState {
6-
private _streamPosition = 0;
7-
private _truncate = false;
6+
truncate = false;
87

8+
private _streamPosition = 0;
99
private path: Incremental.Path;
1010
private dep = dep<Incremental.Path>();
1111

@@ -28,17 +28,6 @@ export class StreamArrayState {
2828
}
2929
}
3030

31-
get truncate() {
32-
return this._truncate;
33-
}
34-
35-
set truncate(value) {
36-
if (value !== this._truncate) {
37-
this._truncate = value;
38-
this.dirty();
39-
}
40-
}
41-
4231
private dirty() {
4332
this.dep.dirty(this.path);
4433
}

0 commit comments

Comments
 (0)