Skip to content

Commit c4c789c

Browse files
authored
chore(editor): preload branch links using Link instead of router push (#4713)
Fixes FER- ## Short description of the changes made ## What was the motivation & context behind this PR? ## How has this PR been tested?
1 parent ca6d8c9 commit c4c789c

File tree

3 files changed

+30
-33
lines changed

3 files changed

+30
-33
lines changed

packages/fern-dashboard/src/components/docs-page/BranchList.tsx

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,6 @@ export function BranchList({ docsUrl, sourceRepo }: { docsUrl: DocsUrl; sourceRe
2424
const [visibleCount, setVisibleCount] = useState(3);
2525
const BRANCHES_PER_PAGE = 3;
2626

27-
const handleBranchClick = (branchName: string) => {
28-
const editorSlug = constructEditorSlug({
29-
orgName,
30-
docsUrl: encodeURIComponent(docsUrl) as EncodedDocsUrl,
31-
branchName,
32-
slug: ROOT_SLUG_ALIAS
33-
});
34-
router.push(editorSlug);
35-
};
36-
3727
const handleBranchDelete = (branchName: string) => {
3828
deleteBranch(branchName);
3929
setDeletedBranches((prev) => new Set(prev).add(branchName));
@@ -62,7 +52,6 @@ export function BranchList({ docsUrl, sourceRepo }: { docsUrl: DocsUrl; sourceRe
6252
sourceRepo={sourceRepo}
6353
docsUrl={docsUrl}
6454
handleBranchDelete={handleBranchDelete}
65-
handleBranchClick={handleBranchClick}
6655
showDivider={index < visibleBranches.length - 1}
6756
/>
6857
))}

packages/fern-dashboard/src/components/docs-page/BranchListItem.tsx

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
import { constructEditorSlug, ROOT_SLUG_ALIAS } from "@fern-docs/components/navigation";
12
import { ArrowRight, Loader2 } from "lucide-react";
2-
import { useState } from "react";
3-
3+
import Link from "next/link";
4+
import { useMemo, useState } from "react";
5+
import { useOrgName } from "@/app/[orgName]/context/OrgNameContext";
46
import type { GithubSourceRepo } from "@/app/services/github/types";
5-
import type { DocsUrl } from "@/utils/types";
6-
7+
import type { DocsUrl, EncodedDocsUrl } from "@/utils/types";
78
import { Button } from "../ui/button";
89
import { BranchPRInfo } from "./BranchPRInfo";
910
import { DeleteBranchButton } from "./DeleteBranchButton";
@@ -13,17 +14,27 @@ export function BranchListItem({
1314
sourceRepo,
1415
docsUrl,
1516
showDivider = false,
16-
handleBranchDelete,
17-
handleBranchClick
17+
handleBranchDelete
1818
}: {
1919
branch: string;
2020
docsUrl: DocsUrl;
2121
sourceRepo?: GithubSourceRepo;
2222
showDivider?: boolean;
2323
handleBranchDelete: (branch: string) => void;
24-
handleBranchClick: (branch: string) => void;
2524
}) {
2625
const [loading, setLoading] = useState(false);
26+
const orgName = useOrgName();
27+
28+
const editorLink = useMemo(
29+
() =>
30+
constructEditorSlug({
31+
orgName,
32+
docsUrl: encodeURIComponent(docsUrl) as EncodedDocsUrl,
33+
branchName: branch,
34+
slug: ROOT_SLUG_ALIAS
35+
}),
36+
[orgName, docsUrl, branch]
37+
);
2738
return (
2839
<>
2940
<div className="flex items-center justify-between gap-x-4 gap-y-1">
@@ -37,19 +48,21 @@ export function BranchListItem({
3748
variant="outline"
3849
onClick={() => {
3950
setLoading(true);
40-
handleBranchClick(branch);
4151
}}
4252
disabled={loading}
4353
className="text-green-1100 hover:text-green-1100 min-w-[84px]"
54+
asChild={!loading}
4455
>
45-
{loading ? (
46-
<Loader2 className="size-4 animate-spin" />
47-
) : (
48-
<>
49-
Open
50-
<ArrowRight className="size-4" />
51-
</>
52-
)}
56+
<Link href={editorLink}>
57+
{loading ? (
58+
<Loader2 className="size-4 animate-spin" />
59+
) : (
60+
<>
61+
Open
62+
<ArrowRight className="size-4" />
63+
</>
64+
)}
65+
</Link>
5366
</Button>
5467
</div>
5568
</div>

packages/fern-dashboard/src/components/docs-page/GoToEditorButton.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,7 @@ export function GoToEditorButton({
6969
>
7070
<span className="pointer-events-auto">
7171
<Button disabled={isLoading || disabled || isValidatingSource} asChild={!disabled}>
72-
<Link
73-
className="flex flex-row items-center gap-1"
74-
href={editorSlug}
75-
onClick={handleClick}
76-
prefetch
77-
>
72+
<Link className="flex flex-row items-center gap-1" href={editorSlug} onClick={handleClick}>
7873
{isLoading ? (
7974
<Loader2 className="animate-spin" />
8075
) : (

0 commit comments

Comments
 (0)