Open jmderby opened 1 month ago
I am using 'use client' and this issue does not arise
` export default function RootLayout({ children }: Readonly<{ children: React.ReactNode }>) { 'use client'
return (
<html lang="en" className={HarmonyOS.className}>
<body className={styles.appContainer}>
<Header></Header>
<ReduxProvider>
<AntdRegistry>{children}</AntdRegistry>
</ReduxProvider>
</body>
</html>
)
} `
I would rather not depend on 'use client';
in a layout component for performance and SEO reasons. Ideally, it would be rendered server-side
Link to the code that reproduces this issue
https://github.com/jmderby/min-repro-next-render-issue
To Reproduce
pnpm i
pnpm dev
Current vs. Expected behavior
TestProvider
's console log to print client-side.TestProvider
's console log client-side. There is sometimes an error that prints which is:Uncaught SyntaxError: Invalid or unexpected token (at layout.js)
Provide environment information
Which area(s) are affected? (Select all that apply)
create-next-app, Developer Experience, Runtime
Which stage(s) are affected? (Select all that apply)
next dev (local)
Additional context
This issue seems to be related to the interaction between Server Components, Client Components with Context Providers, and importing
globals.css
which contains the Tailwind directives from thelayout.tsx
Server Component. It persists even when following Next.js best practices for mixing Server, Client Components, and Context Providers.The issue is most noticeable immediately after starting the development server. If you refresh the page after the initial load, the app typically functions as expected. The problem primarily affects the first render following server startup.
A minimal reproduction repository has been created to demonstrate this issue.
This minimal reproduction was inspired by this Vercel guide of using React Context with Next.js: https://vercel.com/guides/react-context-state-management-nextjs