Whenever a user performs an action, like logging in to the app, I want to show a toast message for a few seconds. The login form is located at /login/page.svelte
, with database interaction handled by /login/page.server.js
. A writable store is used to save the toast messages.
When the form is submitted, the page refreshes and the store is cleared, causing the toast to disappear. The event flow seems to be:
- Form submission to
/login/page.server.js
page.server.js
processes the datapage.server.js
sends back the entire page, triggering a browser reload
I know that using preventdefault
can stop this process, but I only want to prevent the page reload. Preventing everything doesn't seem ideal as it might interfere with other functions.
Is there a better way to communicate between page.svelte
and page.server.js
without triggering a page refresh (which clears the stores), apart from using preventdefault and manual fetch?
Here's a REPL where the toast message stays visible for 3 seconds, but disappears immediately on normal form submission: