Skip to content

fix: reduce pending count even if form with enhance was never submitted#15602

Closed
paoloricciuti wants to merge 1 commit intomainfrom
pending-no-submitted
Closed

fix: reduce pending count even if form with enhance was never submitted#15602
paoloricciuti wants to merge 1 commit intomainfrom
pending-no-submitted

Conversation

@paoloricciuti
Copy link
Member

@paoloricciuti paoloricciuti commented Mar 25, 2026

Closes #15519

Currently, if you have an enhance function, and you conditionally invoke submit the pending value never goes down

REPL

<script>
	import { set_message } from './form.remote.js';

	let should_submit = $state(false);

	const pendings_arr = [];
	const pendings = $derived.by(() => {
		pendings_arr.push(set_message.pending);
		return pendings_arr.join(', ');
	});
</script>

<label>
	<input type="checkbox" bind:checked={should_submit} data-should-submit />
	should submit
</label>

<form
	{...set_message.enhance(async ({ submit }) => {
		if (!should_submit) return;
		await submit();
	})}
>
	<button>submit</button>
</form>

<p data-pending>{pendings}</p>

if you left the checkbox unchecked and submit multiple times, the value of pending will go higher and higher.

This fixes that by checking if the submit function was invoked and decreasing pending in a finally block

@changeset-bot
Copy link

changeset-bot bot commented Mar 25, 2026

🦋 Changeset detected

Latest commit: 3dfc15d

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

@paoloricciuti
Copy link
Member Author

Closing this in favor of #15520 which is a better fix (and was earlier)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cancelling submission in form.enhance does not reset pending count

1 participant