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

Fix: submitSucceeded is set on redux-form/STOP_SUBMIT #3830

Merged

Conversation

stefan-dimitrov
Copy link
Contributor

When doing a submit the event flow was:

redux-form/START_SUBMIT
  submitting: true
redux-form/STOP_SUBMIT
  submitting: undefined
  submitSucceeded: true // this should not be here
redux-form/SET_SUBMIT_FAILED
  submitSucceeded: undefined
  submitFailed: true

So on a failed submit we would get a submitSucceeded flag set before we get the submitFailed, which made it very difficult to reliably determine a failure.

With this change the submitSucceeded is no longer set with the STOP_SUBMIT action, but only with the dedicated SET_SUBMIT_SUCCEEDED.

Fixes #2260

When doing a submit the event flow was:

redux-form/START_SUBMIT
  submitting: true
redux-form/STOP_SUBMIT
  submitting: undefined
  submitSucceeded: true // this should not be here
redux-form/SET_SUBMIT_FAILED
  submitSucceeded: undefined
  submitFailed: true

So on a failed submit we would get a submitSucceeded flag set before
we get the submitFailed, which made it very difficult to reliably
determine a failure.

With this change the submitSucceeded is no longer set with the
STOP_SUBMIT action, but only with the dedicated SET_SUBMIT_SUCCEEDED.
@cdimitroulas
Copy link

👍 just came across this issue myself and this PR would allow reliance on the submitSucceeded prop which otherwise does not work correctly

@ssilve1989
Copy link

I would also like to see this merged. The current behavior of submitSucceeded makes it impossible to rely on it to do any sensible flow in managing form component rendering.

@codecov-io
Copy link

codecov-io commented Mar 2, 2018

Codecov Report

❗ No coverage uploaded for pull request base (master@b5240aa). Click here to learn what that means.
The diff coverage is 100%.

Impacted file tree graph

@@           Coverage Diff            @@
##             master   #3830   +/-   ##
========================================
  Coverage          ?    100%           
========================================
  Files             ?      70           
  Lines             ?    1601           
  Branches          ?       0           
========================================
  Hits              ?    1601           
  Misses            ?       0           
  Partials          ?       0
Impacted Files Coverage Δ
src/createReducer.js 100% <100%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b5240aa...7b59fb7. Read the comment docs.

@erikras erikras merged commit b107510 into redux-form:master Mar 2, 2018
@erikras
Copy link
Member

erikras commented Mar 2, 2018

Published in v7.3.0.

@8of
Copy link

8of commented Mar 28, 2018

So, how should we use it from now on if we need submitSucceeded?
Should we call setSubmitSucceeded(formId) instead of stopSubmit(formId) if our submitting was successful?

@cdimitroulas
Copy link

cdimitroulas commented Mar 28, 2018

@8of you shouldn't need to call any of redux-form's action creators or to do anything special.

redux-form passes a prop called submitSucceeded to your wrapped component which will change to true once the form has submitted successfully. This PR was to fix an issue where it was changing to true even though the form did not submit successfully.

Unless I'm misunderstanding your question...?

@8of
Copy link

8of commented Mar 28, 2018

@cdimitroulas
If I execute setSubmitSucceeded(formId) then submitting is still true, and it shouldn't be true, because, well, submitting was successful.
Any suggestions?

@cdimitroulas
Copy link

hmm that's odd - shouldn't be the case. @stefan-dimitrov should the reducer also set submitting to false when the submission succeeds?

@8of for now as a workaround you could maybe check that submitting is true AND submitSucceeded is false?

@stefan-dimitrov
Copy link
Contributor Author

should the reducer also set submitting to false when the submission succeeds?

I believe it should not. My understanding is that those actions should set only their respective flags, without affecting others, even if they are "thematically" related (submit completion and submit success).
redux-form handles setting of those flags automatically when the submission completes (probably using the Promise resolution mechanism, I haven't looked into those details).

I could be wrong, but what you are describing, @8of, seems to be manual setting of the flags, without relying on the mechanisms in redux-form. If that is case I think the setting of the related flags should be handled explicitly by your logic.
I do not think there is any missing behavior in redux-form regarding your scenario.

@8of
Copy link

8of commented Apr 3, 2018

those actions should set only their respective flags
Makes sense.
Now I make calls like this:

stopSubmit(formId);
setSubmitSucceeded(formId);

submitting and submitSucceeded have expected values (false and true respectively)

The only downside I can think of - submitting and submitSucceeded don't switch states at the same time. But that's ok for me.

Thank you guys for the clarification. 👏

@lock
Copy link

lock bot commented Jun 1, 2018

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.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 1, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants