Skip to content

Commit

Permalink
fix: Router component had memory leaks after mount/unmount (#221)
Browse files Browse the repository at this point in the history
  • Loading branch information
CatchABus authored Jun 16, 2021
1 parent 69c226d commit be73586
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions Router.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ function scrollstateHistoryHandler(event) {
{/if}

<script>
import {createEventDispatcher, afterUpdate} from 'svelte'
import {onDestroy, createEventDispatcher, afterUpdate} from 'svelte'
import {parse} from 'regexparam'
/**
Expand Down Expand Up @@ -451,7 +451,7 @@ let componentObj = null
// Handle hash change events
// Listen to changes in the $loc store and update the page
// Do not use the $: syntax because it gets triggered by too many things
loc.subscribe(async (newLoc) => {
const unsubscribeLoc = loc.subscribe(async (newLoc) => {
lastLoc = newLoc
// Find a route matching the location
Expand Down Expand Up @@ -545,4 +545,8 @@ loc.subscribe(async (newLoc) => {
component = null
componentObj = null
})
onDestroy(() => {
unsubscribeLoc()
})
</script>

0 comments on commit be73586

Please sign in to comment.