Skip to content

Hydration issue in Firefox #31296

Closed as not planned
Closed as not planned

Description

@rvetrsek

Environment

  • Operating System: Linux
  • Node Version: v18.20.3
  • Nuxt Version: 3.16.0
  • CLI Version: 3.22.5
  • Nitro Version: 2.11.5
  • Package Manager: [email protected]
  • Builder: -
  • User Config: compatibilityDate, devtools, app
  • Runtime Modules: -
  • Build Modules: -

Reproduction

A reproduction of the issue can be found on StackBlitz

Describe the bug

I found an issue with a hydration mismatch with the Firefox browser. Going from a loaded state to a loading state works as expected, but going from a loading state to a loaded state does not work as expected in Firefox. All other browsers worked as expected.

Specifically, I made a custom button component and tried different sequences of going between the loading and loaded states.

Additional context

  1. Button 1: Immediate Transition on Mount

    • Initial state: loading = true
    • On mount: Immediately set loading = false
    • Expected Behavior: No hydration mismatch as we are waiting for the onMounted hook to complete before setting the loading state to false.
    • Actual Behavior: No hydration mismatch in Chrome, but there is a warning in Firefox if the page is refreshed, on a hard refresh or initial load there is no warning.
  2. Button 2: Transition After requestAnimationFrame

    • Initial state: loading = true
    • On mount: Set loading = false inside requestAnimationFrame
    • Expected Behavior: No hydration mismatch as we are waiting for the requestAnimationFrame to complete before setting the loading state to false.
    • Actual Behavior: No hydration mismatch in Chrome, but there is a warning in Firefox if the page is refreshed, on a hard refresh or initial load there is no warning.
  3. Button 3: Delayed Transition (1s)

    • Initial state: loading = true
    • On mount: Set loading = false after 1 second timeout
    • Expected Behavior: No hydration mismatch as we are waiting for the setTimeout to complete before setting the loading state to false.
    • Actual Behavior: No hydration mismatch in Chrome, but there is a warning in Firefox if the page is refreshed, on a hard refresh or initial load there is no warning.
  4. Button 4: Delayed Loading Start (1s)

    • Initial state: loading = false
    • On mount: Set loading = true after 1 second timeout
    • Expected Behavior: No hydration mismatch as we are waiting for the setTimeout to complete before setting the loading state to true.
    • Actual Behavior: No hydration mismatch in Chrome or Firefox.
  5. Button 5: Immediate Loading Start on Mount

    • Initial state: loading = false
    • On mount: Immediately set loading = true
    • Expected Behavior: No hydration mismatch as we are waiting for the onMounted hook to complete before setting the loading state to true.
    • Actual Behavior: No hydration mismatch in Chrome or Firefox.

Activity

  1. bolt-new-by-stackblitz commented on Mar 9, 2025

    @bolt-new-by-stackblitz
  2. rvetrsek commented on Mar 10, 2025

    @rvetrsek
    Author

    I learned from the Nuxt community (thank you, Kal) that there is a related issue on the Firefox repo and that this behaviour might be caused by how Firefox caches form elements when refreshing the pages. Specifically, it also caches the disabled state of form elements. When you initially load a page with a component that you go from a disabled to a not disabled state, it will cache it as a not disabled component. The server will want to load it as disabled upon refreshing, causing a hydration mismatch because the client wants to load it as not disabled.

    Firefox-related issue: Form restoration interop #7292

  3. huang-julien commented on Mar 12, 2025

    @huang-julien
    Member

    Hey 👋 great findings !
    Seems like it causes issues on different libraries. I think we'll close this issue for now as this can only be saved at firefox level

  4. added
    upstream
    and removed on Mar 12, 2025
  5. starcannxn commented on Jun 10, 2025

    @starcannxn

    Hello,
    I've been trying to solve the hydration mismatch for the past 20 minutes and finally noticed that it's only on Firefox, and went down the rabbit hole until I got to this open issue, so I'd like to add my findings, maybe they'll help.

    The hydration mismatch only happens specifically when:

    • The component in question is a form component, AND...
    • The component either in the Header or the Footer of the app

    The exact same component works with no warning elsewhere.
    I would also like to point out that I'm not using Nuxt UI.

    A band-aid "fix" was to just wrap the element in a client-only tag.

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

    upstreamworkaround available

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions