feat: add _freshIndicator support for partial form submits (#3753)

## Summary
- Extends the `_freshIndicator` loading signal to form submissions, not
just anchor clicks
- Checks the submitter element first, falling back to the form element
- Wraps the fetch in try/finally to ensure the indicator resets on
success or failure
- Adds 3 browser tests: indicator on button, indicator on form, and
submitter-over-form precedence

Closes #3504

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Bartek Iwańczuk
2026-04-09 12:21:39 +02:00
committed by GitHub
co-authored by Claude Opus 4.6
parent af3f30dbaa
commit 28cce5f607
3 changed files with 294 additions and 3 deletions
+17 -3
View File
@@ -278,6 +278,14 @@ document.addEventListener("submit", async (e) => {
// this check, every form inside f-client-nav would be intercepted
// because el.action is always non-empty (defaults to the current URL).
if (hasExplicitPartial && rawPartialUrl !== "") {
// deno-lint-ignore no-explicit-any
const indicator = ((e.submitter as any)?._freshIndicator ??
// deno-lint-ignore no-explicit-any
(el as any)._freshIndicator) as { value: boolean } | undefined;
if (indicator !== undefined) {
indicator.value = true;
}
e.preventDefault();
const partialUrl = new URL(rawPartialUrl, location.href);
@@ -295,9 +303,15 @@ document.addEventListener("submit", async (e) => {
init = { body: new FormData(el, e.submitter), method: lowerMethod };
}
await withViewTransition(async () => {
await fetchPartials(actionUrl, partialUrl, true, init);
});
try {
await withViewTransition(async () => {
await fetchPartials(actionUrl, partialUrl, true, init);
});
} finally {
if (indicator !== undefined) {
indicator.value = false;
}
}
}
}
});