diff --git a/client/web-sveltekit/src/lib/repo/filePopover/FilePopover.gql b/client/web-sveltekit/src/lib/repo/filePopover/FilePopover.gql index 439dc63a572..ed10e51b5d4 100644 --- a/client/web-sveltekit/src/lib/repo/filePopover/FilePopover.gql +++ b/client/web-sveltekit/src/lib/repo/filePopover/FilePopover.gql @@ -2,10 +2,10 @@ query FileOrDirPopoverQuery($repoName: String!, $revision: String!, $filePath: S repository(name: $repoName) { commit(rev: $revision) { path(path: $filePath) { - ...on GitBlob { + ... on GitBlob { ...FilePopoverFragment } - ...on GitTree { + ... on GitTree { ...DirPopoverFragment } } @@ -49,7 +49,7 @@ fragment DirPopoverFragment on GitTree { } } -fragment FilePopoverLastCommitFragment on GitCommit { +fragment FilePopoverLastCommitFragment on GitCommit { abbreviatedOID oid subject diff --git a/client/web-sveltekit/src/routes/[...repo=reporev]/(validrev)/-/commit/[...revspec]/+page.svelte b/client/web-sveltekit/src/routes/[...repo=reporev]/(validrev)/-/commit/[...revspec]/+page.svelte index 43a9e990bef..d3546aa0ca3 100644 --- a/client/web-sveltekit/src/routes/[...repo=reporev]/(validrev)/-/commit/[...revspec]/+page.svelte +++ b/client/web-sveltekit/src/routes/[...repo=reporev]/(validrev)/-/commit/[...revspec]/+page.svelte @@ -15,7 +15,6 @@ import CopyButton from '$lib/wildcard/CopyButton.svelte' import type { PageData, Snapshot } from './$types' - import type { CommitPage_DiffConnection } from './page.gql' interface Capture { scroll: ScrollerCapture @@ -45,14 +44,9 @@ let scroller: Scroller let expandedDiffs = new Map() - let diffs: CommitPage_DiffConnection | null = null $: diffQuery = data.diff - // We conditionally check for the ancestors field to be able to show - // previously loaded commits when an error occurs while fetching more commits. - $: if ($diffQuery?.data?.repository) { - diffs = $diffQuery.data.repository.comparison.fileDiffs - } + $: diffs = $diffQuery?.data?.repository?.comparison.fileDiffs ?? null @@ -115,7 +109,7 @@ {#if $diffQuery?.fetching || $diffQuery?.restoring} {:else if $diffQuery?.error} -
+
Unable to fetch file diffs: {$diffQuery.error.message} @@ -157,11 +151,17 @@ font-size: inherit; } + .error, ul.diffs { - list-style: none; padding: 1rem; + } - li { + ul.diffs { + // Removes globally set margin + margin: 0; + list-style: none; + + li:not(:last-child) { margin-bottom: 1rem; } } diff --git a/client/web-sveltekit/src/routes/[...repo=reporev]/(validrev)/-/commit/[...revspec]/+page.ts b/client/web-sveltekit/src/routes/[...repo=reporev]/(validrev)/-/commit/[...revspec]/+page.ts index 69bddaf7a48..2e75ca8073e 100644 --- a/client/web-sveltekit/src/routes/[...repo=reporev]/(validrev)/-/commit/[...revspec]/+page.ts +++ b/client/web-sveltekit/src/routes/[...repo=reporev]/(validrev)/-/commit/[...revspec]/+page.ts @@ -39,7 +39,10 @@ export const load: PageLoad = async ({ params }) => { after: null as string | null, }, nextVariables: previousResult => { - if (previousResult?.data?.repository?.comparison?.fileDiffs?.pageInfo?.hasNextPage) { + if ( + !previousResult.error && + previousResult?.data?.repository?.comparison?.fileDiffs?.pageInfo?.hasNextPage + ) { return { after: previousResult.data.repository.comparison.fileDiffs.pageInfo.endCursor, } @@ -48,7 +51,12 @@ export const load: PageLoad = async ({ params }) => { }, combine: (previousResult, nextResult) => { if (!nextResult.data?.repository?.comparison) { - return nextResult + return { + ...nextResult, + // When this code path is executed we probably have an error. + // We still want to show the data that was loaded before the error occurred. + data: previousResult.data, + } } const previousNodes = previousResult.data?.repository?.comparison?.fileDiffs?.nodes ?? [] const nextNodes = nextResult.data.repository?.comparison?.fileDiffs?.nodes ?? [] diff --git a/client/web-sveltekit/src/routes/[...repo=reporev]/(validrev)/-/commit/[...revspec]/page.spec.ts b/client/web-sveltekit/src/routes/[...repo=reporev]/(validrev)/-/commit/[...revspec]/page.spec.ts index a8ceca38b70..f5662dccb48 100644 --- a/client/web-sveltekit/src/routes/[...repo=reporev]/(validrev)/-/commit/[...revspec]/page.spec.ts +++ b/client/web-sveltekit/src/routes/[...repo=reporev]/(validrev)/-/commit/[...revspec]/page.spec.ts @@ -56,3 +56,37 @@ test('error loading diff information', async ({ page, sg }) => { await page.goto(url) await expect(page.getByText(/Test error/)).toBeVisible() }) + +test('shows previous diffs when error occurs', async ({ page, sg }) => { + let callCount = 0 + sg.mockOperations({ + CommitPage_DiffQuery: () => { + if (callCount === 1) { + throw new Error('Test error') + } + callCount++ + return { + repository: { + comparison: { + fileDiffs: { + nodes: [ + { + __typename: 'FileDiff', + oldPath: null, + newPath: '', + }, + ], + pageInfo: { + hasNextPage: true, + endCursor: 'cursor', + }, + }, + }, + }, + } + }, + }) + await page.goto(url) + await expect(page.getByText('')).toBeVisible() + await expect(page.getByText('Test error')).toBeVisible() +})