-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: await applyAction and goto #13032
base: main
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: d23e70b The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
preview: https://svelte-dev-git-preview-kit-13032-svelte.vercel.app/ this is an automated message |
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. |
if you're expecting a redirect, why bother changing |
Yep, it's just more boilerplate: <form
method="post"
use:enhance={() => {
sending = true;
return async ({ result, update }) => {
if (result.type !== "redirect") sending = false;
update();
};
}}
> And I figured you should be able to await |
@@ -1983,7 +1983,7 @@ export async function applyAction(result) { | |||
tick().then(reset_focus); | |||
} | |||
} else if (result.type === 'redirect') { | |||
_goto(result.location, { invalidateAll: true }, 0); | |||
await _goto(result.location, { invalidateAll: true }, 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think await applyAction(result)
makes sense, but I'm not sure about this part anymore. It's basically guaranteeing that you're gonna run into a situation where you're likely to deal with dangling objects from the old page, and that could result in harder to debug issues compared to a spinner aborting too earlier, which can be worked around easily as shown in the discussion
Here is a simple form with a button that gets disabled while the form is being submitted:
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:
.
And here is what it looks like after these changes:
.
Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
Tests
pnpm test
and lint the project withpnpm lint
andpnpm check
Changesets
pnpm changeset
and following the prompts. Changesets that add features should beminor
and those that fix bugs should bepatch
. Please prefix changeset messages withfeat:
,fix:
, orchore:
.Edits