Skip to content

Commit

Permalink
fix(hydration issue): Only look at IncrementalSource.Mutation types f…
Browse files Browse the repository at this point in the history
…or hydration before/after (#82908)

There are many IncrementalSource possibilities (definition copied
below), but we really only want to look at mutations. Mouse moves,
input, and possibly even StyleSheetRule shouldn't affect hydrating the
DOM that react cares about.

The full list of this enum is:
```
export declare enum IncrementalSource {
    Mutation = 0,
    MouseMove = 1,
    MouseInteraction = 2,
    Scroll = 3,
    ViewportResize = 4,
    Input = 5,
    TouchMove = 6,
    MediaInteraction = 7,
    StyleSheetRule = 8,
    CanvasMutation = 9,
    Font = 10,
    Log = 11,
    Drag = 12,
    StyleDeclaration = 13,
    Selection = 14,
    AdoptedStyleSheet = 15,
    CustomElement = 16
}
```

The parent type that we are refining down from is:
```
export type incrementalSnapshotEvent = {
    type: EventType.IncrementalSnapshot;
    data: incrementalData;
};
```
  • Loading branch information
ryan953 authored Jan 3, 2025
1 parent 205decf commit 66e2ada
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
8 changes: 2 additions & 6 deletions static/app/utils/replays/getDiffTimestamps.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type {Event} from 'sentry/types/event';
import type ReplayReader from 'sentry/utils/replays/replayReader';
import type {HydrationErrorFrame} from 'sentry/utils/replays/types';
import {EventType, isHydrationErrorFrame} from 'sentry/utils/replays/types';
import {isHydrationErrorFrame, isRRWebChangeFrame} from 'sentry/utils/replays/types';

export function getReplayDiffOffsetsFromFrame(
replay: ReplayReader | null,
Expand All @@ -15,11 +15,7 @@ export function getReplayDiffOffsetsFromFrame(
}

const startTimestampMs = replay.getReplay().started_at.getTime() ?? 0;
const domChangedFrames = replay
.getRRWebFrames()
.filter(frame =>
[EventType.FullSnapshot, EventType.IncrementalSnapshot].includes(frame.type)
);
const domChangedFrames = replay.getRRWebFrames().filter(isRRWebChangeFrame);

const prevIncremental = domChangedFrames.filter(
frame => frame.timestamp < hydrationError.timestampMs
Expand Down
8 changes: 8 additions & 0 deletions static/app/utils/replays/types.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
EventType,
type eventWithTime as TEventWithTime,
IncrementalSource,
MouseInteractions,
} from '@sentry-internal/rrweb';

Expand Down Expand Up @@ -143,6 +144,13 @@ export function isRecordingFrame(
return 'type' in attachment && 'timestamp' in attachment;
}

export function isRRWebChangeFrame(frame: RecordingFrame) {
return (
frame.type === EventType.FullSnapshot ||
(frame.type === EventType.IncrementalSnapshot &&
frame.data.source === IncrementalSource.Mutation)
);
}
export function isTouchStartFrame(frame: RecordingFrame) {
return (
frame.type === EventType.IncrementalSnapshot &&
Expand Down

0 comments on commit 66e2ada

Please sign in to comment.