sveltejs / kit

web development, streamlined
https://svelte.dev/docs/kit
MIT License
18.75k stars 1.95k forks source link

fix: await applyAction and goto #13032

Open GitRowin opened 2 days ago

GitRowin commented 2 days ago

Here is a simple form with a button that gets disabled while the form is being submitted:

<form
  method="post"
  use:enhance={() => {
    sending = true;
    return async ({ update }) => {
      await update();
      sending = false;
    };
  }}
>
  <div>
    <button disabled={sending}>{sending ? "Sending..." : "Send"}</button>
  </div>
</form>

If the server responds with a redirect, I expect the button to stay on "Sending..." until the other page shows up. Unfortunately, this is not what happens right now: video.

And here is what it looks like after these changes: video.


Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

Tests

Changesets

Edits

changeset-bot[bot] commented 2 days ago

🦋 Changeset detected

Latest commit: d23e70b6a9755064205eaa38d2529de9dca2c1e8

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package | Name | Type | | ------------- | ----- | | @sveltejs/kit | Patch |

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Rich-Harris commented 2 days ago

preview: https://svelte-dev-git-preview-kit-13032-svelte.vercel.app/

this is an automated message

dummdidumm commented 1 day ago

I think this makes sense. The question is what exactly happens if the redirect happens and then the code from the previos page runs. This could possibly also cause problems because it tries to change elements that are no longer there.