Skip to content

Commit cf7a540

Browse files
madster456N2D4
andauthored
fix links and redirect issues on components index page (#796)
<!-- Make sure you've read the CONTRIBUTING.md guidelines: https://github.com/stack-auth/stack-auth/blob/dev/CONTRIBUTING.md --> Fixes broken links on /docs/{platform}/components pagse to now work, and fixes redirect when switching off of react-like platforms when on components or sdk pages. <!-- ELLIPSIS_HIDDEN --> ---- > [!IMPORTANT] > Fixes broken links and redirect issues on components index page by updating paths and improving URL handling logic. > > - **Behavior**: > - Fixes broken links on `/docs/{platform}/components` pages by updating relative paths in `index.mdx`. > - Corrects redirect logic when switching platforms on components or SDK pages in `docs-layout-router.tsx`. > - **Functions**: > - Adds `joinUrlPath()` in `generate-platform-navigation.js` to safely join URL path segments. > - Updates `pageExistsForPlatform()` in `generate-platform-navigation.js` to handle `/index.mdx` paths. > - **Misc**: > - Adds type safety checks for platform handling in `docs-layout-router.tsx`. > > <sup>This description was created by </sup>[<img alt="Ellipsis" src="https://img.shields.io/badge/Ellipsis-blue?color=175173">](https://www.ellipsis.dev?ref=stack-auth%2Fstack-auth&utm_source=github&utm_medium=referral)<sup> for 0a5337d. You can [customize](https://app.ellipsis.dev/stack-auth/settings/summaries) this summary. It will automatically update as commits are pushed.</sup> <!-- ELLIPSIS_HIDDEN --> --------- Co-authored-by: Konsti Wohlwend <n2d4xc@gmail.com>
1 parent 35b96c7 commit cf7a540

3 files changed

Lines changed: 42 additions & 21 deletions

File tree

docs/scripts/generate-platform-navigation.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ function joinUrlPath(...segments: string[]): string {
6161
return segments
6262
.filter(segment => segment && segment.length > 0)
6363
.join('/')
64-
.replace(/\/+/g, '/'); // Remove duplicate slashes
64+
.replace(/\\/+/g, '/'); // Remove duplicate slashes
6565
}
6666
6767
/**
@@ -79,7 +79,7 @@ export function pageExistsForPlatform(path: string, platform: Platform): boolean
7979
if (!page && !pathWithExt.includes('/index.mdx')) {
8080
const indexPath = normalizedPath.endsWith('.mdx')
8181
? normalizedPath.replace('.mdx', '/index.mdx')
82-
: joinUrlPath(normalizedPath, 'index.mdx');
82+
: \`\${normalizedPath}/index.mdx\`;
8383
page = PLATFORM_PAGES.find(p => p.path === indexPath);
8484
}
8585

docs/src/components/layouts/docs-layout-router.tsx

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ import type { PageTree } from 'fumadocs-core/server';
3030
import { usePathname } from 'next/navigation';
3131
import type { ReactNode } from 'react';
3232
import { useMemo } from 'react';
33-
import { getSmartRedirectUrl } from '../../lib/navigation-utils';
34-
import { getCurrentPlatform, PLATFORMS } from '../../lib/platform-utils';
33+
import { getSmartRedirectUrl, platformSupportsComponents, platformSupportsSDK } from '../../lib/navigation-utils';
34+
import { getCurrentPlatform, PLATFORMS, type Platform } from '../../lib/platform-utils';
3535
import type { Option } from '../layout/root-toggle';
3636
import { PlatformRedirect } from '../platform-redirect';
3737
import { ApiSidebarContent } from './api/api-sidebar';
@@ -149,18 +149,39 @@ export function DynamicDocsLayout({ children, ...props }: DynamicDocsLayoutProps
149149
// Extract current platform from pathname
150150
const currentPlatform = getCurrentPlatform(pathname);
151151

152+
// Helper function to safely cast platform to Platform type
153+
const isPlatform = (platform: string): platform is Platform => {
154+
return ['next', 'react', 'js', 'python'].includes(platform);
155+
};
156+
152157
return PLATFORMS.map(platform => {
158+
// Safe type guard - if this fails, something is seriously wrong with PLATFORMS constant
159+
if (!isPlatform(platform)) {
160+
console.error(`Invalid platform in PLATFORMS array: ${platform}`);
161+
// Fallback to a safe default to prevent runtime errors
162+
platform = 'next';
163+
}
164+
165+
const platformType = platform as Platform;
153166
let url: string;
154167

155168
if (isInSdkSection(pathname)) {
156-
// For SDK section: /docs/platform/sdk
157-
url = `/docs/${platform}/sdk`;
169+
// For SDK section: check if platform supports SDK, otherwise use smart redirect
170+
if (platformSupportsSDK(platformType)) {
171+
url = `/docs/${platform}/sdk`;
172+
} else {
173+
url = getSmartRedirectUrl(pathname, platformType);
174+
}
158175
} else if (isInComponentsSection(pathname)) {
159-
// For Components section: /docs/platform/components
160-
url = `/docs/${platform}/components`;
176+
// For Components section: check if platform supports components, otherwise use smart redirect
177+
if (platformSupportsComponents(platformType)) {
178+
url = `/docs/${platform}/components`;
179+
} else {
180+
url = getSmartRedirectUrl(pathname, platformType);
181+
}
161182
} else {
162183
// For normal docs: use smart redirect
163-
url = getSmartRedirectUrl(pathname, platform);
184+
url = getSmartRedirectUrl(pathname, platformType);
164185
}
165186

166187
return {

docs/templates/components/index.mdx

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,47 +42,47 @@ To get started with Stack Auth in your Next.js application, follow the [setup gu
4242
## Sign In and Sign Up
4343

4444
<CardGroup>
45-
<Card href="../components/sign-in" >
45+
<Card href="./components/sign-in" >
4646
<div className="components-card-content">
4747
<div className="img-wrapper">
4848
<img src="/imgs/sign-in.png" alt="SignIn" className="stack-200h" />
4949
</div>
5050
&lt;SignIn /&gt;
5151
</div>
5252
</Card>
53-
<Card href="../components/sign-up">
53+
<Card href="./components/sign-up">
5454
<div className="components-card-content">
5555
<div className="img-wrapper">
5656
<img src="/imgs/sign-up.png" alt="SignUp" className="stack-200h" />
5757
</div>
5858
&lt;SignUp /&gt;
5959
</div>
6060
</Card>
61-
<Card href="../components/credential-sign-in">
61+
<Card href="./components/credential-sign-in">
6262
<div className="components-card-content">
6363
<div className="img-wrapper">
6464
<img src="/imgs/credential-sign-in.png" alt="CredentialSignIn" className="stack-150h" />
6565
</div>
6666
&lt;CredentialSignIn /&gt;
6767
</div>
6868
</Card>
69-
<Card href="../components/credential-sign-up">
69+
<Card href="./components/credential-sign-up">
7070
<div className="components-card-content">
7171
<div className="img-wrapper">
7272
<img src="/imgs/credential-sign-up.png" alt="CredentialSignUp" className="stack-200h" />
7373
</div>
7474
&lt;CredentialSignUp /&gt;
7575
</div>
7676
</Card>
77-
<Card href="../components/oauth-button">
77+
<Card href="./components/oauth-button">
7878
<div className="components-card-content">
7979
<div className="img-wrapper">
8080
<img src="/imgs/oauth-button.png" alt="OAuthButton" className="stack-50h" />
8181
</div>
8282
&lt;OAuthButton /&gt;
8383
</div>
8484
</Card>
85-
<Card href="../components/oauth-button-group">
85+
<Card href="./components/oauth-button-group">
8686
<div className="components-card-content">
8787
<div className="img-wrapper">
8888
<img src="/imgs/oauth-button-group.png" alt="OAuthButtonGroup" className="stack-200h" />
@@ -96,15 +96,15 @@ To get started with Stack Auth in your Next.js application, follow the [setup gu
9696
## User
9797

9898
<CardGroup>
99-
<Card href="../components/user-button">
99+
<Card href="./components/user-button">
100100
<div className="components-card-content">
101101
<div className="img-wrapper">
102102
<img src="/imgs/user-button.png" alt="UserButton" className="stack-200h" />
103103
</div>
104104
&lt;UserButton /&gt;
105105
</div>
106106
</Card>
107-
<Card href="../components/account-settings">
107+
<Card href="./components/account-settings">
108108
<div className="components-card-content">
109109
<div className="img-wrapper">
110110
<img src="/imgs/account-settings.png" alt="AccountSettings" className="stack-100h" />
@@ -118,7 +118,7 @@ To get started with Stack Auth in your Next.js application, follow the [setup gu
118118
## Teams & Organizations
119119

120120
<CardGroup>
121-
<Card href="../components/selected-team-switcher">
121+
<Card href="./components/selected-team-switcher">
122122
<div className="components-card-content">
123123
<div className="img-wrapper">
124124
<img src="/imgs/selected-team-switcher.png" alt="SelectedTeamSwitcher" className="stack-200h" />
@@ -131,17 +131,17 @@ To get started with Stack Auth in your Next.js application, follow the [setup gu
131131
## Utilities
132132

133133
<CardGroup>
134-
<Card href="../components/stack-handler">
134+
<Card href="./components/stack-handler">
135135
<div className="components-card-content">
136136
&lt;StackHandler /&gt;
137137
</div>
138138
</Card>
139-
<Card href="../components/stack-provider">
139+
<Card href="./components/stack-provider">
140140
<div className="components-card-content">
141141
&lt;StackProvider /&gt;
142142
</div>
143143
</Card>
144-
<Card href="../components/stack-theme">
144+
<Card href="./components/stack-theme">
145145
<div className="components-card-content">
146146
&lt;StackTheme /&gt;
147147
</div>

0 commit comments

Comments
 (0)