react-final-form icon indicating copy to clipboard operation
react-final-form copied to clipboard

[Bug v7.0.0] useField returns undefined value on initial render despite initialValues being set

Open yurii-oliiarnyk-finsight opened this issue 6 months ago • 6 comments

Description

Hi, thanks for your work on the library!

We're encountering a blocking issue when trying to migrate to [email protected] to prepare for React 19.

Problem

When initialValues are passed to the <Form />, the corresponding fields registered via useField initially return value: undefined. This was not the case in earlier versions.

It seems that the field state is now derived via form.getFieldState() during initialization here — but this runs before the field is registered here, so the field state is not available at that moment.

As a result:

Fields render with value: undefined on the first render. Components relying on the initial value (e.g., to initialize local state or trigger effects) fail or misbehave.

Expect result:

Fields render with defined value on initialize as it was before in v6.5.9

Sandbox Link

v6.5.9 https://codesandbox.io/p/sandbox/h7lk86 Logs: Image

v7.0.0 https://codesandbox.io/p/sandbox/6cd2fz Logs: Image

Noticed the same issue while migrating to expo 53/React 19. At first, I assumed there was something wrong with our ref usage and React 19 changes, but in the end I figured final-form might be at cause. In the end:

  • We kept the changes to expo53/react 19
  • Reverted to final-form:4.20.10 and react-final-form:6.5.9
  • Overrides were set for both package to use React-19 And everything seems to work fine. So there seems to be something that changed with the changes in 7.0.0, but haven't had the time to look at the code yet.

chevvy avatar Jul 23 '25 13:07 chevvy

Same issue on Expo 53/React 19, had to roll back to the pre-typescript version

lsapozh avatar Jul 30 '25 15:07 lsapozh

@chevvy What solution do you use for this?

  • Overrides were set for both package to use React-19

@chevvy What solution do you use for this?

  • Overrides were set for both package to use React-19

in my package.json:

{
  "dependencies": {
    "final-form": "^4.20.10",
    "react-final-form": "^6.5.9",
  },
  "overrides": {
    "react-final-form": {
      "react": "19.0.0"
    },
    "final-form": {
      "react": "19.0.0"
    }
  },
}

as of my comment last week, this still seems to be an adequate workaround, but your millage may vary!

chevvy avatar Aug 04 '25 17:08 chevvy

Too many bugs. In our code I notice them in different places. Some fields are empty. As we have complex dynamic field generation, it is hard to isolate it to provide a minimal example. I think this version should be reverted or fixed ASAP. It was declared as "There should be NO BREAKING CHANGES" but actually it is completely broken.

Dron007 avatar Aug 06 '25 12:08 Dron007

I've also been experiencing this, I'll spend some time on it and see if I can get get the initial value behavior back to how it was before

joshua-burbidge avatar Dec 02 '25 20:12 joshua-burbidge