Skip to content

Commit 1e026ca

Browse files
authored
fix: Resolve dev server warnings and errors (#453)
- Removes `pageExtensions` from `next.config.mjs`. Explicitly defining this key caused spurious "Duplicate page detected" warnings during development. Relying on the Nextra default resolves the issue. - Addresses a `useLayoutEffect` warning during SSR caused by the `AskCookbook` component. Attempts to use `next/dynamic` directly in `_app.mdx` led to MDX parsing errors. - Introduces `ClientOnlyAskCookbook.tsx`, a wrapper component that dynamically imports `AskCookbook` with `ssr: false` to ensure client-side rendering. - Updates `_app.mdx` to use the `ClientOnlyAskCookbook` wrapper and removes leftover comments from previous troubleshooting steps.
1 parent 56b07cf commit 1e026ca

File tree

3 files changed

+35
-21
lines changed

3 files changed

+35
-21
lines changed

next.config.mjs

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,36 @@
1-
import nextra from 'nextra'
2-
import path from 'path'
3-
import remarkCodeImport from 'remark-code-import'
4-
import { fileURLToPath } from 'url'
1+
import nextra from "nextra";
2+
import path from "path";
3+
import remarkCodeImport from "remark-code-import";
4+
import { fileURLToPath } from "url";
55

6-
const __dirname = path.dirname(fileURLToPath(import.meta.url))
6+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
77

88
const withNextra = nextra({
9-
theme: 'nextra-theme-docs',
10-
themeConfig: './theme.config.tsx',
9+
theme: "nextra-theme-docs",
10+
themeConfig: "./theme.config.tsx",
1111
defaultShowCopyCode: true,
1212
mdxOptions: {
13-
remarkPlugins: [
14-
remarkCodeImport,
15-
]
16-
}
17-
})
13+
remarkPlugins: [remarkCodeImport],
14+
},
15+
});
1816

1917
const config = withNextra({
2018
eslint: {
2119
ignoreDuringBuilds: true,
2220
},
2321
images: {
24-
unoptimized: true
22+
unoptimized: true,
2523
},
2624
webpack: (config) => {
2725
config.resolve.alias = {
2826
...config.resolve.alias,
29-
'@': path.join(__dirname, 'src'),
30-
}
31-
return config
27+
"@": path.join(__dirname, "src"),
28+
};
29+
return config;
3230
},
33-
pageExtensions: ['js', 'jsx', 'md', 'mdx', 'ts', 'tsx'],
3431
experimental: {
3532
mdxRs: true,
3633
},
37-
})
34+
});
3835

39-
export default config
36+
export default config;
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import React from "react";
2+
import dynamic from "next/dynamic";
3+
4+
// Dynamically import the original AskCookbook component with SSR disabled
5+
const AskCookbookDynamic = dynamic(
6+
() => import("./AskCookbook").then((mod) => mod.AskCookbook),
7+
{
8+
ssr: false,
9+
}
10+
);
11+
12+
// This wrapper component simply renders the dynamically imported one
13+
const ClientOnlyAskCookbook: React.FC = () => {
14+
return <AskCookbookDynamic />;
15+
};
16+
17+
export default ClientOnlyAskCookbook;

src/pages/_app.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { ThemeProvider } from "next-themes";
22
import Script from "next/script";
33
import { inter, plus_jakarta_sans } from "../fonts";
4-
import { AskCookbook } from "../components/AskCookbook";
4+
import ClientOnlyAskCookbook from "../components/ClientOnlyAskCookbook";
55
import "../globals.css";
66

77
export default function App({ Component, pageProps }) {
@@ -39,7 +39,7 @@ export default function App({ Component, pageProps }) {
3939
<Component {...pageProps} />
4040
</div>
4141
</div>
42-
<AskCookbook />
42+
<ClientOnlyAskCookbook />
4343
</ThemeProvider>
4444
);
4545
}

0 commit comments

Comments
 (0)