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

dispatchEvent has no longer any effect on latest react version #12344

Closed
rdandnayak opened this issue Mar 8, 2018 · 2 comments
Closed

dispatchEvent has no longer any effect on latest react version #12344

rdandnayak opened this issue Mar 8, 2018 · 2 comments

Comments

@rdandnayak
Copy link

rdandnayak commented Mar 8, 2018

Do you want to request a feature or report a bug?
This is a bug in latest react v16.2.0

What is the current behavior?
It does not listen to programatically generated key events with react@16.2.0, but with older react@15.5.2 It does the job.

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem. Your bug will get fixed much faster if we can run your code and it doesn't have dependencies other than React. Paste the link to your JSFiddle (https://jsfiddle.net/Luktwrdm/) or CodeSandbox (https://codesandbox.io/s/new) example below:
Find below link for codeSandbox
https://codesandbox.io/s/pklvvz6vw0
this is a basic react app which is trying to dispatchEvent and fill the input field after click on 'Inject' button. react version for this sandbox is react@15.5.2

if you check the console. It is logging current state of React component

What is the expected behavior?
if we change version of sandbox to 16.2.0 (latest). It does fills expected value in textbox but it does not get recognised in React internal state. and console log is blank. which means id did not even trigger any internal state change.

what can we do if we want to fill the input textbox programatically.
we are setting up our internal test framework where we would want to generate all events manually to observe the entire app behaviour.

Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?
works with react@15.5.2 but not with latest 16.2.0

@rdandnayak
Copy link
Author

rdandnayak commented Mar 8, 2018

following function solved my problem

function setNativeValue(element, value) {
  const valueSetter = Object.getOwnPropertyDescriptor(element, 'value').set;
  const prototype = Object.getPrototypeOf(element);
  const prototypeValueSetter = Object.getOwnPropertyDescriptor(prototype, 'value').set;
  
  if (valueSetter && valueSetter !== prototypeValueSetter) {
  	prototypeValueSetter.call(element, value);
  } else {
    valueSetter.call(element, value);
  }
}

from issue thread #10135

will leave it up to owners to close this issue. I am still not sure this is bug or not.

@rdandnayak rdandnayak reopened this Mar 8, 2018
@rdandnayak rdandnayak changed the title manual dispatchEvent has no longer any effect on latest react version dispatchEvent has no longer any effect on latest react version Mar 9, 2018
@aweary
Copy link
Contributor

aweary commented Mar 9, 2018

The solution outlined in #10135 is the recommended solution 👍

@aweary aweary closed this as completed Mar 9, 2018
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

No branches or pull requests

2 participants