Repository navigation
Closed as not planned
Labels
Description
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
-
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.
- Initial state:
-
Button 2: Transition After requestAnimationFrame
- Initial state:
loading = true - On mount: Set
loading = falseinsiderequestAnimationFrame - 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.
- Initial state:
-
Button 3: Delayed Transition (1s)
- Initial state:
loading = true - On mount: Set
loading = falseafter 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.
- Initial state:
-
Button 4: Delayed Loading Start (1s)
- Initial state:
loading = false - On mount: Set
loading = trueafter 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.
- Initial state:
-
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.
- Initial state:
Reacted by Felix
Activity
bolt-new-by-stackblitz commentedon Mar 9, 2025
rvetrsek commentedon Mar 10, 2025
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
huang-julien commentedon Mar 12, 2025
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
starcannxn commentedon Jun 10, 2025
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 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.