Fork me on GitHub
#reagent
<
2018-03-31
>
Alex H19:03:09

So I don't have a reproducer that I can share (yet), but I've been using reagent with React 16, and ran into a really weird event propagation issue. It's roughly: a parent element with a handler (say on-click), and a child with also some on-click, and in the child handler I reset! a reagent atom, that causes a rerender with e.g. a modal or similar. When that modal closes (and only then) does an event suddenly propagate up to the parent element.

Alex H19:03:20

Same code works fine with React 15 (and same reagent version)

Alex H19:03:50

I'll try and build a reproducer that I can share (and raise an issue with), but just wondering if anyone else has had similar issues with React 16 and reagent

Alex H19:03:39

a backtrace on the parent's handler isn't terribly helpful as it just traces back to batchedUpdates within React

justinlee19:03:26

@alex340 I’m trying but failing to google for the issue, but there is an oddity with event handlers that changed from 15 to 16

justinlee19:03:45

basically the issue is what you are returning from the event handler

justinlee19:03:06

try consistently returning nil from the event handler and see if that makes the behavior consistent

Alex H19:03:06

well, I found some old reagent docs talking about that, but it didn't really seem applicable anymore

Alex H19:03:10

(about returning false vs not)

justinlee19:03:20

hm it sounds like that issue

Alex H19:03:39

looks like some issue with the event scheduling within reagent vs react 16's fibers to me

Alex H19:03:53

an explicit stopPropagation didn't really help, either

justinlee19:03:59

yea maybe. that’s just what initial reaction was

justinlee19:03:45

this is crazy, but have you confirmed that the handler actually returns after the reset!? it is hard to understand how the event handling mechanism could be influenced by any of this unless something is getting triggered synchronously off of the reset!

Alex H19:03:30

didn't check that, no, although a synchronous render from the event handler is what I was thinking

Alex H19:03:42

I'll give that a whirl when I come back to it, maybe tomorrow

justinlee19:03:54

another thought: are you programmatically causing a click event anywhere and is there any possibility that that code is being called on rerender in a way you don’t expect

Alex H19:03:06

definitely not, no - no programmatic clicks

justinlee19:03:47

i don’t even think it is possible to re-render in the middle of an event handler but i’m not that experienced with these kind of browser edge cases

justinlee19:03:17

easy to check; just stick a print statemetn after the reset

Alex H19:03:24

yep, will do

Alex H19:03:48

nah, it does return fine

justinlee19:03:01

that is super weird then

justinlee19:03:17

beyond my knowledge of the bowels of reagent and react

justinlee19:03:53

Juho might know but I think he’s on central europe time. probably helpful to have a repo

Alex H20:03:06

upon a bit of further investigation I think I might actually be running into https://github.com/facebook/react/issues/11387

justinlee20:03:19

interesting. i’ve never used portal but there is at least one open bug about portal in reagent too.

justinlee20:03:49

(side note, it’s pretty amazing that react only has 351 open issues on 12000+ reported)