Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issues with descendants and allDescendants #3728

Merged
merged 1 commit into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah interesting - there is a chance there is some code out there that was depending on the prior behavior (intentionally or not), but hard to argue that it was correct. This looks like the right choice / fix to me.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree that this change makes sense - previous behavior was definitely confusing - I vaguely remember this from when we were re-working these methods way back but can't remember why we included the record in the list of descendants


## 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?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this came in a while ago with a big refactor that introduced many of these recordset APIs - doesn't look like a response to a particular bug or use case.

https://github.com/xh/hoist-react/pull/1082/files

(FWIW - I'd still vote to carry it forward - will cop to a certain amount of paranoia in these classes myself)

idSet.add(child.id);
this.gatherDescendantIds(child.id, idSet);
}
}

});
return idSet;
}
}
Loading