ciscoheat / sveltekit-flash-message

Send temporary data after redirect, usually from endpoints. Works with both SSR and client.
https://www.npmjs.com/package/sveltekit-flash-message
MIT License
246 stars 5 forks source link

fix: unsubscribe the page subscription onDestroy to avoid memory leak #14

Closed stLmpp closed 1 year ago

stLmpp commented 1 year ago

This PR fixes a memory leak on the client side. If you navigate away from a page that uses the "initFlash" function, the page subscription will never finish and for every form action with the "use:enhance" it will throw an error:

image

I created a repro: https://github.com/stLmpp/flash-svelte-page-subscription

  1. Install the dependencies
  2. Run npm run dev
  3. Use the anchor to navigate to the "other" route
  4. Click the button to submit the form
  5. Check the console to see the errors
ciscoheat commented 1 year ago

Thank you! Will merge and release a patch soon.