Stale Reference
In dynamic web applications (like those using HTMX, Hotwire, Turbo or React), there is this classic "stale reference" issue. As a quick example, consider the following javascript code that finds an element after receiving an event, and then deletes that element after 5 seconds. document.addEventListener("elementSwapped", () => { const timestampElements = document.querySelectorAll('[id^="el-last-saved-"]'); timestampElements.forEach(timestampElement => { if (!timestampElement.dataset.clearPending) { timestampElement.dataset.clearPending = 'true'; setTimeout(() => { timestampElement.remove(); }, 5000); }; }); }); While the logic is sound, the element reference el captured in setTimeout is likely becoming outdated before the 5 seconds are up. ...