Skip to content

Commit f4db65e

Browse files
sbawabestephencme
andauthored
fix(editor): ensure version and headertabs are aware of root slug alias (#4648)
Co-authored-by: Stephen Chen <[email protected]>
1 parent 2450623 commit f4db65e

File tree

7 files changed

+38
-14
lines changed

7 files changed

+38
-14
lines changed

packages/fern-dashboard/src/app/[orgName]/(visual-editor)/editor/[docsUrl]/[branch]/[...slug]/@headertabs/page.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { getTabs } from "@fern-api/docs-server/handle-node-fallbacks";
22
import * as FernNavigation from "@fern-api/fdr-sdk/navigation";
33
import { slugjoin } from "@fern-api/fdr-sdk/navigation";
44
import { HeaderTabsList } from "@fern-docs/components/HeaderTabsList";
5-
5+
import { getRootAliasAwareNavigationSlug } from "@fern-docs/components/navigation";
66
import { getCurrentSession } from "@/app/services/auth0/getCurrentSession";
77
import { getCachedEditableDocsLoader } from "@/app/services/docs-loader/cachedEditableDocsLoader";
88
import { getHostFromHeaders } from "@/utils/getHostFromHeaders";
@@ -35,7 +35,8 @@ export default async function HeaderTabsPage({
3535

3636
const showAuthenticatedNodes = (await loader.getEdgeFlags()).isAuthenticatedPagesDiscoverable;
3737

38-
const foundNode = FernNavigation.utils.findNode(root, slugjoin(slug));
38+
const navigationSlug = getRootAliasAwareNavigationSlug(slugjoin(slug), root);
39+
const foundNode = FernNavigation.utils.findNode(root, navigationSlug);
3940

4041
const tabs = getTabs(
4142
foundNode,

packages/fern-dashboard/src/app/[orgName]/(visual-editor)/editor/[docsUrl]/[branch]/[...slug]/@logo/page.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import { withLogo } from "@fern-api/docs-server/withLogo";
33
import * as FernNavigation from "@fern-api/fdr-sdk/navigation";
44
import { getPageId, slugjoin } from "@fern-api/fdr-sdk/navigation";
55
import { AbstractLogo } from "@fern-docs/components/abstract/logo";
6+
import { getRootAliasAwareNavigationSlug } from "@fern-docs/components/navigation";
67
import { getFrontmatter } from "@fern-docs/mdx";
7-
88
import { getCurrentSession } from "@/app/services/auth0/getCurrentSession";
99
import { getCachedEditableDocsLoader } from "@/app/services/docs-loader/cachedEditableDocsLoader";
1010
import { getHostFromHeaders } from "@/utils/getHostFromHeaders";
@@ -34,7 +34,8 @@ export default async function LogoPage({
3434
]);
3535

3636
const resolveFileSrc = createFileResolver(files);
37-
const foundNode = FernNavigation.utils.findNode(root, slugjoin(slug));
37+
const navigationSlug = getRootAliasAwareNavigationSlug(slugjoin(slug), root);
38+
const foundNode = FernNavigation.utils.findNode(root, navigationSlug);
3839

3940
let frontmatter = null;
4041
if (foundNode.type === "found") {

packages/fern-dashboard/src/app/[orgName]/(visual-editor)/editor/[docsUrl]/[branch]/[...slug]/@productSelect/page.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { getFallbackProduct } from "@fern-api/docs-server/handle-node-fallbacks"
44
import * as FernNavigation from "@fern-api/fdr-sdk/navigation";
55
import { slugjoin } from "@fern-api/fdr-sdk/navigation";
66
import { ProductDropdown } from "@fern-docs/components/header/ProductDropdown";
7+
import { getRootAliasAwareNavigationSlug } from "@fern-docs/components/navigation";
78
import { getCurrentSession } from "@/app/services/auth0/getCurrentSession";
89
import { getCachedEditableDocsLoader } from "@/app/services/docs-loader/cachedEditableDocsLoader";
910
import { getHostFromHeaders } from "@/utils/getHostFromHeaders";
@@ -34,9 +35,10 @@ export default async function ProductSelectPage({
3435
]);
3536
const useDenseLayout = layout.isHeaderDisabled;
3637

37-
const foundNode = FernNavigation.utils.findNode(root, slugjoin(slug));
38+
const navigationSlug = getRootAliasAwareNavigationSlug(slugjoin(slug), root);
39+
const foundNode = FernNavigation.utils.findNode(root, navigationSlug);
3840

39-
const fallbackProduct = getFallbackProduct(foundNode, root, slug);
41+
const fallbackProduct = getFallbackProduct(foundNode, root, navigationSlug);
4042
if (fallbackProduct == null) {
4143
return null;
4244
}

packages/fern-dashboard/src/app/[orgName]/(visual-editor)/editor/[docsUrl]/[branch]/[...slug]/@versionSelect/page.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { getFallbackProduct, getFallbackVersion } from "@fern-api/docs-server/ha
44
import * as FernNavigation from "@fern-api/fdr-sdk/navigation";
55
import { slugjoin } from "@fern-api/fdr-sdk/navigation";
66
import { VersionDropdown } from "@fern-docs/components/header/VersionDropdown";
7+
import { getRootAliasAwareNavigationSlug } from "@fern-docs/components/navigation";
78
import { getCurrentSession } from "@/app/services/auth0/getCurrentSession";
89
import { getCachedEditableDocsLoader } from "@/app/services/docs-loader/cachedEditableDocsLoader";
910
import { getHostFromHeaders } from "@/utils/getHostFromHeaders";
@@ -34,7 +35,8 @@ export default async function VersionSelectPage({
3435
]);
3536
const useDenseLayout = layout.isHeaderDisabled;
3637

37-
const foundNode = FernNavigation.utils.findNode(root, slugjoin(slug));
38+
const navigationSlug = getRootAliasAwareNavigationSlug(slugjoin(slug), root);
39+
const foundNode = FernNavigation.utils.findNode(root, navigationSlug);
3840
const collector = FernNavigation.NodeCollector.collect(root);
3941
const versionNodes = collector.getVersionNodes();
4042

packages/fern-dashboard/src/app/[orgName]/(visual-editor)/editor/[docsUrl]/[branch]/[...slug]/page.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import { AbstractLayoutEvaluatorContent } from "@fern-docs/components/layouts/Ab
66
import {
77
constructEditorSlug,
88
getEditorRedirectSlug,
9-
getSerializableFoundNode,
10-
ROOT_SLUG_ALIAS
9+
getRootAliasAwareNavigationSlug,
10+
getSerializableFoundNode
1111
} from "@fern-docs/components/navigation";
1212
import { getFrontmatter } from "@fern-docs/mdx";
1313

@@ -50,11 +50,8 @@ export default async function Page({
5050
branchName: branch
5151
});
5252

53-
const requestedSlug = slugjoin(slug);
5453
const root = await loader.getRoot();
55-
56-
// If requested slug == ROOT_SLUG_ALIAS ("root"), use slug from the root node instead
57-
const navigationSlug = requestedSlug === ROOT_SLUG_ALIAS ? root.slug : requestedSlug;
54+
const navigationSlug = getRootAliasAwareNavigationSlug(slugjoin(slug), root);
5855
const navigationNode = FernNavigation.utils.findNode(root, navigationSlug);
5956

6057
// Handle notFound case first - treat as potential client page instead of redirecting

packages/fern-docs/components/src/navigation/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ export {
1313
getAllSectionsFromSidebarRootNode,
1414
getClientPageDefaultFilename
1515
} from "./pageUtils";
16-
export { constructEditorSlug, getEditorRedirectSlug, ROOT_SLUG_ALIAS } from "./routingUtils";
16+
export {
17+
constructEditorSlug,
18+
getEditorRedirectSlug,
19+
getRootAliasAwareNavigationSlug,
20+
ROOT_SLUG_ALIAS
21+
} from "./routingUtils";
1722
export * from "./types";
1823
export * from "./useDerivedFoundNode";

packages/fern-docs/components/src/navigation/routingUtils.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,19 @@ function findFirstPageNode(
9191
}
9292
return undefined;
9393
}
94+
95+
/**
96+
* Returns the navigation slug to use for the requested slug, taking into account the root alias. This
97+
* is used within the Editor to ensure that first land into editor (which uses a root alias) calculates
98+
* the correct navigation slug to use.
99+
*
100+
* @param requestedSlug - The slug to find the navigation node for
101+
* @param root - The root node of the navigation tree
102+
* @returns The navigation slug to use for the requested slug, taking into account the root alias
103+
*/
104+
export function getRootAliasAwareNavigationSlug(
105+
requestedSlug: string,
106+
root: FernNavigation.RootNode
107+
): FernNavigation.Slug {
108+
return requestedSlug === ROOT_SLUG_ALIAS ? root.slug : FernNavigation.Slug(requestedSlug);
109+
}

0 commit comments

Comments
 (0)