Skip to content

Commit

Permalink
fix: race condition in snapshot browser
Browse files Browse the repository at this point in the history
  • Loading branch information
garethgeorge committed Dec 20, 2023
1 parent fe92b62 commit f239b91
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions webui/src/components/SnapshotBrowser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,31 +109,31 @@ export const SnapshotBrowser = ({
},
{ pathPrefix: "/api" }
);

let toUpdate: DataNode | null = null;
for (const node of treeData) {
toUpdate = findInTree(node, key as string);
if (toUpdate) {
break;

setTreeData((treeData) => {
let toUpdate: DataNode | null = null;
for (const node of treeData) {
toUpdate = findInTree(node, key as string);
if (toUpdate) {
break;
}
}
}

if (!toUpdate) {
return;
}

const toUpdateCopy = { ...toUpdate };
toUpdateCopy.children = respToNodes(resp);

const newTree = treeData.map((node) => {
const didUpdate = replaceKeyInTree(node, key as string, toUpdateCopy);
if (didUpdate) {
return didUpdate;

if (!toUpdate) {
return treeData;
}
return node;

const toUpdateCopy = { ...toUpdate };
toUpdateCopy.children = respToNodes(resp);

return treeData.map((node) => {
const didUpdate = replaceKeyInTree(node, key as string, toUpdateCopy);
if (didUpdate) {
return didUpdate;
}
return node;
});
});

setTreeData(newTree);
};

return (
Expand Down

0 comments on commit f239b91

Please sign in to comment.