Modifying the DOM in an attach or detach listener might cause inconsistent results
See original GitHub issueWhen 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:
- Created 5 years ago
- Reactions:4
- Comments:14 (12 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.
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?