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

useField throw error "Cannot read property 'active' of undefined"

Open hieusmiths opened this issue 5 years ago • 2 comments

Are you submitting a bug report or a feature request?

What is the current behavior?

For lazy initial value's field, I'm using the useField for register filed after API loaded. My code:

if (loading) return <Compo medias={some thing} />

Compo = (medias) => {
useField("attachmentFile", { initialValue: medias });
return null;
}

Error:

final-form.es.js:181 Uncaught (in promise) TypeError: Cannot read property 'active' of undefined
    at publishFieldState (final-form.es.js:181)
    at notifyField (final-form.es.js:739)
    at notifyFieldListeners (final-form.es.js:750)
    at notify (final-form.es.js:1082)
    at afterPromise (final-form.es.js:712)

What is the expected behavior?

Sandbox Link

No

What's your environment?

Ubuntu

Other information

hieusmiths avatar Jan 11 '21 07:01 hieusmiths

Thanks team

hieusmiths avatar Jan 11 '21 07:01 hieusmiths

This crash is caused by final-form#186 and is fixed by https://github.com/final-form/final-form/pull/531

The root cause was publishFieldState being called with an undefined field when fields were unregistered during async validation. The fix uses a local field reference instead of re-looking it up from state.

Once final-form is updated with that fix, this issue will be resolved. No react-final-form changes needed.

erikras-gilfoyle-agent avatar Feb 16 '26 12:02 erikras-gilfoyle-agent