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
.submit()
breaks when used on a form that has been cloned with React.cloneElement()
in v8.x
#4490
Comments
I wrote up a test I expected to be red, but it passed just fine. diff --git a/src/__tests__/reduxForm.spec.js b/src/__tests__/reduxForm.spec.js
index 0df393c..3a0bc63 100644
--- a/src/__tests__/reduxForm.spec.js
+++ b/src/__tests__/reduxForm.spec.js
@@ -1,6 +1,6 @@
import { noop } from 'lodash'
/* eslint react/no-multi-comp:0 */
-import React, { Component } from 'react'
+import React, { Children, Component, cloneElement } from 'react'
import TestUtils from 'react-dom/test-utils'
import { Provider } from 'react-redux'
import { combineReducers as plainCombineReducers, createStore } from 'redux'
@@ -5715,6 +5715,55 @@ const describeReduxForm = (name, structure, combineReducers, setup) => {
expect(propsAtNthRender(formRender, 1).valid).toBe(false)
expect(propsAtNthRender(formRender, 2).valid).toBe(true)
})
+
+ it('can be submitted by instance function after being cloned', () => {
+ const store = makeStore({})
+ const Form = () => <div />
+ const onSubmit = jest.fn()
+ const Decorated = reduxForm({
+ form: 'testForm',
+ onSubmit,
+ })(Form)
+
+ class Container extends Component {
+ renderFirstChild = () => {
+ const firstChild = Children.toArray(this.props.children)[0]
+
+ return cloneElement(
+ firstChild,
+ {
+ ref: ref => { this.child = ref },
+ },
+ )
+ }
+
+ render() {
+ return (
+ <div>
+ {this.renderFirstChild()}
+ <button
+ type="button"
+ onClick={() => { console.log(this.child.submit()) }}
+ >
+ Submit
+ </button>
+ </div>
+ )
+ }
+ }
+
+ const dom = TestUtils.renderIntoDocument(
+ <Provider store={store}>
+ <Container>
+ <Decorated />
+ </Container>
+ </Provider>
+ )
+ const submit = TestUtils.findRenderedDOMComponentWithTag(dom, 'button')
+ TestUtils.Simulate.click(submit)
+
+ expect(onSubmit).toHaveBeenCalledTimes(1)
+ })
})
}
I was able to get it to fail like so: diff --git a/package.json b/package.json
index 0d9fdf4..9325df3 100644
--- a/package.json
+++ b/package.json
@@ -126,7 +126,7 @@
"prettier-eslint-cli": "^4.7.1",
"react": "^16.7.0",
"react-dom": "^16.7.0",
- "react-redux": "^6.0.0",
+ "react-redux": "^5.0.7",
"redux": "^4.0.1",
"redux-immutablejs": "^0.0.8",
"rifraf": "^2.0.3",
But that caused a lot of other errors: At this point I noticed the following in "peerDependencies": {
...
"react-redux": "^6.0.0 || ^7.0.0",
...
}, Which is a problem. I don't want to use Needless to say, I'm in way over my head. |
I upgraded to Expo SDK33 (which was a colossal pain in the butt), upgraded to I'm going to leave this issue open at your whim because I still believe something is broken. The required I also think not supporting |
@Asday any updates? |
Not at all - I ended up not using normalisation at all because I had a project to ship. It's possible I revisit this while I'm furloughed, but don't depend on me for it. :) |
Are you submitting a bug report or a feature request?
Bug report.
What is the current behavior?
Attempting to submit a form that has been cloned with
React.cloneElement()
fails withthis.ref.current.submit is not a function
.What is the expected behavior?
(In my sandbox's case) the contents of "First Name" should be logged to the console upon clicking submit.
Sandbox Link
https://codesandbox.io/embed/redux-form-simple-example-quyv7
What's your environment?
react 16.5.0, redux 4.0.1, redux-form 8.2.4, react-redux 5.0.7.
Discovered the issue in Expo SDK 32, but reproduced in a more vanilla environment as shown in the sandbox.
Other information
Appears to work fine on redux-form v7.4.2. (Sandbox link with just the dependency changed).
To preempt "why are you doing this? That's ridiculous": I've made a wizard that's aware of redux form. When the user attempts to advance to the next step in the wizard, the wizard checks whether the current step has a
.submit()
function, and if so, freezes the wizard interface until that function's returned promise resolves, at which point it moves on to the next step.This is done with the following code (please excuse the react native):
Where
onNext()
is this action creator, bound:This worked fine with my test case in which I imitated a redux form:
But when I came to use a redux form for real, heavens crashed to the Earth, madness reigned, and milk was spilt.
This is actually stopping my work, so once I've opened this issue, I'll be working on it myself, but I can make no promises of fixing it, because I am a stupid stupid idiot and I am very bad at things.
The text was updated successfully, but these errors were encountered: