Skip to content

Commit bcfbe8a

Browse files
authored
ref(replay): Refactor extractDomNodes stepper strategy into extractDomNodes.tsx (#80810)
Just wanted to move this replayStepper strategy outside of the ReplayReader class. It's a big file that contains the class, and most of the other stepper stuff isn't in here.
1 parent 1b66eaa commit bcfbe8a

File tree

5 files changed

+27
-28
lines changed

5 files changed

+27
-28
lines changed

static/app/components/replays/breadcrumbs/breadcrumbItem.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import Timeline from 'sentry/components/timeline';
1616
import {Tooltip} from 'sentry/components/tooltip';
1717
import {t} from 'sentry/locale';
1818
import {space} from 'sentry/styles/space';
19-
import type {Extraction} from 'sentry/utils/replays/extractHtml';
19+
import type {Extraction} from 'sentry/utils/replays/extractDomNodes';
2020
import {getReplayDiffOffsetsFromFrame} from 'sentry/utils/replays/getDiffTimestamps';
2121
import getFrameDetails from 'sentry/utils/replays/getFrameDetails';
2222
import type ReplayReader from 'sentry/utils/replays/replayReader';

static/app/utils/replays/extractHtml.tsx renamed to static/app/utils/replays/extractDomNodes.tsx

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type {Mirror} from '@sentry-internal/rrweb-snapshot';
22

33
import type {ReplayFrame} from 'sentry/utils/replays/types';
4+
import {getNodeIds} from 'sentry/utils/replays/types';
45
import constructSelector from 'sentry/views/replays/deadRageClick/constructSelector';
56

67
export type Extraction = {
@@ -10,7 +11,27 @@ export type Extraction = {
1011
timestamp: number;
1112
};
1213

13-
export default function extractHtmlAndSelector(
14+
const extractDomNodes = {
15+
shouldVisitFrame: frame => {
16+
const nodeIds = getNodeIds(frame);
17+
return nodeIds.filter(nodeId => nodeId !== -1).length > 0;
18+
},
19+
onVisitFrame: (frame, collection, replayer) => {
20+
const mirror = replayer.getMirror();
21+
const nodeIds = getNodeIds(frame);
22+
const {html, selectors} = extractHtmlAndSelector((nodeIds ?? []) as number[], mirror);
23+
collection.set(frame as ReplayFrame, {
24+
frame,
25+
html,
26+
selectors,
27+
timestamp: frame.timestampMs,
28+
});
29+
},
30+
};
31+
32+
export default extractDomNodes;
33+
34+
function extractHtmlAndSelector(
1435
nodeIds: number[],
1536
mirror: Mirror
1637
): {html: string[]; selectors: Map<number, string>} {

static/app/utils/replays/hooks/useExtractDomNodes.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {useQuery, type UseQueryResult} from 'sentry/utils/queryClient';
2-
import type {Extraction} from 'sentry/utils/replays/extractHtml';
2+
import type {Extraction} from 'sentry/utils/replays/extractDomNodes';
33
import type ReplayReader from 'sentry/utils/replays/replayReader';
44
import type {ReplayFrame} from 'sentry/utils/replays/types';
55

@@ -10,9 +10,7 @@ export default function useExtractDomNodes({
1010
}): UseQueryResult<Map<ReplayFrame, Extraction>> {
1111
return useQuery({
1212
queryKey: ['getDomNodes', replay],
13-
queryFn: () => {
14-
return replay?.getExtractDomNodes();
15-
},
13+
queryFn: () => replay?.getExtractDomNodes(),
1614
enabled: Boolean(replay),
1715
gcTime: Infinity,
1816
});

static/app/utils/replays/replayReader.tsx

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {defined} from 'sentry/utils';
66
import domId from 'sentry/utils/domId';
77
import localStorageWrapper from 'sentry/utils/localStorage';
88
import clamp from 'sentry/utils/number/clamp';
9-
import extractHtmlandSelector from 'sentry/utils/replays/extractHtml';
9+
import extractDomNodes from 'sentry/utils/replays/extractDomNodes';
1010
import hydrateBreadcrumbs, {
1111
replayInitBreadcrumb,
1212
} from 'sentry/utils/replays/hydrateBreadcrumbs';
@@ -28,7 +28,6 @@ import type {
2828
MemoryFrame,
2929
OptionFrame,
3030
RecordingFrame,
31-
ReplayFrame,
3231
serializedNodeWithId,
3332
SlowClickFrame,
3433
SpanFrame,
@@ -38,7 +37,6 @@ import type {
3837
import {
3938
BreadcrumbCategories,
4039
EventType,
41-
getNodeIds,
4240
IncrementalSource,
4341
isCLSFrame,
4442
isConsoleFrame,
@@ -149,24 +147,6 @@ function removeDuplicateNavCrumbs(
149147
return otherBreadcrumbFrames.concat(uniqueNavCrumbs);
150148
}
151149

152-
const extractDomNodes = {
153-
shouldVisitFrame: frame => {
154-
const nodeIds = getNodeIds(frame);
155-
return nodeIds.filter(nodeId => nodeId !== -1).length > 0;
156-
},
157-
onVisitFrame: (frame, collection, replayer) => {
158-
const mirror = replayer.getMirror();
159-
const nodeIds = getNodeIds(frame);
160-
const {html, selectors} = extractHtmlandSelector((nodeIds ?? []) as number[], mirror);
161-
collection.set(frame as ReplayFrame, {
162-
frame,
163-
html,
164-
selectors,
165-
timestamp: frame.timestampMs,
166-
});
167-
},
168-
};
169-
170150
export default class ReplayReader {
171151
static factory({
172152
attachments,

static/app/views/replays/detail/breadcrumbs/breadcrumbRow.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import classNames from 'classnames';
44

55
import BreadcrumbItem from 'sentry/components/replays/breadcrumbs/breadcrumbItem';
66
import {useReplayContext} from 'sentry/components/replays/replayContext';
7-
import type {Extraction} from 'sentry/utils/replays/extractHtml';
7+
import type {Extraction} from 'sentry/utils/replays/extractDomNodes';
88
import useCrumbHandlers from 'sentry/utils/replays/hooks/useCrumbHandlers';
99
import useCurrentHoverTime from 'sentry/utils/replays/playback/providers/useCurrentHoverTime';
1010
import type {ReplayFrame} from 'sentry/utils/replays/types';

0 commit comments

Comments
 (0)