React-final-form: Uncaught TypeError: Cannot read property 'subscription' of undefined when using FormSpy

Created on 13 Feb 2018  ·  10Comments  ·  Source: final-form/react-final-form

Are you submitting a bug report or a feature request?

Bug report

What is the current behavior?

When rendering a Form with a FormSpy, it becomes impossible to remove the spy from the react hierarchy based on form state, without triggering errors during subscription handling.

In the sandbox example, submitting the form will trigger the form to re-render and only return a string, unmounting the FormSpy. This will then lead to an error being thrown.

A workaround is to keep rendering the FormSpy regardless of whether the form has been successfully submitted.

What is the expected behavior?

It should be possible to remove the FormSpy from the tree without having it conflict with subscription handling.

Sandbox Link

https://codesandbox.io/s/0o6o6mp3ov

What's your environment?

final-form 4.2.0
react-final-form 3.1.0

Most helpful comment

Published fix in [email protected].

All 10 comments

Is there any news regarding this bug?

I'm trying to reproduce it.

reproduced, let me debug it.

Updating the FF and RFF deps in that code sandbox fixes the problem. 🤷‍♂️

I still have this issue with updated dependencies

Uncaught (in promise) TypeError: Cannot read property 'subscription' of undefined
    at final-form.es.js:382
    at Array.forEach (<anonymous>)
    at notify (final-form.es.js:380)
    at notifyFormListeners (final-form.es.js:798)
    at complete (final-form.es.js:1132)

Just found the same error (version 4.12.0)

final-form.es.js:407 Uncaught (in promise) TypeError: Cannot read property 'subscription' of undefined
    at final-form.es.js:407
    at Array.forEach (<anonymous>)
    at notify (final-form.es.js:405)
    at notifyFormListeners (final-form.es.js:827)
    at complete (final-form.es.js:1182)

For what it's worth, it is also happening with final-form 4.11.1 and react-final-form 4.0.2.
I am unsure what are the conditions to replicate it. I will post more information when I identify what conditions trigger this error.

Published fix in [email protected].

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

vlopp picture vlopp  ·  4Comments

CodeWithOz picture CodeWithOz  ·  4Comments

gsantiago picture gsantiago  ·  5Comments

kiliw picture kiliw  ·  4Comments

ThaNarie picture ThaNarie  ·  3Comments