houdini-react 1.3.11 → 1.3.12

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.
@@ -81647,20 +81647,21 @@ var CacheInternal = class {
81647
81647
  }
81648
81648
  } else if (Array.isArray(value) && (typeof previousValue === "undefined" || previousValue === null || Array.isArray(previousValue))) {
81649
81649
  let oldIDs = [...previousValue || []];
81650
- const emptyEdges = !updates ? [] : oldIDs.map((id) => {
81651
- if (!id) {
81652
- return "";
81653
- }
81654
- const { value: cursorField } = this.storage.get(id, "cursor");
81655
- if (cursorField) {
81656
- return "";
81657
- }
81658
- const { value: node } = this.storage.get(id, "node");
81659
- if (!node) {
81660
- return "";
81661
- }
81662
- return node;
81663
- });
81650
+ if (updates?.includes("append") || updates?.includes("prepend")) {
81651
+ oldIDs = oldIDs.filter((id) => {
81652
+ for (const layer2 of this.storage.data) {
81653
+ for (const operation of Object.values(layer2.operations)) {
81654
+ if (operation.fields?.[key])
81655
+ for (const listOperation of operation.fields[key]) {
81656
+ if ("id" in listOperation && listOperation.id === id) {
81657
+ return false;
81658
+ }
81659
+ }
81660
+ }
81661
+ }
81662
+ return true;
81663
+ });
81664
+ }
81664
81665
  let linkedIDs = [];
81665
81666
  const { newIDs, nestedIDs } = this.extractNestedListIDs({
81666
81667
  value,
@@ -81679,39 +81680,45 @@ var CacheInternal = class {
81679
81680
  layer.writeLink(parent, key, linkedIDs);
81680
81681
  };
81681
81682
  if (applyUpdates && updates) {
81682
- if (key === "edges") {
81683
- const newNodeIDs = [];
81684
- for (const id of newIDs) {
81683
+ const filterIDs = (keep, insert) => {
81684
+ const existingIDs = /* @__PURE__ */ new Set();
81685
+ for (const id of keep) {
81685
81686
  if (!id) {
81686
81687
  continue;
81687
81688
  }
81688
81689
  const { value: node } = this.storage.get(id, "node");
81689
- if (typeof node !== "string") {
81690
+ if (!node) {
81690
81691
  continue;
81691
81692
  }
81692
- if (!node || !this.storage.get(node, "__typename")) {
81693
+ const nodeID = this.storage.get(node, "id");
81694
+ if (!nodeID) {
81693
81695
  continue;
81694
81696
  }
81695
- newNodeIDs.push(node);
81697
+ existingIDs.add(nodeID.value);
81696
81698
  }
81697
- oldIDs = oldIDs.filter((id) => {
81699
+ return insert.filter((id) => {
81698
81700
  if (!id) {
81699
81701
  return true;
81700
81702
  }
81701
- const { value: value2 } = this.storage.get(id, "node");
81702
- const node = value2;
81703
- if (newNodeIDs.includes(node) && emptyEdges.includes(node)) {
81704
- return false;
81703
+ const { value: node } = this.storage.get(id, "node");
81704
+ if (!node) {
81705
+ return true;
81705
81706
  }
81706
- return true;
81707
+ const nodeID = this.storage.get(node, "id");
81708
+ if (!nodeID) {
81709
+ return true;
81710
+ }
81711
+ return !existingIDs.has(nodeID.value);
81707
81712
  });
81708
- }
81713
+ };
81709
81714
  for (const update of applyUpdates) {
81710
81715
  if (update !== "replace" && !updates.includes(update)) {
81711
81716
  continue;
81712
81717
  }
81713
81718
  if (update === "prepend") {
81714
- linkedIDs = newIDs.concat(oldIDs);
81719
+ linkedIDs = newIDs.concat(
81720
+ filterIDs(newIDs, oldIDs)
81721
+ );
81715
81722
  if (layer?.optimistic) {
81716
81723
  action = () => {
81717
81724
  for (const id of newIDs) {
@@ -81722,7 +81729,7 @@ var CacheInternal = class {
81722
81729
  };
81723
81730
  }
81724
81731
  } else if (update === "append") {
81725
- linkedIDs = oldIDs.concat(newIDs);
81732
+ linkedIDs = filterIDs(newIDs, oldIDs).concat(newIDs);
81726
81733
  if (layer?.optimistic) {
81727
81734
  action = () => {
81728
81735
  for (const id of newIDs) {
@@ -81639,20 +81639,21 @@ var CacheInternal = class {
81639
81639
  }
81640
81640
  } else if (Array.isArray(value) && (typeof previousValue === "undefined" || previousValue === null || Array.isArray(previousValue))) {
81641
81641
  let oldIDs = [...previousValue || []];
81642
- const emptyEdges = !updates ? [] : oldIDs.map((id) => {
81643
- if (!id) {
81644
- return "";
81645
- }
81646
- const { value: cursorField } = this.storage.get(id, "cursor");
81647
- if (cursorField) {
81648
- return "";
81649
- }
81650
- const { value: node } = this.storage.get(id, "node");
81651
- if (!node) {
81652
- return "";
81653
- }
81654
- return node;
81655
- });
81642
+ if (updates?.includes("append") || updates?.includes("prepend")) {
81643
+ oldIDs = oldIDs.filter((id) => {
81644
+ for (const layer2 of this.storage.data) {
81645
+ for (const operation of Object.values(layer2.operations)) {
81646
+ if (operation.fields?.[key])
81647
+ for (const listOperation of operation.fields[key]) {
81648
+ if ("id" in listOperation && listOperation.id === id) {
81649
+ return false;
81650
+ }
81651
+ }
81652
+ }
81653
+ }
81654
+ return true;
81655
+ });
81656
+ }
81656
81657
  let linkedIDs = [];
81657
81658
  const { newIDs, nestedIDs } = this.extractNestedListIDs({
81658
81659
  value,
@@ -81671,39 +81672,45 @@ var CacheInternal = class {
81671
81672
  layer.writeLink(parent, key, linkedIDs);
81672
81673
  };
81673
81674
  if (applyUpdates && updates) {
81674
- if (key === "edges") {
81675
- const newNodeIDs = [];
81676
- for (const id of newIDs) {
81675
+ const filterIDs = (keep, insert) => {
81676
+ const existingIDs = /* @__PURE__ */ new Set();
81677
+ for (const id of keep) {
81677
81678
  if (!id) {
81678
81679
  continue;
81679
81680
  }
81680
81681
  const { value: node } = this.storage.get(id, "node");
81681
- if (typeof node !== "string") {
81682
+ if (!node) {
81682
81683
  continue;
81683
81684
  }
81684
- if (!node || !this.storage.get(node, "__typename")) {
81685
+ const nodeID = this.storage.get(node, "id");
81686
+ if (!nodeID) {
81685
81687
  continue;
81686
81688
  }
81687
- newNodeIDs.push(node);
81689
+ existingIDs.add(nodeID.value);
81688
81690
  }
81689
- oldIDs = oldIDs.filter((id) => {
81691
+ return insert.filter((id) => {
81690
81692
  if (!id) {
81691
81693
  return true;
81692
81694
  }
81693
- const { value: value2 } = this.storage.get(id, "node");
81694
- const node = value2;
81695
- if (newNodeIDs.includes(node) && emptyEdges.includes(node)) {
81696
- return false;
81695
+ const { value: node } = this.storage.get(id, "node");
81696
+ if (!node) {
81697
+ return true;
81697
81698
  }
81698
- return true;
81699
+ const nodeID = this.storage.get(node, "id");
81700
+ if (!nodeID) {
81701
+ return true;
81702
+ }
81703
+ return !existingIDs.has(nodeID.value);
81699
81704
  });
81700
- }
81705
+ };
81701
81706
  for (const update of applyUpdates) {
81702
81707
  if (update !== "replace" && !updates.includes(update)) {
81703
81708
  continue;
81704
81709
  }
81705
81710
  if (update === "prepend") {
81706
- linkedIDs = newIDs.concat(oldIDs);
81711
+ linkedIDs = newIDs.concat(
81712
+ filterIDs(newIDs, oldIDs)
81713
+ );
81707
81714
  if (layer?.optimistic) {
81708
81715
  action = () => {
81709
81716
  for (const id of newIDs) {
@@ -81714,7 +81721,7 @@ var CacheInternal = class {
81714
81721
  };
81715
81722
  }
81716
81723
  } else if (update === "append") {
81717
- linkedIDs = oldIDs.concat(newIDs);
81724
+ linkedIDs = filterIDs(newIDs, oldIDs).concat(newIDs);
81718
81725
  if (layer?.optimistic) {
81719
81726
  action = () => {
81720
81727
  for (const id of newIDs) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "houdini-react",
3
- "version": "1.3.11",
3
+ "version": "1.3.12",
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.28.1",
44
44
  "use-deep-compare-effect": "^1.8.1",
45
- "houdini": "^1.5.7"
45
+ "houdini": "^1.5.8"
46
46
  },
47
47
  "files": [
48
48
  "build"