Skip to content

Commit

Permalink
Merge pull request #220 from bento-platform/fix/double-loading-flicker
Browse files Browse the repository at this point in the history
fix: double loading/counts flicker for overview
  • Loading branch information
davidlougheed authored Nov 13, 2024
2 parents d62987f + 6efe6ab commit 9088195
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/js/components/BentoAppRouter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,19 @@ const ScopedRoute = () => {
const { projectId, datasetId } = useParams();
const dispatch = useAppDispatch();
const navigate = useNavigate();
const { selectedScope, projects } = useMetadata();
const { selectedScope, projects, projectsStatus } = useMetadata();

useEffect(() => {
if ([RequestStatus.Idle, RequestStatus.Pending].includes(projectsStatus)) return; // Wait for projects to load first

// Update selectedScope based on URL parameters
const valid = validProjectDataset(projects, { project: projectId, dataset: datasetId });

// Don't change the scope object if the scope value is the same, otherwise it'll trigger needless re-renders.
if (scopeEqual(selectedScope.scope, valid.scope)) {
// Make sure scope is marked as set to trigger the first load.
// This can happen when the true URL scope is the whole instance, which is also the initial scope value.
dispatch(markScopeSet());
if (!selectedScope.scopeSet) dispatch(markScopeSet());
return;
}

Expand All @@ -68,7 +70,7 @@ const ScopedRoute = () => {
}
const newPathString = '/' + newPath.join('/');
navigate(newPathString, { replace: true });
}, [projects, projectId, datasetId, dispatch, navigate, selectedScope]);
}, [projects, projectsStatus, projectId, datasetId, dispatch, navigate, selectedScope]);

return <Outlet />;
};
Expand Down

0 comments on commit 9088195

Please sign in to comment.