Update flash messages after client-side fetch
masterWhen using the browser fetch API instead of SvelteKit's built-in form handling, the flash message store will not update automatically. You must call updateFlash(page) after the fetch completes to sync the state.
<script lang="ts">
import { updateFlash } from 'sveltekit-flash-message';
import { page } from '$app/state';
async function submitForm(e: Event) {
const form = e.target as HTMLFormElement;
const body = new FormData(form);
await fetch(form.action, { method: 'POST', body });
await updateFlash(page);
}
</script>
<form method="POST" action="/test" on:submit|preventDefault={submitForm}>
<button>Submit with fetch</button>
</form>