Skip to content

Commit 2ff2814

Browse files
authored
ref(sdk-updates): Refactor types and args related to useOrganizationSDKUpdates and uses (#97642)
The hook `useOrganizationSDKUpdates` was returning the wrong types, it was way to narrow and didn't get the `isFetched` return changed over to `isPending` back when react-query updated. Now it's got the proper response type. Also, i updated `useProjectSdkNeedsUpdate` and added tests, to use `useOrganizationSDKUpdates` internally. This gives it the correct types too. Finally, i updated all the replay callsites to use consts for all the minVersion fields. This way we can see all the special versions of the replay SDK that are out there in one spot. All the min_version_* stuff also has a link to docs or something, even if that's not yet used in the UI; it's a reference for us too.
1 parent 9291c6f commit 2ff2814

File tree

9 files changed

+48
-63
lines changed

9 files changed

+48
-63
lines changed

static/app/components/replays/canvasSupportNotice.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {t, tct} from 'sentry/locale';
99
import {space} from 'sentry/styles/space';
1010
import {trackAnalytics} from 'sentry/utils/analytics';
1111
import {useReplayReader} from 'sentry/utils/replays/playback/providers/replayReaderProvider';
12+
import {MIN_CANVAS_SUPPORTED_SDK} from 'sentry/utils/replays/sdkVersions';
1213
import useDismissAlert from 'sentry/utils/useDismissAlert';
1314
import useOrganization from 'sentry/utils/useOrganization';
1415
import useProjectSdkNeedsUpdate from 'sentry/utils/useProjectSdkNeedsUpdate';
@@ -25,8 +26,7 @@ export function CanvasSupportNotice() {
2526
const {isFetching} = useReplayContext();
2627
const projectId = replay?.getReplay().project_id;
2728
const {needsUpdate} = useProjectSdkNeedsUpdate({
28-
minVersion: '7.98.0',
29-
organization,
29+
minVersion: MIN_CANVAS_SUPPORTED_SDK.minVersion,
3030
projectId: [projectId ?? '-1'],
3131
});
3232

static/app/components/replays/jetpackComposePiiNotice.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ export function JetpackComposePiiNotice() {
3838
<ExternalLink href="https://github.com/getsentry/sentry-java/security/advisories/GHSA-7cjh-xx4r-qh3f" />
3939
),
4040
link: (
41-
<ExternalLink href={MIN_JETPACK_COMPOSE_VIEW_HIERARCHY_PII_FIX.changelog} />
41+
<ExternalLink
42+
href={MIN_JETPACK_COMPOSE_VIEW_HIERARCHY_PII_FIX.releaseNotes}
43+
/>
4244
),
4345
}
4446
)}
Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
export const MIN_REPLAY_CLICK_SDK = {
22
minVersion: '7.44.0',
3-
changelog: 'https://github.com/getsentry/sentry-javascript/releases/tag/7.44.0',
3+
releaseNotes: 'https://github.com/getsentry/sentry-javascript/releases/tag/7.44.0',
4+
};
5+
6+
// Knowns bugs in v7.50 to v7.53.0 inclusive
7+
export const MIN_REPLAY_NETWORK_BODIES_SDK_KNOWN_BUG = {
8+
minVersion: '7.50.0',
9+
releaseNotes: 'https://github.com/getsentry/sentry-javascript/releases/tag/7.50.0',
10+
};
11+
12+
// This version fixes the known bugs when capturing network bodies
13+
export const MIN_REPLAY_NETWORK_BODIES_SDK = {
14+
minVersion: '7.53.1',
15+
releaseNotes: 'https://github.com/getsentry/sentry-javascript/releases/tag/7.53.1',
416
};
517

618
export const MIN_DEAD_RAGE_CLICK_SDK = {
@@ -9,7 +21,12 @@ export const MIN_DEAD_RAGE_CLICK_SDK = {
921
'https://changelog.getsentry.com/announcements/user-frustration-signals-rage-and-dead-clicks-in-session-replay',
1022
};
1123

24+
export const MIN_CANVAS_SUPPORTED_SDK = {
25+
minVersion: '7.98.0',
26+
docs: 'https://docs.sentry.io/platforms/javascript/session-replay/troubleshooting/#my-canvas-elements-arent-getting-captured',
27+
};
28+
1229
export const MIN_JETPACK_COMPOSE_VIEW_HIERARCHY_PII_FIX = {
1330
minVersion: '8.14.0',
14-
changelog: 'https://github.com/getsentry/sentry-java/releases/tag/8.14.0',
31+
releaseNotes: 'https://github.com/getsentry/sentry-java/releases/tag/8.14.0',
1532
};

static/app/utils/useOrganizationSDKUpdates.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,7 @@ interface Options {
77
projectId?: string[];
88
}
99

10-
export function useOrganizationSDKUpdates({projectId, enabled}: Options): {
11-
isError: boolean;
12-
isFetching: boolean;
13-
data?: ProjectSdkUpdates[];
14-
} {
10+
export function useOrganizationSDKUpdates({projectId, enabled}: Options) {
1511
const organization = useOrganization();
1612

1713
return useApiQuery<ProjectSdkUpdates[]>(

static/app/utils/useProjectSdkNeedsUpdate.spec.tsx

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,16 @@ import {renderHook, waitFor} from 'sentry-test/reactTestingLibrary';
77

88
import {QueryClientProvider} from 'sentry/utils/queryClient';
99
import useProjectSdkNeedsUpdate from 'sentry/utils/useProjectSdkNeedsUpdate';
10+
import {OrganizationContext} from 'sentry/views/organizationContext';
1011

1112
const MOCK_ORG = OrganizationFixture();
1213
const MOCK_PROJECT = ProjectFixture();
1314

1415
function wrapper({children}: {children?: ReactNode}) {
1516
return (
16-
<QueryClientProvider client={makeTestQueryClient()}>{children}</QueryClientProvider>
17+
<OrganizationContext value={MOCK_ORG}>
18+
<QueryClientProvider client={makeTestQueryClient()}>{children}</QueryClientProvider>
19+
</OrganizationContext>
1720
);
1821
}
1922

@@ -47,17 +50,14 @@ describe('useProjectSdkNeedsUpdate', () => {
4750
wrapper,
4851
initialProps: {
4952
minVersion: '1.0.0',
50-
organization: MOCK_ORG,
5153
projectId: [MOCK_PROJECT.id],
5254
},
5355
});
5456

5557
await waitFor(() => {
5658
expect(result.current.isError).toBeFalsy();
5759
});
58-
await waitFor(() => {
59-
expect(result.current.isFetching).toBeFalsy();
60-
});
60+
expect(result.current.isFetching).toBeFalsy();
6161
expect(result.current.needsUpdate).toBeFalsy();
6262
});
6363

@@ -73,20 +73,17 @@ describe('useProjectSdkNeedsUpdate', () => {
7373
wrapper,
7474
initialProps: {
7575
minVersion: '8.0.0',
76-
organization: MOCK_ORG,
7776
projectId: [MOCK_PROJECT.id],
7877
},
7978
});
8079
await waitFor(() => {
8180
expect(result.current.isError).toBeFalsy();
8281
});
83-
await waitFor(() => {
84-
expect(result.current.isFetching).toBeFalsy();
85-
});
82+
expect(result.current.isFetching).toBeFalsy();
8683
expect(result.current.needsUpdate).toBeTruthy();
8784
});
8885

