Hello, I have an application that consists of several components (The application is inside webpack bundle, also there is another bundled app on the page), one them is app-links. This component has several event listeners, for example:
events: {
‘.gn-appList-links-toggler click’: function () {
this.viewModel.showMenu();
},
‘.gn-overlay click’: function () {
this.viewModel.hideMenu();
},
Often I get such error, when I click on this component:
delegate.js:47 Uncaught TypeError: Cannot read property ‘click’ of undefined
at HTMLElement.handleEvent
After debugging I noticed that during initial load the component is initialized with other components in can-dom-data-state.js module. In set() function its data is saved in object with certain id (51 as you can see on the screenshot)
But after all components are initialized and stored with their ids, I see that deleteNode() function executes with some text node that has the same id (51) as app-links component, so all data for this component is deleted from the store, though it exists on the page.
As the result when I click on app-links component I got error, because data with listeners has been unexpectedly deleted.
Could you advise what’s cause of such behaviour and how to fix it?
But I noticed that this error doesn’t happen when this app is alone on a page. It happens when there are several others. But the application is inside webpack bundle, it shouldn’t interact with another code, strange.
I see in debugger, that text element has identification property in such format: canFri Aug 10 2018 17:39:36 GMT+0300 (Moscow Standard Time) : “51” . And the deleteNode function executes when other application on the page has been loaded and the data from my application with same 51 id becomes deleted.
I’ll see what can be done, also want to share this info : my app is build with webpack and canjs 3. Another app is build with canjs 2.2.9 and scripts for this app are inserted without webpack into the page. The error exist only when there are 2 apps on the page.
I’ve found workaround to avoid this bug: if to define event listeners without css selectors, the error doesn’t appear. So I declared events in such way:
‘{toggler} click’: function () {
this.viewModel.showMenu();
},
‘{overlay} click’: function () {
this.viewModel.hideMenu();
},