Skip to content

fix: Theme hydration mismatch on html element #104

Closed

Description

@larryro

Problem Statement

Next.js hydration mismatch error occurring on the <html> element due to next-themes applying className="light" and style={{color-scheme:"light"}} attributes client-side that don't exist in the server-rendered HTML.

Current State

  • Server: <html lang={locale}> (no theme attributes)
  • Client: <html lang={locale} className="light" style={{color-scheme:"light"}}> (modified by next-themes)

This triggers a React hydration warning in the console.

Proposed Solution

Add suppressHydrationWarning attribute to the <html> element in the root layout. This is the official recommended approach by next-themes.

Affected Components

  • services/platform/app/(app)/layout.tsx - Root layout file

Acceptance Criteria

  • No hydration mismatch warning in browser console
  • Theme switching continues to work correctly
  • SSR remains functional

🤖 Generated with Claude Code

Activity

  1. larryro commented on Jan 8, 2026

    @larryro
    ContributorAuthor

    Implementation Plan

    Step 1: Update root layout

    Modify services/platform/app/(app)/layout.tsx line 67:

    - <html lang={locale}>
    + <html lang={locale} suppressHydrationWarning>

    Files to Modify

    File Changes
    services/platform/app/(app)/layout.tsx Add suppressHydrationWarning to <html> element

    Why This Works

    suppressHydrationWarning tells React to skip hydration mismatch warnings for that specific element. This is necessary because:

    1. Theme detection requires client-side JavaScript (to read localStorage or system preference)
    2. The server cannot know the user's theme preference
    3. The mismatch is intentional and expected behavior from next-themes

    Risk Assessment

    • Low risk: Standard, well-documented pattern used by many Next.js applications
    • No functional change: Only suppresses the expected console warning
    • Production-ready: Recommended by next-themes documentation

    Testing Strategy

    • Run the application locally and verify no hydration warning in console
    • Verify theme switching (light/dark) still works correctly
    • Test with system preference changes
    • Verify SSR content renders correctly

    🤖 Generated with Claude Code

  2. larryro commented on Jan 8, 2026

    @larryro
    ContributorAuthor
    Image
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority: low

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions