Skip to content

[dashboard] Avoid re-rendering the whole App on Org load #16976

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

Merged
merged 2 commits into from
Mar 22, 2023
Merged
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
15 changes: 8 additions & 7 deletions components/dashboard/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,18 @@ const App: FunctionComponent = () => {
if (!user) {
return <Login />;
}
// TODO(gpl) "isLoading" is "true" even if there are errors in this "useCurrentOrg" call.
// Why don't understand as to why .isLoading is not resolved at some point, though. Maybe we're missing proper error handling for useOrganizations
// if (currentOrgQuery.isLoading) {
// return <AppLoading />;
// }

// At this point we want to make sure that we never render AppRoutes prematurely, e.g. without finishing loading the orgs
// This would cause us to re-render the whole App again soon after, creating havoc with all our "onMount" hooks.
if (currentOrgQuery.isLoading) {
return <AppLoading />;
}

// If we made it here, we have a logged in user w/ their teams. Yay.
return (
<Suspense fallback={<AppLoading />}>
{/* Use org id as key to force re-render on org change */}
<AppRoutes key={currentOrgQuery.data?.id ?? "no-org"} />
{/* Use org id, or user id (for personal account) as key to force re-render on org change */}
<AppRoutes key={currentOrgQuery?.data?.id ?? user.id} />
</Suspense>
);
};
Expand Down