Custom Element with Leaflet not rendering correctly after client-side navigation in SvelteKit

I built a custom element using Leaflet that renders all the elements on the map by simply passing a JSON object.

The map works perfectly on a full page reload, but when navigating between different pages (using client-side navigation in SvelteKit), and then returning to the map, the elements don’t display, and a Leaflet error is thrown. It seems like the map is not being reinitialized properly after navigation.

What could be causing this issue, and how can I ensure the map is correctly initialized when navigating back to the page?

I tried different SvelteKit methods for re-rendering the component or reloading the script every time I navigate to the page, but none of these attempts worked.

SSR is off.