Skip to content

Commit 513bf01

Browse files
tianzhouclaude
andauthored
fix: resolve prefetch warning and getSidebar crash (#936)
- Extract prefetch prop in Link component to prevent React non-boolean attribute warning - Add validation in getSidebar to handle missing _layout.md files gracefully 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude <[email protected]>
1 parent 003821e commit 513bf01

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

src/components/shared/link/link.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ const Link = ({
4444
href,
4545
children,
4646
withArrow = false,
47+
prefetch,
4748
...props
4849
}: LinkProps) => {
4950
const linkClassName = clsx(
@@ -63,7 +64,7 @@ const Link = ({
6364

6465
if (href.startsWith('/')) {
6566
return (
66-
<NextLink className={linkClassName} href={href} {...props}>
67+
<NextLink className={linkClassName} href={href} prefetch={prefetch} {...props}>
6768
{content}
6869
</NextLink>
6970
);

src/lib/api-docs.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,12 @@ const getPostBySlug = (
2424
const source = fs.readFileSync(`${docsPath}/${slug}.md`);
2525
const { data, content } = matter(source);
2626

27-
const contentWithReplacements = content.replace(
28-
/%%bb_api_endpoint%%/g,
29-
(match) => {
30-
if (match === '%%bb_api_endpoint%%') {
31-
return API_ENDPOINT;
32-
}
33-
return match; // Just in case there's a match that doesn't fit any case
34-
},
35-
);
27+
const contentWithReplacements = content.replace(/%%bb_api_endpoint%%/g, (match) => {
28+
if (match === '%%bb_api_endpoint%%') {
29+
return API_ENDPOINT;
30+
}
31+
return match; // Just in case there's a match that doesn't fit any case
32+
});
3633

3734
return { data, content: contentWithReplacements };
3835
} catch (e) {
@@ -84,6 +81,11 @@ const getSidebar = (docsPath: string): { sidebar: SidebarItem[]; expandedList: s
8481

8582
const sidebar: SidebarItem[] = [];
8683

84+
// Check if layout file exists
85+
if (!layoutFile || !layoutFile[0]) {
86+
return { sidebar: [], expandedList: [] };
87+
}
88+
8789
const md = fs.readFileSync(layoutFile[0], 'utf-8');
8890
const { data, content } = matter(md);
8991

0 commit comments

Comments
 (0)