File tree Expand file tree Collapse file tree 7 files changed +38
-14
lines changed
fern-dashboard/src/app/[orgName]/(visual-editor)/editor/[docsUrl]/[branch]/[...slug]
fern-docs/components/src/navigation Expand file tree Collapse file tree 7 files changed +38
-14
lines changed Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ import { getTabs } from "@fern-api/docs-server/handle-node-fallbacks";
22import * as FernNavigation from "@fern-api/fdr-sdk/navigation" ;
33import { slugjoin } from "@fern-api/fdr-sdk/navigation" ;
44import { HeaderTabsList } from "@fern-docs/components/HeaderTabsList" ;
5-
5+ import { getRootAliasAwareNavigationSlug } from "@fern-docs/components/navigation" ;
66import { getCurrentSession } from "@/app/services/auth0/getCurrentSession" ;
77import { getCachedEditableDocsLoader } from "@/app/services/docs-loader/cachedEditableDocsLoader" ;
88import { 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 ,
Original file line number Diff line number Diff line change @@ -3,8 +3,8 @@ import { withLogo } from "@fern-api/docs-server/withLogo";
33import * as FernNavigation from "@fern-api/fdr-sdk/navigation" ;
44import { getPageId , slugjoin } from "@fern-api/fdr-sdk/navigation" ;
55import { AbstractLogo } from "@fern-docs/components/abstract/logo" ;
6+ import { getRootAliasAwareNavigationSlug } from "@fern-docs/components/navigation" ;
67import { getFrontmatter } from "@fern-docs/mdx" ;
7-
88import { getCurrentSession } from "@/app/services/auth0/getCurrentSession" ;
99import { getCachedEditableDocsLoader } from "@/app/services/docs-loader/cachedEditableDocsLoader" ;
1010import { 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" ) {
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import { getFallbackProduct } from "@fern-api/docs-server/handle-node-fallbacks"
44import * as FernNavigation from "@fern-api/fdr-sdk/navigation" ;
55import { slugjoin } from "@fern-api/fdr-sdk/navigation" ;
66import { ProductDropdown } from "@fern-docs/components/header/ProductDropdown" ;
7+ import { getRootAliasAwareNavigationSlug } from "@fern-docs/components/navigation" ;
78import { getCurrentSession } from "@/app/services/auth0/getCurrentSession" ;
89import { getCachedEditableDocsLoader } from "@/app/services/docs-loader/cachedEditableDocsLoader" ;
910import { 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 }
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import { getFallbackProduct, getFallbackVersion } from "@fern-api/docs-server/ha
44import * as FernNavigation from "@fern-api/fdr-sdk/navigation" ;
55import { slugjoin } from "@fern-api/fdr-sdk/navigation" ;
66import { VersionDropdown } from "@fern-docs/components/header/VersionDropdown" ;
7+ import { getRootAliasAwareNavigationSlug } from "@fern-docs/components/navigation" ;
78import { getCurrentSession } from "@/app/services/auth0/getCurrentSession" ;
89import { getCachedEditableDocsLoader } from "@/app/services/docs-loader/cachedEditableDocsLoader" ;
910import { 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
Original file line number Diff line number Diff line change @@ -6,8 +6,8 @@ import { AbstractLayoutEvaluatorContent } from "@fern-docs/components/layouts/Ab
66import {
77 constructEditorSlug ,
88 getEditorRedirectSlug ,
9- getSerializableFoundNode ,
10- ROOT_SLUG_ALIAS
9+ getRootAliasAwareNavigationSlug ,
10+ getSerializableFoundNode
1111} from "@fern-docs/components/navigation" ;
1212import { 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
Original file line number Diff line number Diff 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" ;
1722export * from "./types" ;
1823export * from "./useDerivedFoundNode" ;
Original file line number Diff line number Diff 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+ }
You can’t perform that action at this time.
0 commit comments