cemrehancavdar / hyperleaflet

https://docs.hyperleaflet.dev/
MIT License
67 stars 3 forks source link

"Can't observer twice" error when navigating back and forth between pages #38

Open alexandermalyga opened 11 months ago

alexandermalyga commented 11 months ago

First of all thanks for the amazing work on this library, looks really promising!

I noticed an error popping up when:

  1. Navigate to a page that contains the map and some elements with data-id attributes.
  2. Navigate back to a page that doesn't display the map.
  3. Navigate to the map page again. Now we get the following error and the map becomes unresponsive and does not display new markers, looks like it keeps the old ones.
hyperleaflet.js:1 Uncaught Error: Can't observer twice
    at Object.observe (hyperleaflet.js:1:2088)
    at hyperleaflet.js:1:8952
    at c (hyperleaflet.js:1:9182)
    at MutationObserver.observe.childList (hyperleaflet.js:1:9389)

I had a quick look at the code and seems like the hyperChangeDetection.events object is not being cleared when navigating away from the page, so next time it's visited it still contains the old elements and newly loaded ones will be duplicated.