Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

chore(svelte): Refactor repo loaders#63828

Merged
fkling merged 3 commits into
mainfrom
fkling/sk/refactor-repo-page
Jul 16, 2024
Merged

chore(svelte): Refactor repo loaders#63828
fkling merged 3 commits into
mainfrom
fkling/sk/refactor-repo-page

Conversation

@fkling

@fkling fkling commented Jul 15, 2024

Copy link
Copy Markdown
Contributor

This commit is in preparation for other work. It refactors how we work with resolved repository and resolved revision information.

The idea was that the top level repo loader should try to resolve the repository information and error if that wasn't possible. Not being able to resolve the revision was accepted, hence this check:

// still render the main repo navigation and header
if (!isRevisionNotFoundErrorLike(repoError)) {
  error(400, asError(repoError))
}

However the way it was implemented meant that we wouldn't pass any resolved repository information to the sub-pages/layouts when the revision couldn't be resolved, which seems wrong.

With these changes, the top level repo loader now provides a resolvedRepository object (where commit/changelist might be unset) and the (validrev) loader creates the resolvedRevision object, just how its sub-pages/layouts expect.

And instead of returning error objects from resolveRepoRevision and checking them in the loader we throw errors/redirects directly in that function. IMO that makes the whole flow easier to understand.

Test plan

Manual testing, CI integration tests

@fkling fkling self-assigned this Jul 15, 2024
@cla-bot cla-bot Bot added the cla-signed label Jul 15, 2024
// subpages that if they load the requested revision exists. This
// relieves subpages from testing whether the revision is valid.
const { repoName, resolvedRevisionOrError } = await parent()
const { revision, defaultBranch, resolvedRepository, repoName } = await parent()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Oh very nice. It was always annoying to have to worry about resolution errors in child pages.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

You didn't have to worry about it because this loader would ensure that resolvedRevision is not an error. But the way this was all set up was a bit convoluted IMO.

repo: resolvedRepository,
commitID: commit.oid,
defaultBranch,
} satisfies ResolvedRevision,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

satisfies is so good 🙂

client,
repoName,
revspec: revision,
url: untrack(() => new URL(url)),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Mind leaving a comment on why we need untrack here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I removed untrack. I originally though we needed it since we don't want the loader to rerun when the URL changes, but since the URL is only really read when creating a redirect to a different host this is not necessary.

@fkling fkling enabled auto-merge (squash) July 16, 2024 05:25
@fkling fkling merged commit 902b898 into main Jul 16, 2024
@fkling fkling deleted the fkling/sk/refactor-repo-page branch July 16, 2024 05:45
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants