final-form / final-form

🏁 Framework agnostic, high performance, subscription-based form state management

Home Page:https://final-form.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Regression: props.initialValues isn't being updated

doytch opened this issue · comments

Are you submitting a bug report or a feature request?

Bug Report

What is the current behavior?

The <Form> render props version of initialValues isn't being updated correctly in some situations. We change the value we pass to the Form's initialValues during loading of a page and the rendered component's props.initialValues stay the initial iV, an empty object.

We have working environments with FF 4.18.5 and RFF 6.3.0, but environments with FF 4.18.6 and 6.3.3 exhibit the above failing behaviour.

What is the expected behavior?

props.initialValues should always have the latest current value.

Sandbox Link

I've tried, but have been unable to reproduce here.

What's your environment?

FF 4.18.6
RFF 6.3.3

An interesting behaviour I've noticed is that the initialValuesEqual callback I provide isn't being called all the time.

I defined it as so:

(a, b) => {
    console.log('isEqual', a, b);
    return isEqual(a, b);
  }

I start by providing initialValues as undefined and eventually pass in an object. That callback gets called when both a and b are undefined, and then again when a and b are both the object I pass in as initialValues. However, it never gets called when one is undefined and the other is the passed-in object.

This doesn't match the behaviour I'm seeing in the CodeSandbox I created, so there's something odd going on here. Can dig deeper but not sure what to be looking for exactly.

The weirdest part I see is that in my form component, props.form.getState().initialValues is correct, even when props.initialValues isn't. I feel like that should be a clue but it isn't to me. 😆

So, I wonder whether this is a case of us being naughty users here. We use the subscription prop to specify a few items, but initialValues wasn't one of them. Previously, this actually worked fine.

But now it didn't. However, adding initialValues: true to the subscription object made everything start working again. So I'm actually not sure if this was a regression or just fixing a bug that we were exploiting previously...