Skip to content

Commit

Permalink
chore: be more strict in the add/remove-logic
Browse files Browse the repository at this point in the history
It's a miracle this worked before
  • Loading branch information
haakonflatval-cognite committed Sep 12, 2024
1 parent 06c687b commit e56a844
Showing 1 changed file with 2 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export function CadModelContainer({

useApplyCadModelStyling(model, styling);

useEffect(() => removeModel, [model]);
useEffect(() => () => removeModel(model), [model]);

return <></>;

Expand Down Expand Up @@ -96,15 +96,14 @@ export function CadModelContainer({
}
}

function removeModel(): void {
function removeModel(model: CogniteCadModel | undefined): void {
if (!modelExists(model, viewer)) return;

if (cachedViewerRef !== undefined && !cachedViewerRef.isRevealContainerMountedRef.current)
return;

viewer.removeModel(model);
setRevealResourcesCount(getViewerResourceCount(viewer));
setModel(undefined);
}
}

Expand Down

0 comments on commit e56a844

Please sign in to comment.