Skip to content

Commit

Permalink
Fix event bubbling can break in test conditions (preactjs#4161)
Browse files Browse the repository at this point in the history
  • Loading branch information
nbalatsk-oracle committed Dec 15, 2023
1 parent 4f2a04f commit 7865768
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/diff/props.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ function setStyle(style, key, value) {
}
}

let globalCounter = Number.MIN_SAFE_INTEGER;
const getCounter = increment => {
return increment ? ++globalCounter : globalCounter;
};

/**
* Set a property value on a DOM node
* @param {PreactElement} dom The DOM node to modify
Expand Down Expand Up @@ -63,7 +68,7 @@ export function setProperty(dom, name, value, oldValue, isSvg) {

if (value) {
if (!oldValue) {
value._attached = Date.now();
value._attached = getCounter();
const handler = useCapture ? eventProxyCapture : eventProxy;
dom.addEventListener(name, handler, useCapture);
} else {
Expand Down Expand Up @@ -133,7 +138,7 @@ function eventProxy(e) {
if (!e._dispatched) {
// When an event has no _dispatched we know this is the first event-target in the chain
// so we set the initial dispatched time.
e._dispatched = Date.now();
e._dispatched = getCounter(true);
// When the _dispatched is smaller than the time when the targetted event handler was attached
// we know we have bubbled up to an element that was added during patching the dom.
} else if (e._dispatched <= eventHandler._attached) {
Expand Down

0 comments on commit 7865768

Please sign in to comment.