Skip to content

Commit

Permalink
Fix issues with descendants and allDescendants (#3728)
Browse files Browse the repository at this point in the history
  • Loading branch information
lbwexler authored Jul 22, 2024
1 parent 066dc52 commit d96cd99
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
* Enhanced `markdown` component to support the underlying `components` prop from
`react-markdown`. Use this prop to customize markdown rendering.

### 🐞 Bug Fixes
* The `Record.descendants` and `Record.allDescendants` getters were incorrectly returning the
record itself. This has been fixed.

## 66.0.2 - 2024-07-17

### 🐞 Bug Fixes
Expand Down
14 changes: 7 additions & 7 deletions data/impl/RecordSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ export class RecordSet {
this.store.logDebug(`Attempted to remove non-existent record: ${id}`);
return;
}
allRemoves.add(id);
this.gatherDescendantIds(id, allRemoves);
});
allRemoves.forEach(it => newRecords.delete(it));
Expand Down Expand Up @@ -273,14 +274,13 @@ export class RecordSet {
}

private gatherDescendantIds(id: StoreRecordId, idSet: Set<StoreRecordId>): Set<StoreRecordId> {
if (!idSet.has(id)) {
idSet.add(id);
const children = this.childrenMap.get(id);
if (children) {
children.forEach(child => this.gatherDescendantIds(child.id, idSet));
this.childrenMap.get(id)?.forEach(child => {
if (!idSet.has(child.id)) {
// paranoia? did we encounter loops?
idSet.add(child.id);
this.gatherDescendantIds(child.id, idSet);
}
}

});
return idSet;
}
}

0 comments on commit d96cd99

Please sign in to comment.