89-
it('should return needsUpdate if multiple projects', async () => {
86+
it('should return needsUpdate if all projects are below minSdk', async () => {
9087
mockCurrentVersion([
9188
{
9289
projectId: '1',
@@ -102,17 +99,14 @@ describe('useProjectSdkNeedsUpdate', () => {
10299
wrapper,
103100
initialProps: {
104101
minVersion: '8.0.0',
105-
organization: MOCK_ORG,
106102
projectId: ['1', '2'],
107103
},
108104
});
109105

110106
await waitFor(() => {
111107
expect(result.current.isError).toBeFalsy();
112108
});
113-
await waitFor(() => {
114-
expect(result.current.isFetching).toBeFalsy();
115-
});
109+
expect(result.current.isFetching).toBeFalsy();
116110
expect(result.current.needsUpdate).toBeTruthy();
117111
});
118112

@@ -132,17 +126,14 @@ describe('useProjectSdkNeedsUpdate', () => {
132126
wrapper,
133127
initialProps: {
134128
minVersion: '8.0.0',
135-
organization: MOCK_ORG,
136129
projectId: ['1', '2'],
137130
},
138131
});
139132

140133
await waitFor(() => {
141134
expect(result.current.isError).toBeFalsy();
142135
});
143-
await waitFor(() => {
144-
expect(result.current.isFetching).toBeFalsy();
145-
});
136+
expect(result.current.isFetching).toBeFalsy();
146137
expect(result.current.needsUpdate).toBeFalsy();
147138
});
148139
});
Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,38 @@
1-
import type {Organization} from 'sentry/types/organization';
2-
import {useQuery} from 'sentry/utils/queryClient';
3-
import useApi from 'sentry/utils/useApi';
1+
import {useOrganizationSDKUpdates} from 'sentry/utils/useOrganizationSDKUpdates';
42
import {semverCompare} from 'sentry/utils/versions/semverCompare';
53

64
type Opts = {
75
minVersion: string;
8-
organization: Organization;
96
projectId: string[];
107
};
118

12-
function useProjectSdkNeedsUpdate({
9+
export default function useProjectSdkNeedsUpdate({
1310
minVersion,
14-
organization,
1511
projectId,
1612
}: Opts):
1713
| {isError: false; isFetching: true; needsUpdate: undefined}
1814
| {isError: true; isFetching: false; needsUpdate: undefined}
1915
| {isError: false; isFetching: false; needsUpdate: boolean} {
20-
const path = `/organizations/${organization.slug}/sdk-updates/`;
21-
const api = useApi({persistInFlight: true});
22-
const {data, isPending, isError} = useQuery({
23-
queryKey: [path],
24-
queryFn: async () => {
25-
try {
26-
return await api.requestPromise(path, {
27-
method: 'GET',
28-
});
29-
} catch {
30-
return [];
31-
}
32-
},
33-
staleTime: 5000,
34-
refetchOnMount: false,
16+
const {data, isError, isPending} = useOrganizationSDKUpdates({
17+
projectId,
18+
enabled: true,
3519
});
3620

3721
if (isPending) {
3822
return {isError: false, isFetching: true, needsUpdate: undefined};
3923
}
40-
4124
if (isError) {
4225
return {isError: true, isFetching: false, needsUpdate: undefined};
4326
}
4427

45-
const selectedProjects = data.filter((sdkUpdate: any) =>
28+
const selectedProjects = data.filter(sdkUpdate =>
4629
projectId.includes(sdkUpdate.projectId)
4730
);
4831

4932
const needsUpdate =
5033
selectedProjects.length > 0 &&
5134
selectedProjects.every(
52-
(sdkUpdate: any) => semverCompare(sdkUpdate.sdkVersion || '', minVersion) === -1
35+
sdkUpdate => semverCompare(sdkUpdate.sdkVersion || '', minVersion) === -1
5336
);
5437

5538
return {
@@ -58,5 +41,3 @@ function useProjectSdkNeedsUpdate({
5841
needsUpdate,
5942
};
6043
}
61-
62-
export default useProjectSdkNeedsUpdate;

static/app/views/replays/detail/network/details/onboarding.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ import TextCopyInput from 'sentry/components/textCopyInput';
77
import {t, tct} from 'sentry/locale';
88
import {space} from 'sentry/styles/space';
99
import {useReplayReader} from 'sentry/utils/replays/playback/providers/replayReaderProvider';
10+
import {
11+
MIN_REPLAY_NETWORK_BODIES_SDK,
12+
MIN_REPLAY_NETWORK_BODIES_SDK_KNOWN_BUG,
13+
} from 'sentry/utils/replays/sdkVersions';
1014
import type {SpanFrame} from 'sentry/utils/replays/types';
1115
import useDismissAlert from 'sentry/utils/useDismissAlert';
1216
import useOrganization from 'sentry/utils/useOrganization';
@@ -59,13 +63,11 @@ export function Setup({
5963
showSnippet: Output;
6064
visibleTab: TabKey;
6165
}) {
62-
const organization = useOrganization();
6366
const {isFetching, needsUpdate} = useProjectSdkNeedsUpdate({
64-
// Only show update instructions if not >= 7.50.0, but our instructions
67+
// Only show update instructions if <7.50.0, but our instructions
6568
// will show a different min version as there are known bugs in 7.50 ->
6669
// 7.53
67-
minVersion: '7.50.0',
68-
organization,
70+
minVersion: MIN_REPLAY_NETWORK_BODIES_SDK_KNOWN_BUG.minVersion,
6971
projectId: [projectId],
7072
});
7173
const sdkNeedsUpdate = !isFetching && Boolean(needsUpdate);
@@ -89,7 +91,7 @@ export function Setup({
8991
) : null
9092
) : (
9193
<SetupInstructions
92-
minVersion="7.53.1"
94+
minVersion={MIN_REPLAY_NETWORK_BODIES_SDK.minVersion}
9395
sdkNeedsUpdate={sdkNeedsUpdate}
9496
showSnippet={showSnippet}
9597
url={url}

static/app/views/replays/list.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ export default function ReplaysListContainer() {
3939
} = usePageFilters();
4040
const rageClicksSdkVersion = useProjectSdkNeedsUpdate({
4141
minVersion: MIN_DEAD_RAGE_CLICK_SDK.minVersion,
42-
organization,
4342
projectId: projects.map(String),
4443
});
4544

static/app/views/replays/list/replayIndexTable.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ export default function ReplayIndexTable() {
7979

8080
const rageClicksSdkVersion = useProjectSdkNeedsUpdate({
8181
minVersion: MIN_DEAD_RAGE_CLICK_SDK.minVersion,
82-
organization,
8382
projectId: projects.map(String),
8483
});
8584
const hasSentReplays = useHaveSelectedProjectsSentAnyReplayEvents();
@@ -186,13 +185,11 @@ export default function ReplayIndexTable() {
186185
}
187186

188187
function useNeedsSDKUpdateForClickSearch({query}: {query: string}) {
189-
const organization = useOrganization();
190188
const {
191189
selection: {projects},
192190
} = usePageFilters();
193191
const {needsUpdate} = useProjectSdkNeedsUpdate({
194192
minVersion: MIN_REPLAY_CLICK_SDK.minVersion,
195-
organization,
196193
projectId: projects.map(String),
197194
});
198195

0 commit comments

Comments
 (0)