Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import { useModificationsSelection } from './use-modifications-selection';
import {
fetchSubModificationsForExpandedRows,
findAllLoadedCompositeModifications,
findAllLoadedReferenceModifications,
findDepth,
formatToComposedModification,
isCompositeModification,
Expand Down Expand Up @@ -155,19 +156,19 @@ export function NetworkModificationsTable({
);
setComposedModifications(nextMods);

// Re-fetch authoritative children for every composite that already had loaded children,
// correcting anything stale that was temporarily preserved above.
// Re-fetch authoritative children for every composite AND reference that already had
// loaded children, correcting anything stale that was temporarily preserved above.
// References matter here because a shared-element update changes the referenced
// composite's content while the reference row stays expanded.
// Source of truth: prevMods — nextMods children may have been filtered just above.
// The rowKeys collected here are still valid in nextMods since the merge above preserved them.
const loadedComposites: ComposedModificationMetadata[] = [];
findAllLoadedCompositeModifications(prevMods, loadedComposites);
if (loadedComposites.length > 0) {
fetchSubModificationsForExpandedRows(
loadedComposites.map((m) => m.rowKey),
nextMods,
setComposedModifications,
true
);
const loadedReferences: ComposedModificationMetadata[] = [];
findAllLoadedReferenceModifications(prevMods, loadedReferences);
const expandedRowKeysToRefresh = [...loadedComposites, ...loadedReferences].map((m) => m.rowKey);
if (expandedRowKeysToRefresh.length > 0) {
fetchSubModificationsForExpandedRows(expandedRowKeysToRefresh, nextMods, setComposedModifications, true);
}
}, [modifications]);

Expand Down
22 changes: 22 additions & 0 deletions src/features/network-modification-table/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,28 @@ export function findAllLoadedCompositeModifications(
});
}

/**
* Collects every reference modification whose children are already loaded, at any depth
* (a reference can be nested inside an expanded composite). Unlike
* {@link findAllLoadedCompositeModifications}, recursion does not stop on non-matching
* nodes since a reference's ancestors are usually composites.
* @param modifications source where the reference modifications are looked for
* @param references result : all the loaded reference modifications found
*/
export function findAllLoadedReferenceModifications(
modifications: ComposedModificationMetadata[],
references: ComposedModificationMetadata[]
) {
modifications.forEach((modification) => {
if (modification.subModifications.length > 0) {
if (isReferenceModification(modification)) {
references.push(modification);
}
findAllLoadedReferenceModifications(modification.subModifications, references);
}
});
}

export function findModificationInTree(
rowKey: UUID,
mods: ComposedModificationMetadata[]
Expand Down
Loading