question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Modifying the DOM in an attach or detach listener might cause inconsistent results

See original GitHub issue

When an attach listener makes modifications to the DOM, there can be situations where the attach happens twice (leading to a server-side Can't change id once it has been assigned) or never happens (leading to a client-side Node -1 is already registered). The exact result will vary depending on the relative DOM positions between the node with the attach listener and the newly attached node.

Something similar will most likely also happen detaches, or combinations where an attach listener detaches something or vice versa.

As a workaround, an attach or detach listener can defer the DOM modification using beforeClientResponse.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:4
  • Comments:14 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
johannestcommented, Oct 11, 2018

More information about the issue. It is reproducible also without Spring. Pushed even simplified example into the repository mentioned above.

The root cause is that if you use the same instance of Component such as layout for Grid’s detail row. If you construct a new instance of component used for Grid’s detail row every time, there is no issues.

Steps to reproduce: Navigate to categories, open a details row for a grid row, open another details row for some other grid row, navigate to reviews.

0reactions
Jucharcommented, Jan 14, 2019

It seems that the onDetach() is called before the parent member variable is updated, causing the detach listeners to be fired before the node is really detached.

Is this the intended behaviour?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Event listener in elements appended after DOM Content Loaded
Attaching events directly to DOM nodes is fine, given that those nodes already exist in the DOM. But, as your case requests, ...
Read more >
The 10 Most Common JavaScript Issues Developers Face
The common errors that developers make while coding in JavaScript include mistaken thinking about how the "this" keyword works, incorrect assumptions about ...
Read more >
DOM tree - The Modern JavaScript Tutorial
All these objects are accessible using JavaScript, and we can use them to modify the page. For example, document.body is the object ...
Read more >
An Introduction To DOM Events - Smashing Magazine
Events can be triggered on any part of a document, ... have had major inconsistencies in the way they attach event listeners to...
Read more >
CS50W - Lecture 6 - User Interfaces - CS50 Video Player
... go ahead and attach an event listener · 0:08:25to each of those buttons. ... 0:24:59And as a result, we can change the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found