-
-
Notifications
You must be signed in to change notification settings - Fork 231
e.target null in React 0.14.7 #255
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
Comments
There was this thing React implemented a while back (0.13?) where events would have their properties wiped at the end of the callback unless you call This commit here looks related: It's weird though because I'm using 0.14.7 in my work project and I haven't had this problem. Are you sure there's nothing else changed? |
in term of |
That's weird. Ok, need to figure out if problem with React.JS or scalajs-react. If problem with JS, you can confirm quick using a fiddle https://jsfiddle.net/reactjs/69z2wepo/ and if it's a bug, raise on facebook/react directly. If JS is ok then I suggest write a Scala.JS unit test to confirm and demonstrate. |
Oops that fiddle is 0.14.6. Oh well, just update the JS links to 0.14.7. |
ok, will look into it. May take some time as I am on vacation. |
No worries. I use 0.14.7 too so I'll keep an eye out. |
After I updated SPA tutorial to use 0.14.7, I'm also seeing this same issue in TODO.scala def updateDescription(e: ReactEventI) =
// update TodoItem content
t.modState(s => s.copy(item = s.item.copy(content = e.target.value)))
.
.
<.input.text(bss.formControl, ^.id := "description", ^.value := s.item.content,
^.placeholder := "write description", ^.onChange ==> updateDescription)),
Going back to 0.14.6 fixes the problem. |
Probably a React bug. We aren't doing anything special with events or modState. |
Seems like sort of expected behaviour in React (http://ludovf.net/reactbook/blog/reactjs-null-event-target.html). For some reason wasn't that visible before 0.14.7 |
Modifying the code like this fixes the issue in 0.14.7, too def updateDescription(e: ReactEventI) = {
val text = e.target.value
// update TodoItem content
t.modState(s => s.copy(item = s.item.copy(content = text)))
} |
hmm, that's strange. If it works, the previous version should work too. |
Maybe they changed how aggressively / eagerly they recycle? |
Seems pretty deliberate: facebook/react#5840 This sucks because it's another one of those cases where you need to read the fine print of the docs to avoid a runtime error. Unfortunately, there's nothing I can do to prevent this at compile-time. We'll have to just either live with it or petition upstream to do something about it. |
What about Callback.event helper that returns an On Thu, Feb 25, 2016, 3:29 AM David Barri [email protected] wrote:
|
React actively discourages using .persist so I wouldn't want to build a helper on it. Instead how about tacking a method onto events that allows them to immediately extract the portion they need like def extract[A, B](f: this.type => A)(g: A => B): B =
g compose f which when used looks like: def updateDescription(e: ReactEventI) =
e.extract(_.target.value)(text =>
t.modState(s => s.copy(item = s.item.copy(content = text))) It's just a bit of sugar to avoid writing: def updateDescription(e: ReactEventI) = {
val text = e.target.value
t.modState(s => s.copy(item = s.item.copy(content = text)))
} I'm not sure it's worth it. |
Yeah, I'd rather it would just automatically lift it to a Scala case class On Thu, Feb 25, 2016, 7:40 PM David Barri [email protected] wrote:
|
Also, ==> could be changed to not take a raw ReactEventI etc. but some new On Thu, Feb 25, 2016, 10:18 PM Naftoli Gugenheim [email protected]
|
The problem is that events are mutable and recycled by React, presumably because it's important for performance. Making a wrapper case class or changing |
* Update react to 15.0.1. * Use e.extract to get the target of an event to get around japgolly/scalajs-react#255. Tests didn't catch this bug. :(
https://github.com/facebook/react/releases/tag/v0.14.7
seems to break react.js 0.10.4
is broken because somehow
e.target
isnull
. Downgrade to react.js 0.14.6 seems to fix it.The text was updated successfully, but these errors were encountered: