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

Synchronous call to onSubmit() from props #1068

Merged
merged 1 commit into from
Oct 26, 2018

Conversation

sbusch
Copy link
Contributor

@sbusch sbusch commented Oct 26, 2018

Reasons for making this change

Due to the use of setImmediate() hack in setState utility function from utils.js,
the onSubmit() handler from props is called asynchronously.

This leads to problems for submit handlers requiring browser "trusted events", like window.open() or
when programmatically submitting forms with target _blank.

Because onSubmit() should not need the performance-related setImmiate() hack, I
replaced call to setState utility function with proper this.setState() from
React, which fixed the problem.

Checklist

  • I'm updating documentation
    • I've checked the rendering of the Markdown text I've added
    • If I'm adding a new section, I've updated the Table of Content
  • I'm adding or updating code
    • I've added and/or updated tests: couldnt figure out how to properly test this.
    • I've updated docs if needed
    • I've run npm run cs-format on my branch to conform my code to prettier coding style
  • I'm adding a new feature
    • I've updated the playground with an example use of the feature

Due to the use of setImmediate() hack in setState utility function (utils.js),
onSubmit() handler from props is called asynchronously. This leads to massive
problems for operations requiring "trusted events", like window.open() or
programmatically submitting forms with target "_blank" (which we needed)

Because onSubmit() should not need the performance-related setImmiate() hack, I
replaced call to setState utility function with proper this.setState() from
React.
@glasserc
Copy link
Contributor

Thanks!

@glasserc glasserc merged commit e2e7120 into rjsf-team:master Oct 26, 2018
@sbusch sbusch deleted the fix-async-onSubmit branch October 29, 2018 06:31
@althalus86
Copy link

Hi guys, I might be mistaken but this commit is breaking my build.

It's throwing a "TypeError: this.updater.enqueueCallback is not a function" when submitting the form.

The code is fairly simple

<Form schema={this.state.schema} onChange={log("changed")} onSubmit={this.onSubmit}

onSubmit is just an empty function

submiterror

althalus86 added a commit to althalus86/react-jsonschema-form that referenced this pull request Nov 3, 2018
@glasserc
Copy link
Contributor

@althalus86 I'm not a React expert so I don't claim to understand what's going on, but I don't think we have any control over ReactComponent.setState and I don't know what this.updater is or why it would have an enqueueSetState but not an enqueueCallback. If you're still having this problem, feel free to open another issue that refers to this one.

@sbusch
Copy link
Contributor Author

sbusch commented Jan 13, 2019

@althalus86

Do you have a reproducible full example?

Did you install via "npm install react-jsonschema-form"?

Is node_modules/react-jsonschema-form a regular directory or a symlink?

Which react, react-dom and typescript version are you using? (npm ls output for each of them)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants