Skip to content

Minor Bug in "taintedMessage" beforeNavigate hook #683

Description

@gurpreetatwal

Description
The taintedMessage beforeNavigate hook can cause the goto function to throw if the user is navigating to an external link. This is a minor bug all things considered because it does not break anything for the user. Just causes noise in error tracking platforms like Sentry.

Relevant Code

try {
Tainted.forceRedirection = true;
//@ts-expect-error Possible SvelteKit breaking change, it worked before.
await goto(nav.to.url, { ...nav.to.params });
return;
} finally {

MRE

<script lang="ts">
  import { superForm } from 'sveltekit-superforms';

  let { data } = $props();

  const { form, enhance } = superForm(data.form, {
    taintedMessage: 'You will lose all of your changes',
  });
</script>

<form method="POST" use:enhance style="display: flex; flex-direction: column; gap: 1rem">
  <label>
    Name
    <input name="name" bind:value={$form.name} />
  </label>

  <p>
    <a href="https://www.github.com" style="color: blue; text-decoration: underline;">
      Click me after editing the form to trigger the error
    </a>
  </p>
</form>

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions