Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(replay): Calculate hydration diff timestamps based on related hydration breadcrumbs #73095

Merged
merged 4 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {ReplayGroupContextProvider} from 'sentry/components/replays/replayGroupC
import {t} from 'sentry/locale';
import type {Event} from 'sentry/types/event';
import type {Group} from 'sentry/types/group';
import {getReplayDiffOffsetsFromEvent} from 'sentry/utils/replays/getDiffTimestamps';
import useReplayReader from 'sentry/utils/replays/hooks/useReplayReader';

interface Props {
Expand All @@ -31,11 +32,7 @@ export default function ReplayDiffContent({event, group, orgSlug, replaySlug}: P
return null;
}

// TODO: base the event timestamp off the replay data itself.
const startTimestampMS =
'startTimestamp' in event ? event.startTimestamp * 1000 : undefined;
const timeOfEvent = event.dateCreated ?? startTimestampMS ?? event.dateReceived;
const eventTimestampMs = timeOfEvent ? Math.floor(new Date(timeOfEvent).getTime()) : 0;
const {leftOffsetMs, rightOffsetMs} = getReplayDiffOffsetsFromEvent(replay, event);

return (
<EventDataSection
Expand All @@ -44,9 +41,9 @@ export default function ReplayDiffContent({event, group, orgSlug, replaySlug}: P
actions={
<OpenReplayComparisonButton
key="open-modal-button"
leftTimestamp={0}
leftOffsetMs={leftOffsetMs}
replay={replay}
rightTimestamp={eventTimestampMs}
rightOffsetMs={rightOffsetMs}
size="xs"
>
{t('Open Diff Viewer')}
Expand All @@ -57,9 +54,9 @@ export default function ReplayDiffContent({event, group, orgSlug, replaySlug}: P
<ReplayGroupContextProvider groupId={group?.id} eventId={event.id}>
<ReplayDiff
defaultTab={DiffType.VISUAL}
leftTimestamp={0}
leftOffsetMs={leftOffsetMs}
replay={replay}
rightTimestamp={eventTimestampMs}
rightOffsetMs={rightOffsetMs}
/>
</ReplayGroupContextProvider>
</ErrorBoundary>
Expand Down
57 changes: 40 additions & 17 deletions static/app/components/replays/breadcrumbs/breadcrumbItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,21 @@ import {Tooltip} from 'sentry/components/tooltip';
import {t} from 'sentry/locale';
import {space} from 'sentry/styles/space';
import type {Extraction} from 'sentry/utils/replays/extractDomNodes';
import {getReplayDiffOffsetsFromFrame} from 'sentry/utils/replays/getDiffTimestamps';
import getFrameDetails from 'sentry/utils/replays/getFrameDetails';
import type {ErrorFrame, FeedbackFrame, ReplayFrame} from 'sentry/utils/replays/types';
import {isErrorFrame, isFeedbackFrame} from 'sentry/utils/replays/types';
import type ReplayReader from 'sentry/utils/replays/replayReader';
import type {
ErrorFrame,
FeedbackFrame,
HydrationErrorFrame,
ReplayFrame,
} from 'sentry/utils/replays/types';
import {
isBreadcrumbFrame,
isErrorFrame,
isFeedbackFrame,
isHydrationErrorFrame,
} from 'sentry/utils/replays/types';
import useOrganization from 'sentry/utils/useOrganization';
import useProjectFromSlug from 'sentry/utils/useProjectFromSlug';
import IconWrapper from 'sentry/views/replays/detail/iconWrapper';
Expand Down Expand Up @@ -88,22 +100,10 @@ function BreadcrumbItem({
}, [description, expandPaths, onInspectorExpanded]);

const renderComparisonButton = useCallback(() => {
return frame?.data && 'mutations' in frame.data ? (
<div>
<OpenReplayComparisonButton
replay={replay}
leftTimestamp={frame.offsetMs}
rightTimestamp={
(frame.data.mutations.next?.timestamp ?? 0) -
(replay?.getReplay().started_at.getTime() ?? 0)
}
size="xs"
>
{t('Open Hydration Diff')}
</OpenReplayComparisonButton>
</div>
return isBreadcrumbFrame(frame) && isHydrationErrorFrame(frame) ? (
<CrumbHydrationButton replay={replay} frame={frame} />
) : null;
}, [frame?.data, frame.offsetMs, replay]);
}, [frame, replay]);

const renderCodeSnippet = useCallback(() => {
return extraction?.html ? (
Expand Down Expand Up @@ -187,6 +187,29 @@ function BreadcrumbItem({
);
}

function CrumbHydrationButton({
replay,
frame,
}: {
frame: HydrationErrorFrame;
replay: ReplayReader | null;
}) {
const {leftOffsetMs, rightOffsetMs} = getReplayDiffOffsetsFromFrame(replay, frame);

return (
<div>
<OpenReplayComparisonButton
replay={replay}
leftOffsetMs={leftOffsetMs}
rightOffsetMs={rightOffsetMs}
size="xs"
>
{t('Open Hydration Diff')}
</OpenReplayComparisonButton>
</div>
);
}

function CrumbErrorIssue({frame}: {frame: FeedbackFrame | ErrorFrame}) {
const organization = useOrganization();
const project = useProjectFromSlug({organization, projectSlug: frame.data.projectSlug});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ const LazyComparisonModal = lazy(

interface Props {
children: ReactNode;
leftTimestamp: number;
leftOffsetMs: number;
replay: null | ReplayReader;
rightTimestamp: number;
rightOffsetMs: number;
size?: ButtonProps['size'];
}

export function OpenReplayComparisonButton({
children,
leftTimestamp,
leftOffsetMs,
replay,
rightTimestamp,
rightOffsetMs,
size,
}: Props) {
const organization = useOrganization();
Expand Down Expand Up @@ -59,8 +59,8 @@ export function OpenReplayComparisonButton({
<LazyComparisonModal
replay={replay}
organization={organization}
leftTimestamp={leftTimestamp}
rightTimestamp={rightTimestamp}
leftOffsetMs={leftOffsetMs}
rightOffsetMs={rightOffsetMs}
{...deps}
/>
</Suspense>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@ import type ReplayReader from 'sentry/utils/replays/replayReader';
import {OrganizationContext} from 'sentry/views/organizationContext';

interface Props extends ModalRenderProps {
leftTimestamp: number;
leftOffsetMs: number;
organization: Organization;
replay: null | ReplayReader;
rightTimestamp: number;
rightOffsetMs: number;
}

export default function ReplayComparisonModal({
Body,
Header,
leftTimestamp,
leftOffsetMs,
organization,
replay,
rightTimestamp,
rightOffsetMs,
}: Props) {
return (
<OrganizationContext.Provider value={organization}>
Expand Down Expand Up @@ -55,8 +55,8 @@ export default function ReplayComparisonModal({
</StyledParagraph>
<ReplayDiff
replay={replay}
leftTimestamp={leftTimestamp}
rightTimestamp={rightTimestamp}
leftOffsetMs={leftOffsetMs}
rightOffsetMs={rightOffsetMs}
/>
</Body>
</OrganizationContext.Provider>
Expand Down
16 changes: 8 additions & 8 deletions static/app/components/replays/replayDiff.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ import type ReplayReader from 'sentry/utils/replays/replayReader';
const MAX_CLAMP_TO_START = 2000;

interface Props {
leftTimestamp: number;
leftOffsetMs: number;
replay: null | ReplayReader;
rightTimestamp: number;
rightOffsetMs: number;
defaultTab?: DiffType;
}

Expand All @@ -33,16 +33,16 @@ export enum DiffType {

export default function ReplayDiff({
defaultTab = DiffType.VISUAL,
leftTimestamp,
leftOffsetMs,
replay,
rightTimestamp,
rightOffsetMs,
}: Props) {
const fetching = false;

const [leftBody, setLeftBody] = useState(null);
const [rightBody, setRightBody] = useState(null);

let startOffset = leftTimestamp - 1;
let startOffset = leftOffsetMs - 1;
// If the error occurs close to the start of the replay, clamp the start offset to 1
// to help compare with the html provided by the server, This helps with some errors on localhost.
if (startOffset < MAX_CLAMP_TO_START) {
Expand Down Expand Up @@ -96,16 +96,16 @@ export default function ReplayDiff({
</ReplayContextProvider>
<ReplayContextProvider
analyticsContext="replay_comparison_modal_right"
initialTimeOffsetMs={{offsetMs: rightTimestamp + 1}}
initialTimeOffsetMs={{offsetMs: rightOffsetMs + 1}}
isFetching={fetching}
prefsStrategy={StaticReplayPreferences}
replay={replay}
>
<ComparisonSideWrapper id="rightSide">
{rightTimestamp > 0 ? (
{rightOffsetMs > 0 ? (
<ReplaySide
selector="#rightSide iframe"
expectedTime={rightTimestamp + 1}
expectedTime={rightOffsetMs + 1}
onLoad={setRightBody}
/>
) : (
Expand Down
Loading
Loading