When focus and blur are dispatched, a global capturing event listener sees the event and manually dispatches it through the tree to listeners added with wrapped addEventListener calls. The manual dispatching patches currentTarget to return retargeted values (along with eventPhase, since we are simulating the bubbling phase via a capturing listener). When all addEventListener calls are wrapped this works fine.
However, because the capturing listener does not stop propagation, the event will also natively fire to any native listeners added with an unwrapped addEventListener call (note that Polymer does not wrapaddEventListener for listeners added via templates when in noPatch mode, as a performance optimization/correctness tradeoff). Because the manual dispatching code leaves the patched currentTarget accessor installed, it can cause the subsequent native listeners to see the same event, but with patched accessors that return invalid values (like null), rather than just the unpatched values.
Description
When
focus
andblur
are dispatched, a global capturing event listener sees the event and manually dispatches it through the tree to listeners added with wrappedaddEventListener
calls. The manual dispatching patchescurrentTarget
to return retargeted values (along witheventPhase
, since we are simulating the bubbling phase via a capturing listener). When alladdEventListener
calls are wrapped this works fine.However, because the capturing listener does not stop propagation, the event will also natively fire to any native listeners added with an unwrapped
addEventListener
call (note that Polymer does not wrapaddEventListener
for listeners added via templates when innoPatch
mode, as a performance optimization/correctness tradeoff). Because the manual dispatching code leaves the patchedcurrentTarget
accessor installed, it can cause the subsequent native listeners to see the same event, but with patched accessors that return invalid values (likenull
), rather than just the unpatched values.Example
https://lit.dev/playground/?mods=gists#gist=d0bcd06f7a01426a52a9b1af0251c0d2
Steps to reproduce
Focus input in demo above
Expected behavior
The logged
currentTarget
is the input.Actual behavior
The logged
currentTarget
isnull
.