Skip to content

Commit 108bb13

Browse files
authored
feat(issues): Preserve group when switching environment (#82907)
1 parent dc029c9 commit 108bb13

File tree

1 file changed

+39
-8
lines changed

1 file changed

+39
-8
lines changed

static/app/views/issueDetails/groupDetails.tsx

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {Fragment, useCallback, useEffect, useState} from 'react';
22
import styled from '@emotion/styled';
33
import * as Sentry from '@sentry/react';
4+
import isEqual from 'lodash/isEqual';
45
import * as qs from 'query-string';
56

67
import FloatingFeedbackWidget from 'sentry/components/feedback/widget/floatingFeedbackWidget';
@@ -263,7 +264,43 @@ function useFetchGroupDetails(): FetchGroupDetailsState {
263264
[event]
264265
);
265266

266-
const group = groupData ?? null;
267+
// If the environment changes, we need to refetch the group, but we can
268+
// still display the previous group while the new group is loading.
269+
const previousGroupData = useMemoWithPrevious<{
270+
cachedGroup: typeof groupData | null;
271+
previousEnvironments: typeof environments | null;
272+
previousGroupData: typeof groupData | null;
273+
}>(
274+
previousInstance => {
275+
// Preserve the previous group if:
276+
// - New group is not yet available
277+
// - Previously we had group data
278+
// - The previous group id is the same as the current group id
279+
// - The previous environments are not the same as the current environments
280+
if (
281+
!groupData &&
282+
previousInstance?.cachedGroup &&
283+
previousInstance.cachedGroup.id === groupId &&
284+
!isEqual(previousInstance.previousEnvironments, environments)
285+
) {
286+
return {
287+
previousGroupData: previousInstance.previousGroupData,
288+
previousEnvironments: previousInstance.previousEnvironments,
289+
cachedGroup: previousInstance.cachedGroup,
290+
};
291+
}
292+
293+
// If group data is available, store in memo for comparison later
294+
return {
295+
cachedGroup: groupData,
296+
previousEnvironments: environments,
297+
previousGroupData: null,
298+
};
299+
},
300+
[groupData, environments, groupId]
301+
);
302+
303+
const group = groupData ?? previousGroupData.cachedGroup ?? null;
267304

268305
useEffect(() => {
269306
if (defined(group)) {
@@ -750,13 +787,7 @@ function GroupDetails(props: GroupDetailsProps) {
750787
shouldForceProject
751788
>
752789
{config?.showFeedbackWidget && <FloatingFeedbackWidget />}
753-
<GroupDetailsPageContent
754-
{...props}
755-
{...{
756-
group,
757-
...fetchGroupDetailsProps,
758-
}}
759-
/>
790+
<GroupDetailsPageContent {...props} {...fetchGroupDetailsProps} group={group} />
760791
</PageFiltersContainer>
761792
</SentryDocumentTitle>
762793
</Fragment>

0 commit comments

Comments
 (0)