Skip to content

fix(replay): Fix error state quickly flashing when loading replay #72823

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

Merged
merged 4 commits into from
Jun 18, 2024
Merged
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
37 changes: 27 additions & 10 deletions static/app/utils/replays/hooks/useReplayData.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {useCallback, useMemo} from 'react';
import {useCallback, useMemo, useRef} from 'react';

import {ALL_ACCESS_PROJECTS} from 'sentry/constants/pageFilters';
import useFetchParallelPages from 'sentry/utils/api/useFetchParallelPages';
Expand Down Expand Up @@ -76,8 +76,8 @@ function useReplayData({
errorsPerPage = 50,
segmentsPerPage = 100,
}: Options): Result {
const hasFetchedAttachments = useRef(false);
const projects = useProjects();

const queryClient = useQueryClient();

// Fetch every field of the replay. The TS type definition lists every field
Expand Down Expand Up @@ -120,13 +120,16 @@ function useReplayData({
[orgSlug, projectSlug, replayId]
);

const {pages: attachmentPages, isFetching: isFetchingAttachments} =
useFetchParallelPages({
enabled: !fetchReplayError && Boolean(projectSlug) && Boolean(replayRecord),
hits: replayRecord?.count_segments ?? 0,
getQueryKey: getAttachmentsQueryKey,
perPage: segmentsPerPage,
});
const {
pages: attachmentPages,
isFetching: isFetchingAttachments,
error: fetchAttachmentsError,
} = useFetchParallelPages({
enabled: !fetchReplayError && Boolean(projectSlug) && Boolean(replayRecord),
hits: replayRecord?.count_segments ?? 0,
getQueryKey: getAttachmentsQueryKey,
perPage: segmentsPerPage,
});

const getErrorsQueryKey = useCallback(
({cursor, per_page}): ApiQueryKey => {
Expand Down Expand Up @@ -230,12 +233,25 @@ function useReplayData({
}, [orgSlug, replayId, projectSlug, queryClient]);

return useMemo(() => {
// This hook can enter a state where `fetching` below is false
// before it is entirely ready (i.e. it has not fetched
// attachemnts yet). This can cause downstream components to
// think it is no longer fetching and will display an error
// because there are no attachments. The below will require
// that we have attempted to fetch an attachment once (or it
// errors) before we toggle fetching state to false.
hasFetchedAttachments.current =
hasFetchedAttachments.current || isFetchingAttachments;

Comment on lines +243 to +244
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please double check my logic, but i'm pretty sure this is right and pretty sure we always want to make at least 1 request for attachments or something is wrong.

const fetching =
isFetchingReplay ||
isFetchingAttachments ||
isFetchingErrors ||
isFetchingExtraErrors ||
isFetchingPlatformErrors;
isFetchingPlatformErrors ||
(!hasFetchedAttachments.current &&
!fetchAttachmentsError &&
Boolean(replayRecord?.count_segments));

const allErrors = errorPages
.concat(extraErrorPages)
Expand All @@ -256,6 +272,7 @@ function useReplayData({
errorPages,
extraErrorPages,
fetchReplayError,
fetchAttachmentsError,
isFetchingAttachments,
isFetchingErrors,
isFetchingExtraErrors,
Expand Down
Loading