+ Start a Discussion
michael  limmichael lim 

Lightning function fires twice when component added to Home screen and use tab navigation

I added the AccountLocator component from the  Build an Account Geolocation App trailhead project to my Home tab. I was getting an error with Leaflet.js so I moved the map creation code to the accountsLoaded function in AccountMapController.js.

Everything works OK when I first view the Home page, the accountsLoaded function runs one time. I can click refresh over and over and it works OK.
When I click another tab then go back to Home tab, the accountsLoaded function fires two times. This is causing me an error because the second time it tries to create the map that is already there. I get this error:
Uncaught Action failed: c$AccountMap$controller$accountsLoaded [Map container is already initialized.]

I'm using a Winter 17 dev org.