the-carlisle-group / Abacus

HTML, CSS, and Markdown for Dyalog APL
MIT License
12 stars 0 forks source link

Event bubbling can cause problem if elements are deleted. #16

Open PaulMansour opened 8 months ago

PaulMansour commented 8 months ago

Consider a KeyDown event listener attached to two elements, a <body> and some child <table> ("Current Targets"), and the KeyDown event fired by a key press on a <td> element (the "Target"). If this key down event deletes the contents of the table, then the <td> element no longer exists. The browser, however has processed the <body> event listener before the delete has happened in the APLDOM and the browser DOM synchronized. So when the <body> event listener is sent to the APLDOM, the expected <td> target element is not found.

In the use-case that uncovered this issue, in the higher level event handler, the target is immaterial and unreferenced anyway. This may virtually always be the case. If a lower level event handler is deleting elements, an upper level event handler should not reference them. It may be safe to simply set target to zero if not found.