the scope fallback will cause false positive on tenant access assertion, thus an accessible tenant will be removed from the list. sometimes isLoading may be false but the data is not loaded.
Original
const { scopes = [], isLoading } = useCurrentTenantScopes(); // `scopes` falls back to an empty array
useEffect(() => {
// `scopes` may not be loaded at all, which is `undefined` in the return of `useCurrentTenantScopes()`.
// However, the fallback value `[]` will be used here, while the fetching process is not started yet
// (`isLoading` is `false`) which causes a false positive.
if (isCloud && !isLoading && scopes.length === 0) {
removeTenant(currentTenantId);
navigateTenant('');
}
}, [currentTenantId, isLoading, navigateTenant, removeTenant, scopes.length]);
Now
// No fallback. Everyone should be happy now.
const { scopes, isLoading } = useCurrentTenantScopes();
useEffect(() => {
// When `scopes` is `undefined`, the `scopes?.length === 0` expression will be `false`
if (isCloud && !isLoading && scopes?.length === 0) {
removeTenant(currentTenantId);
navigateTenant('');
}
}, [currentTenantId, isLoading, navigateTenant, removeTenant, scopes?.length]);
Summary
the
scope
fallback will cause false positive on tenant access assertion, thus an accessible tenant will be removed from the list. sometimesisLoading
may befalse
but the data is not loaded.Original
Now
Testing
cloud tests ok
Checklist
.changeset