The code returns the following error:
Encountered a script tag while rendering React component. Scripts inside React components are never executed when rendering on the client. Consider using template tag instead (https://developer.mozilla.org/en-US/docs/Web/HTML/Element/template).
Revise the code to address the error.
I was previewing: /
Let me check the debug logs and look for where the script tag might be:
The error is about a script tag. The issue is likely coming from next-themes injecting a script tag. Let me check the theme-toggle component and search for any script tags:
The issue is the next-themes package - it injects a script tag to prevent theme flash. Since we're using a custom theme system with data-theme attributes, I'll simplify the ThemeProvider to not use next-themes and handle everything ourselves cleanly:
Now I need to update the layout.tsx to remove the next-themes props since we're no longer using it:
I've fixed the script tag error by removing the next-themes dependency from the ThemeProvider. The issue was that next-themes injects a script tag to prevent flash of incorrect theme, which React warns against when rendering on the client. The custom ThemeProvider now handles the Dawn/Dusk theme switching entirely through React state and useEffect, without any script tag injection.
Now let me read the theme-toggle and theme-provider to understand the issue:
I see the issue. The ThemeProvider returns children without the context wrapper when not mounted (if (!mounted) return <>{children}</>). This means ThemeToggle tries to use the context before it's available. I need to always wrap children in the provider, but conditionally show the toggle UI:
Now update the ThemeToggle to handle the mounted state:
I've fixed the issue by always wrapping children in the ThemeContext.Provider and adding a mounted flag to the context. The ThemeToggle now checks the mounted state and shows a disabled placeholder button during initial hydration. This ensures the context is always available when useTheme is called, while still preventing hydration mismatches.