houdini-react 2.0.0-next.1 → 2.0.0-next.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -87469,20 +87469,21 @@ var CacheInternal = class {
87469
87469
  } else if (Array.isArray(value) && // make typescript happy
87470
87470
  (typeof previousValue === "undefined" || previousValue === null || Array.isArray(previousValue))) {
87471
87471
  let oldIDs = [...previousValue || []];
87472
- const emptyEdges = !updates ? [] : oldIDs.map((id) => {
87473
- if (!id) {
87474
- return "";
87475
- }
87476
- const { value: cursorField } = this.storage.get(id, "cursor");
87477
- if (cursorField) {
87478
- return "";
87479
- }
87480
- const { value: node } = this.storage.get(id, "node");
87481
- if (!node) {
87482
- return "";
87483
- }
87484
- return node;
87485
- });
87472
+ if (updates?.includes("append") || updates?.includes("prepend")) {
87473
+ oldIDs = oldIDs.filter((id) => {
87474
+ for (const layer2 of this.storage.data) {
87475
+ for (const operation of Object.values(layer2.operations)) {
87476
+ if (operation.fields?.[key])
87477
+ for (const listOperation of operation.fields[key]) {
87478
+ if ("id" in listOperation && listOperation.id === id) {
87479
+ return false;
87480
+ }
87481
+ }
87482
+ }
87483
+ }
87484
+ return true;
87485
+ });
87486
+ }
87486
87487
  let linkedIDs = [];
87487
87488
  const { newIDs, nestedIDs } = this.extractNestedListIDs({
87488
87489
  value,
@@ -87501,39 +87502,45 @@ var CacheInternal = class {
87501
87502
  layer.writeLink(parent, key, linkedIDs);
87502
87503
  };
87503
87504
  if (applyUpdates && updates) {
87504
- if (key === "edges") {
87505
- const newNodeIDs = [];
87506
- for (const id of newIDs) {
87505
+ const filterIDs = (keep, insert) => {
87506
+ const existingIDs = /* @__PURE__ */ new Set();
87507
+ for (const id of keep) {
87507
87508
  if (!id) {
87508
87509
  continue;
87509
87510
  }
87510
87511
  const { value: node } = this.storage.get(id, "node");
87511
- if (typeof node !== "string") {
87512
+ if (!node) {
87512
87513
  continue;
87513
87514
  }
87514
- if (!node || !this.storage.get(node, "__typename")) {
87515
+ const nodeID = this.storage.get(node, "id");
87516
+ if (!nodeID) {
87515
87517
  continue;
87516
87518
  }
87517
- newNodeIDs.push(node);
87519
+ existingIDs.add(nodeID.value);
87518
87520
  }
87519
- oldIDs = oldIDs.filter((id) => {
87521
+ return insert.filter((id) => {
87520
87522
  if (!id) {
87521
87523
  return true;
87522
87524
  }
87523
- const { value: value2 } = this.storage.get(id, "node");
87524
- const node = value2;
87525
- if (newNodeIDs.includes(node) && emptyEdges.includes(node)) {
87526
- return false;
87525
+ const { value: node } = this.storage.get(id, "node");
87526
+ if (!node) {
87527
+ return true;
87527
87528
  }
87528
- return true;
87529
+ const nodeID = this.storage.get(node, "id");
87530
+ if (!nodeID) {
87531
+ return true;
87532
+ }
87533
+ return !existingIDs.has(nodeID.value);
87529
87534
  });
87530
- }
87535
+ };
87531
87536
  for (const update of applyUpdates) {
87532
87537
  if (update !== "replace" && !updates.includes(update)) {
87533
87538
  continue;
87534
87539
  }
87535
87540
  if (update === "prepend") {
87536
- linkedIDs = newIDs.concat(oldIDs);
87541
+ linkedIDs = newIDs.concat(
87542
+ filterIDs(newIDs, oldIDs)
87543
+ );
87537
87544
  if (layer?.optimistic) {
87538
87545
  action = () => {
87539
87546
  for (const id of newIDs) {
@@ -87544,7 +87551,7 @@ var CacheInternal = class {
87544
87551
  };
87545
87552
  }
87546
87553
  } else if (update === "append") {
87547
- linkedIDs = oldIDs.concat(newIDs);
87554
+ linkedIDs = filterIDs(newIDs, oldIDs).concat(newIDs);
87548
87555
  if (layer?.optimistic) {
87549
87556
  action = () => {
87550
87557
  for (const id of newIDs) {
@@ -87465,20 +87465,21 @@ var CacheInternal = class {
87465
87465
  } else if (Array.isArray(value) && // make typescript happy
87466
87466
  (typeof previousValue === "undefined" || previousValue === null || Array.isArray(previousValue))) {
87467
87467
  let oldIDs = [...previousValue || []];
87468
- const emptyEdges = !updates ? [] : oldIDs.map((id) => {
87469
- if (!id) {
87470
- return "";
87471
- }
87472
- const { value: cursorField } = this.storage.get(id, "cursor");
87473
- if (cursorField) {
87474
- return "";
87475
- }
87476
- const { value: node } = this.storage.get(id, "node");
87477
- if (!node) {
87478
- return "";
87479
- }
87480
- return node;
87481
- });
87468
+ if (updates?.includes("append") || updates?.includes("prepend")) {
87469
+ oldIDs = oldIDs.filter((id) => {
87470
+ for (const layer2 of this.storage.data) {
87471
+ for (const operation of Object.values(layer2.operations)) {
87472
+ if (operation.fields?.[key])
87473
+ for (const listOperation of operation.fields[key]) {
87474
+ if ("id" in listOperation && listOperation.id === id) {
87475
+ return false;
87476
+ }
87477
+ }
87478
+ }
87479
+ }
87480
+ return true;
87481
+ });
87482
+ }
87482
87483
  let linkedIDs = [];
87483
87484
  const { newIDs, nestedIDs } = this.extractNestedListIDs({
87484
87485
  value,
@@ -87497,39 +87498,45 @@ var CacheInternal = class {
87497
87498
  layer.writeLink(parent, key, linkedIDs);
87498
87499
  };
87499
87500
  if (applyUpdates && updates) {
87500
- if (key === "edges") {
87501
- const newNodeIDs = [];
87502
- for (const id of newIDs) {
87501
+ const filterIDs = (keep, insert) => {
87502
+ const existingIDs = /* @__PURE__ */ new Set();
87503
+ for (const id of keep) {
87503
87504
  if (!id) {
87504
87505
  continue;
87505
87506
  }
87506
87507
  const { value: node } = this.storage.get(id, "node");
87507
- if (typeof node !== "string") {
87508
+ if (!node) {
87508
87509
  continue;
87509
87510
  }
87510
- if (!node || !this.storage.get(node, "__typename")) {
87511
+ const nodeID = this.storage.get(node, "id");
87512
+ if (!nodeID) {
87511
87513
  continue;
87512
87514
  }
87513
- newNodeIDs.push(node);
87515
+ existingIDs.add(nodeID.value);
87514
87516
  }
87515
- oldIDs = oldIDs.filter((id) => {
87517
+ return insert.filter((id) => {
87516
87518
  if (!id) {
87517
87519
  return true;
87518
87520
  }
87519
- const { value: value2 } = this.storage.get(id, "node");
87520
- const node = value2;
87521
- if (newNodeIDs.includes(node) && emptyEdges.includes(node)) {
87522
- return false;
87521
+ const { value: node } = this.storage.get(id, "node");
87522
+ if (!node) {
87523
+ return true;
87523
87524
  }
87524
- return true;
87525
+ const nodeID = this.storage.get(node, "id");
87526
+ if (!nodeID) {
87527
+ return true;
87528
+ }
87529
+ return !existingIDs.has(nodeID.value);
87525
87530
  });
87526
- }
87531
+ };
87527
87532
  for (const update of applyUpdates) {
87528
87533
  if (update !== "replace" && !updates.includes(update)) {
87529
87534
  continue;
87530
87535
  }
87531
87536
  if (update === "prepend") {
87532
- linkedIDs = newIDs.concat(oldIDs);
87537
+ linkedIDs = newIDs.concat(
87538
+ filterIDs(newIDs, oldIDs)
87539
+ );
87533
87540
  if (layer?.optimistic) {
87534
87541
  action = () => {
87535
87542
  for (const id of newIDs) {
@@ -87540,7 +87547,7 @@ var CacheInternal = class {
87540
87547
  };
87541
87548
  }
87542
87549
  } else if (update === "append") {
87543
- linkedIDs = oldIDs.concat(newIDs);
87550
+ linkedIDs = filterIDs(newIDs, oldIDs).concat(newIDs);
87544
87551
  if (layer?.optimistic) {
87545
87552
  action = () => {
87546
87553
  for (const id of newIDs) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "houdini-react",
3
- "version": "2.0.0-next.1",
3
+ "version": "2.0.0-next.2",
4
4
  "description": "The React plugin for houdini",
5
5
  "keywords": [
6
6
  "typescript",
@@ -42,7 +42,7 @@
42
42
  "recast": "^0.23.1",
43
43
  "rollup": "^4.39.0",
44
44
  "use-deep-compare-effect": "^1.8.1",
45
- "houdini": "^2.0.0-next.1"
45
+ "houdini": "^2.0.0-next.2"
46
46
  },
47
47
  "files": [
48
48
  "build"