Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prop mismatch, server: "null", client: "true" for a value computed by useState(false) #35558

Closed
1 task done
prscoelho opened this issue Mar 23, 2022 · 2 comments
Closed
1 task done
Labels
bug Issue was opened via the bug report template.

Comments

@prscoelho
Copy link

prscoelho commented Mar 23, 2022

Verify canary release

  • I verified that the issue exists in Next.js canary release

Provide environment information

Operating System:
      Platform: linux
      Arch: x64
      Version: #1 SMP PREEMPT Mon, 21 Mar 2022 22:59:40 +0000
    Binaries:
      Node: 17.7.2
      npm: 8.5.5
      Yarn: 1.22.18
      pnpm: N/A
    Relevant packages:
      next: 12.1.1-canary.17
      react: 17.0.2
      react-dom: 17.0.2

What browser are you using? (if relevant)

Firefox 98.0.2; Firefox developer edition 99.0b7

How are you deploying your application? (if relevant)

next dev

Describe the Bug

A page component renders two buttons, which are disabled depending on state of useState. Changing that state, and refreshing the page results in a Warning: Prop `disabled` did not match. Server: "null" Client: "true". Neither button is disabled, but one of them should be.

If I only render one button, the error doesn't happen anymore even after changing state and refreshing.

This only seems to happen on firefox, tested in chromium and it doesn't seem to happen.

I found this discussion, but no issue. The discussion seems to tend towards this being a firefox bug, but since it no longer happens once we go from two buttons to one, I figured I should file an issue.

Expected Behavior

There should be no mismatch, there's no difference between the server and client.

To Reproduce

import type { NextPage } from 'next'
import { useState } from 'react'

const Home: NextPage = () => {
  const [isDisabled, setDisabled] = useState(false)

  return (
    <div>
      <button disabled={isDisabled} onClick={() => setDisabled(true)}>disable</button>
      <button disabled={!isDisabled} onClick={() => setDisabled(false)}>enable</button>
    </div>
  )
}
export default Home

In firefox, click the button to change default state, refresh and it should result in Warning: Prop `disabled` did not match. Server: "null" Client: "true".

Comment out the second button, refresh, change default state and refresh again and there's no mismatch anymore.

@prscoelho prscoelho added the bug Issue was opened via the bug report template. label Mar 23, 2022
@prscoelho
Copy link
Author

Looks like this is a firefox bug indeed. I found these:

facebook/react#21459
https://bugzilla.mozilla.org/show_bug.cgi?id=654072
whatwg/html#7292

The fix for now is to set autoComplete='off, unfortunately this is a firefox only property so it's not in button prop interface, but you can trick typescript by spreading the autoComplete like this:

const extraProps = {
  autoComplete: 'off'
}
return <button {...extraProps}></button>

@github-actions
Copy link
Contributor

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template.
Projects
None yet
Development

No branches or pull requests

1 participant