Skip to content

Commit e6da352

Browse files
committed
speed up branch list, refactor loading to better utilize suspenses
1 parent 4df409f commit e6da352

File tree

21 files changed

+398
-547
lines changed

21 files changed

+398
-547
lines changed

packages/commons/docs-loader/src/editable-docs-loader.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,6 @@ export const createEditableDocsLoader = async ({
195195
const docsLoader = await createCachedDocsLoader(host, encodeDocsLoaderDomain(domain, branchName), fernToken, {
196196
returnRawMarkdown: true,
197197
cacheConfig: {
198-
// For editable docs, we want shorter TTL so that cache stays fresh
199-
kvTtl: 5 * 60, // 5 minutes
200198
cacheKeySuffix: "editable",
201199
forceRevalidate
202200
},

packages/fern-dashboard/src/app/[orgName]/(homepage)/docs/[docsUrl]/page.tsx

Lines changed: 9 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,18 @@ import getDocsSitesForOrg from "@/app/services/dal/fdr/getDocsSitesForOrg";
88
import { getDocsGithubUrl } from "@/app/services/dal/github/getDocsGithubUrl";
99
import { getAuthenticatedSessionOrRedirect } from "@/app/services/dal/organization";
1010
import { DocsSiteOverviewCard } from "@/components/docs-page/DocsSiteOverviewCard";
11-
import { FernCliVersionDisplayAsync } from "@/components/docs-page/FernCliVersionDisplayAsync";
12-
import { GithubSourceAsync } from "@/components/docs-page/GithubSourceAsync";
13-
import { VisualEditorSectionAsync } from "@/components/docs-page/visual-editor-section/VisualEditorSectionAsync";
14-
import { Skeleton } from "@/components/ui/skeleton";
11+
import { VisualEditorEmptyCard } from "@/components/docs-page/visual-editor-section/VisualEditorEmptyCard";
12+
import { VisualEditorSection } from "@/components/docs-page/visual-editor-section/VisualEditorSection";
1513
import { getDocsSiteUrl } from "@/utils/getDocsSiteUrl";
1614
import { parseDocsUrlParam } from "@/utils/parseDocsUrlParam";
1715
import type { EncodedDocsUrl } from "@/utils/types";
1816

19-
export default async function Page(props: {
20-
params: Promise<{ orgName: Auth0OrgName; docsUrl: EncodedDocsUrl }>;
21-
searchParams: Promise<{ [key: string]: string | string[] | undefined }>;
22-
}) {
17+
export default async function Page(props: { params: Promise<{ orgName: Auth0OrgName; docsUrl: EncodedDocsUrl }> }) {
2318
const { orgName, docsUrl: encodedDocsUrl } = await props.params;
24-
const searchParams = await props.searchParams;
2519

2620
const session = await getAuthenticatedSessionOrRedirect(orgName);
2721
const docsUrl = parseDocsUrlParam({ docsUrl: encodedDocsUrl });
2822

29-
// Only skip cache if explicitly requested via query param (e.g., ?refresh=true)
30-
const skipCache = searchParams.refresh === "true";
31-
3223
// Validate that the docsUrl belongs to this organization so that we avoid errors in the page
3324
const response = await getDocsSitesForOrg({
3425
orgName,
@@ -44,42 +35,16 @@ export default async function Page(props: {
4435
}
4536

4637
// Start expensive operations in parallel without awaiting
47-
// These promises will be passed to async components that will await them independently
48-
// This allows React to render the page shell and fallbacks immediately
49-
const githubUrlPromise = getDocsGithubUrl(docsUrl, session.accessToken);
50-
const githubAuthStatePromise = getGitHubAuthState(docsUrl, session.accessToken, orgName, docsUrl, session);
38+
Promise.all([
39+
getDocsGithubUrl(docsUrl, session.accessToken),
40+
getGitHubAuthState(docsUrl, session.accessToken, orgName, docsUrl, session)
41+
]);
5142

5243
return (
5344
<div className="flex w-full flex-col gap-4">
54-
<DocsSiteOverviewCard
55-
docsSite={currentDocsSite}
56-
githubProtectedArea={
57-
<div className="flex flex-wrap gap-x-10 gap-y-4">
58-
<div className="flex w-fit flex-col gap-2">
59-
<p>Source</p>
60-
<Suspense fallback={<Skeleton className="h-4 w-24" />}>
61-
<GithubSourceAsync docsUrl={docsUrl} githubUrlPromise={githubUrlPromise} />
62-
</Suspense>
63-
</div>
64-
<Suspense fallback={<Skeleton className="h-4 w-24" />}>
65-
<FernCliVersionDisplayAsync
66-
orgName={orgName}
67-
docsUrl={docsUrl}
68-
githubUrlPromise={githubUrlPromise}
69-
githubAuthStatePromise={githubAuthStatePromise}
70-
/>
71-
</Suspense>
72-
</div>
73-
}
74-
/>
45+
<DocsSiteOverviewCard docsUrl={docsUrl} docsSite={currentDocsSite} orgName={orgName} />
7546
<Suspense fallback={null}>
76-
<VisualEditorSectionAsync
77-
docsUrl={docsUrl}
78-
session={session}
79-
orgName={orgName}
80-
githubUrlPromise={githubUrlPromise}
81-
githubAuthStatePromise={githubAuthStatePromise}
82-
/>
47+
<VisualEditorSection docsUrl={docsUrl} session={session} orgName={orgName} />
8348
</Suspense>
8449
</div>
8550
);

packages/fern-dashboard/src/app/actions/getDocsGithubMetadata.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import { fernToken_admin } from "@fern-api/docs-server";
44

5-
import type { GithubAuthState } from "@/components/docs-page/GithubSource";
5+
import type { GithubAuthState } from "@/components/docs-page/GithubSourceClient";
66
import { getDocsUrlMetadata } from "../api/utils/getDocsUrlMetadata";
77
import { type Auth0SessionData, getCurrentSessionOrThrow } from "../services/auth0/getCurrentSession";
88
import type { Auth0OrgName } from "../services/auth0/types";

packages/fern-dashboard/src/app/actions/getGithubMetadata.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
11
import "server-only";
22
import { cache } from "react";
3-
import type { GithubAuthState } from "@/components/docs-page/GithubSource";
4-
import { getGithubSourceMetadata } from "./getGithubSourceMetadata";
3+
import type { GithubAuthState } from "@/components/docs-page/GithubSourceClient";
54
import type { Auth0SessionData } from "../services/auth0/getCurrentSession";
65
import type { Auth0OrgName } from "../services/auth0/types";
76
import { type GetDocsGithubUrlResult, getDocsGithubUrl } from "../services/dal/github/getDocsGithubUrl";
87
import { validateGithubRepoAccess } from "../services/dal/github/validators";
8+
import { getGithubSourceMetadata } from "./getGithubSourceMetadata";
99

1010
type GetDocsGithubUrlError = Extract<GetDocsGithubUrlResult, { success: false }>["error"];
1111

12-
export type GetGitHubAuthStateResult =
13-
| GithubAuthState
14-
| { success: false; error: GetDocsGithubUrlError };
12+
export type GetGitHubAuthStateResult = GithubAuthState | { success: false; error: GetDocsGithubUrlError };
1513

1614
export const getGitHubAuthState = cache(
17-
async (url: string, token: string, orgName: Auth0OrgName, docsUrl: string, session: Auth0SessionData): Promise<GetGitHubAuthStateResult> => {
15+
async (
16+
url: string,
17+
token: string,
18+
orgName: Auth0OrgName,
19+
docsUrl: string,
20+
session: Auth0SessionData
21+
): Promise<GetGitHubAuthStateResult> => {
1822
const urlResult = await getDocsGithubUrl(url, token);
1923
if (!urlResult.success) {
2024
return { success: false, error: urlResult.error };

packages/fern-dashboard/src/app/services/dal/github/getFernVersionUpdateInfo.ts

Lines changed: 39 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -20,49 +20,48 @@ export type GetFernVersionUpdateInfoResult = {
2020

2121
export type GetFernVersionUpdateInfoError = GetFernVersionFromRepoError | { type: "MALFORMED_INPUT" };
2222

23-
export async function getFernVersionUpdateInfo({
24-
githubUrl,
25-
docsUrl,
26-
baseBranch
27-
}: {
28-
githubUrl?: string;
29-
docsUrl?: DocsUrl;
30-
baseBranch?: string;
31-
}): Promise<
32-
{ ok: true; result: GetFernVersionUpdateInfoResult } | { ok: false; error: GetFernVersionUpdateInfoError }
33-
> {
34-
"use cache";
35-
if (githubUrl == null || baseBranch == null || docsUrl == null) {
36-
return { ok: false, error: { type: "MALFORMED_INPUT" } };
37-
}
23+
import { cache } from "react";
24+
25+
export const getFernVersionUpdateInfo = cache(
26+
async (
27+
githubUrl: string,
28+
docsUrl: DocsUrl,
29+
baseBranch: string
30+
): Promise<
31+
{ ok: true; result: GetFernVersionUpdateInfoResult } | { ok: false; error: GetFernVersionUpdateInfoError }
32+
> => {
33+
if (githubUrl == null || baseBranch == null || docsUrl == null) {
34+
return { ok: false, error: { type: "MALFORMED_INPUT" } };
35+
}
3836

39-
const [fernVersionResult, latestVersion] = await Promise.all([
40-
getFernVersionFromRepo(githubUrl, docsUrl),
41-
getLatestFernCliVersion()
42-
]);
37+
const [fernVersionResult, latestVersion] = await Promise.all([
38+
getFernVersionFromRepo(githubUrl, docsUrl),
39+
getLatestFernCliVersion()
40+
]);
4341

44-
if (!fernVersionResult.ok) {
45-
return { ok: false, error: fernVersionResult.error };
46-
}
42+
if (!fernVersionResult.ok) {
43+
return { ok: false, error: fernVersionResult.error };
44+
}
4745

48-
const needsUpgrade = compareVersions(fernVersionResult.version, latestVersion);
49-
const isBelowMinimum = compareVersions(fernVersionResult.version, MIN_VE_CLI_VERSION);
46+
const needsUpgrade = compareVersions(fernVersionResult.version, latestVersion);
47+
const isBelowMinimum = compareVersions(fernVersionResult.version, MIN_VE_CLI_VERSION);
5048

51-
let existingPr;
49+
let existingPr;
5250

53-
// Show version info if any update is available
54-
if (needsUpgrade) {
55-
// Check if there's already an existing upgrade PR
56-
existingPr = await checkUpgradePrStatus(githubUrl, fernVersionResult.version, latestVersion, baseBranch);
57-
}
58-
return {
59-
ok: true,
60-
result: {
61-
current: fernVersionResult.version,
62-
latest: latestVersion,
63-
needsUpgrade,
64-
isBelowMinimum,
65-
existingPr
51+
// Show version info if any update is available
52+
if (needsUpgrade) {
53+
// Check if there's already an existing upgrade PR
54+
existingPr = await checkUpgradePrStatus(githubUrl, fernVersionResult.version, latestVersion, baseBranch);
6655
}
67-
};
68-
}
56+
return {
57+
ok: true,
58+
result: {
59+
current: fernVersionResult.version,
60+
latest: latestVersion,
61+
needsUpgrade,
62+
isBelowMinimum,
63+
existingPr
64+
}
65+
};
66+
}
67+
);

packages/fern-dashboard/src/app/services/dal/mongodb/getRelevantUserBranchesForSite.ts

Lines changed: 0 additions & 60 deletions
This file was deleted.

0 commit comments

Comments
 (0)