Repository navigation
Description
Context
A user can submit a RazorWire form while a serverless host wakes up and see no immediate confirmation. In a serverless app, that makes a successful first click feel ignored and invites repeated clicks. RazorWire should show processing feedback as soon as an enhanced form submission starts, while letting the host application supply its own spinner, text, and layout.
Priority: High. This affects trust in a common interaction during cold starts. This issue covers rw-active forms and their submit controls. Navigation, island loading, and arbitrary app JavaScript requests are follow-up work.
Approved office-hours refinements (2026-09-26)
- This issue covers the reusable RazorWire feature and a proof in the affected consumer application. The public case remains anonymized.
- The public option is PreventDuplicateSubmissions (default true). It names the behavioral guarantee, including Enter and alternate submitters, rather than only the control styling.
- Loading starts on Turbo's accepted form before-fetch-request event so a lazy anti-forgery token wait is visible. A normal Playwright integration test holds token refresh, verifies feedback appears before any form POST, fails refresh and verifies loading clears with no form POST, then restores refresh and verifies one retry POST. A failing test is fixed as part of implementation; no separate release gate is needed.
- The nearest ancestor loading boundary with an owned indicator wins. A body-level indicator applies only to descendant forms. Boundary presence declares the scope; if more than one owned indicator exists, the first in document order is used. A boundary and its indicator remain pending until their last associated activity settles.
- The package fallback bar stays enabled by default when no app indicator applies. Coordinate it with Turbo's delayed bar; when an unrelated visit overlaps, retain visible progress for the visit without showing duplicate bars for one form.
- Keep the public API form-focused. The internal activity ledger may later accept other request sources.
Current State
Verified in the repository on 2026-09-26. The reported app experience is user-observed; its exact form path and production cold-start duration have not been measured.
| Form path | Current feedback | Gap |
|---|---|---|
| Full-page Turbo form | Turbo schedules its top progress bar after 500 ms (wwwroot/razorwire/turbo.es2017-umd.js:4366-4395) |
No immediate confirmation |
| Turbo Frame form | Turbo marks the form/frame busy but does not start that bar (wwwroot/razorwire/turbo.es2017-umd.js:6557-6585) |
No built-in visible progress |
rw-active form with failed-form UX off |
The RazorWire submit handler skips it; data-rw-form is absent unless another feature such as lazy anti-forgery emits it |
No RazorWire pending hooks |
Web/ForgeTrust.RazorWire/assets/src/razorwire.ts:870-889 sets data-rw-submitting, aria-busy, and disables only the initiating submitter inside the failed-form handler. Web/ForgeTrust.RazorWire/TagHelpers/RazorWireFormTagHelper.cs:104-126 emits the failed-form request marker only when failed-form UX is enabled; rw-antiforgery="lazy" can emit the transport marker independently at lines 84-101. Web/ForgeTrust.RazorWire/assets/src/razorwire.ts:1007-1018 restores the submitter on completion and confirms that this path depends on failed-form mode.
Root cause: pending feedback is coupled to failed-form handling. Its busy attributes are not app-defined visible feedback. Turbo's full-page and frame submission paths have different progress-bar behavior.
Preserve
Keep existing failed-form messages and events, anti-forgery behavior, normal Turbo navigation, and native HTML form submission when JavaScript is unavailable. Do not edit the copied third-party Turbo runtime.
Proposed Change
Add a form-loading lifecycle independent of failed-form UX. Enable it by default for rw-active forms. Start on turbo:before-fetch-request for a loading-owned form: this follows browser validation and Turbo confirmation and precedes any lazy anti-forgery token pause. Do not show feedback for a click that starts no accepted request.
An application may author an indicator inside a form-local boundary or a site-wide boundary. Use the nearest ancestor boundary containing an indicator owned by that boundary. A form-local indicator takes precedence over a site-wide one. If no app indicator applies, show one package-owned, immediate top-of-screen progress bar in the visual family of Turbo's navigation bar. Suppress the delayed Turbo form bar while a RazorWire form is pending so there is never a duplicate. The app owns indicator markup and CSS; RazorWire owns visibility and state. Do not start an additional network request to display feedback.
Public API shape
public sealed class RazorWireFormLoadingOptions
{
public bool Enabled { get; set; } = true;
public bool ShowFallbackBar { get; set; } = true;
public bool PreventDuplicateSubmissions { get; set; } = true;
}
// Add to RazorWireFormOptions:
public RazorWireFormLoadingOptions Loading { get; } = new();Enabled=false is a global kill switch for this loading layer and takes precedence over form attributes. It does not change failed-form handling. ShowFallbackBar=false is for apps that supply indicators through boundaries; document that a form without a matching indicator then has no package-owned visible fallback. PreventDuplicateSubmissions defaults to true and is independent of which indicator is displayed.
For an individual rw-active form, data-rw-loading="off" opts out of this loading layer. data-rw-loading-lock="true" or "false" overrides PreventDuplicateSubmissions for that form when loading is enabled. Invalid values are documented and ignored in favor of the global default. The TagHelper must emit a loading ownership marker for every enabled rw-active form, including when failed-form UX is off; do not reuse the failure-only data-rw-form marker for ownership.
<body data-rw-loading-boundary>
<span data-rw-loading-indicator hidden role="status" aria-live="polite">
Processing…
</span>
<form rw-active="true" data-rw-loading-boundary>
<button type="submit">Save</button>
<span data-rw-loading-indicator hidden role="status" aria-live="polite">
Saving…
</span>
</form>
</body>data-rw-loading-boundary is valid on a form or any ancestor element, including body or a Turbo Frame. The first data-rw-loading-indicator owned by that boundary is its indicator; an indicator inside a nested boundary does not belong to the outer boundary. Search outward when a nearer boundary has no indicator. At accepted-request start, remove hidden from the selected indicator, set data-rw-loading-state="pending" on the form and selected boundary, and maintain an internal active-request count for shared boundaries. On completion, restore the indicator's original hidden state and the prior loading-state value (or absence) only when the boundary count reaches zero. The fallback bar is one document-level element with its own active-request count and a polite, screen-reader-readable “Processing…” status. The app can style the fallback through [data-rw-loading-fallback]; the package supplies a usable default. Respect reduced-motion preferences.
The indicator stays visible while a request is pending, including a 10-second cold start. End the lifecycle once on success, handled or unhandled HTTP failure, network error, lazy token refresh failure, cancellation, form removal during Turbo replacement, or page departure. Existing failure UI remains responsible for explaining failure; do not leave a loading indicator covering it. A disconnected form or boundary must not leave a shared loader stuck on. Preserve the original disabled state of controls.
When locking is enabled, cancel a later submit event for the same pending form in the capture phase, before Turbo can start another request. This covers another submit button, an external form-associated submit control, Enter, later submitter.click(), and later form.requestSubmit(). Direct form.submit() bypasses Turbo and is outside this contract. Disable its submit controls during the pending request and restore only controls RazorWire changed. Other forms remain usable. This is client-side duplicate-action protection, not a server-side idempotency guarantee. data-rw-loading-lock="false" allows repeat submission for that form while retaining feedback; completion accounting must remain correct for overlapping requests.
The existing razorwire:form:submit-start and razorwire:form:submit-end failure-UX events keep their current meaning and gating. The new loading boundary works without consumer JavaScript; use the documented DOM state hooks for app styling. Update the public contract manifest for all new attributes and CSS hooks. Do not add an endpoint or persistent state.
Execution order
- High: Decouple the ownership marker and loading lifecycle from failed-form UX; otherwise forms with failure UX off remain uncovered.
- High: Add boundary selection, fallback bar, and concurrent-request cleanup; this gives users immediate feedback across full-page and frame forms.
- Medium: Add configurable repeat-submit locking and restore behavior; it depends on correct lifecycle accounting.
- Medium: Document and prove the contract with a sample and browser tests before release.
Acceptance Criteria
- An accepted
rw-activesubmission shows its applicable indicator by the next browser paint, before a deliberately delayed 5-second response. - Form-local indicator wins over site-wide indicator; site-wide wins over fallback. Exactly one loading indicator is visible for a given submission.
- The fallback bar appears for both full-page and frame-targeted forms and no delayed Turbo bar duplicates it, including after the 500 ms Turbo delay.
- Loading works with
EnableFailureUx=falseand withdata-rw-form-failure="off", without adding failed-form request markers, messages, or events back to those forms. - With locking enabled, two rapid user submissions create one request for that form, including Enter and a second submit control. Another form can submit. Global and form-level locking settings produce the documented behavior.
- A control already disabled before submission remains disabled afterward. RazorWire restores every control it disabled, including on failure or cancellation.
- Success, handled and unhandled HTTP failure, network error, lazy token refresh failure, cancellation, Turbo replacement, and page departure clear pending state exactly once. Two concurrent forms sharing a site-wide boundary keep it visible until both finish.
- Browser validation rejection shows no loading state and sends no request. A request delayed 10 seconds keeps the indicator visible without a timer-based reset.
- With JavaScript unavailable, the form keeps native HTML submission behavior and app-authored indicators remain hidden.
- Existing failed-form handling, anti-forgery, and Turbo navigation tests continue to pass. Generated assets and public docs match the authored TypeScript contract.
Testing Plan
| Layer | What to verify | Minimum new cases |
|---|---|---|
| C# unit | TagHelper marker and option defaults/precedence, including failure UX off and per-form opt-out | 4 |
| Node/browser-runtime | Boundary ownership and precedence, fallback, concurrent forms, locking/restoration, all terminal paths, invalid input | 12 |
| Playwright integration | Controlled 5-second full-page and frame submissions; next-paint feedback, one bar, request count, completion; lazy token hold/failure/retry with no unprotected form POST; reduced-motion and no-JS smoke check | 5 |
| Example and docs | One form-local and one site-wide loader, plus the zero-markup fallback | 1 example |
Run pnpm --dir Web run assets:razorwire:build, assets:razorwire:typecheck, assets:razorwire:test, and assets:razorwire:verify; run the RazorWire unit and MVC integration suites. Use the existing Web/ForgeTrust.RazorWire/Docs/runtime-contract-pipeline.md workflow. Do not hand-edit minified outputs.
Rollback Plan
Revert the package/runtime change and regenerated asset together. No data or infrastructure migration is involved.
Effort Estimate
About 20 hours, or 2–3 working days: options and TagHelper 3 hours; runtime lifecycle and UI 8 hours; tests 6 hours; sample and documentation 3 hours. Production cold-start latency and frequency are unknown; measure them separately in the affected app rather than inventing a framework-wide number.
Files Reference
| File | Change |
|---|---|
Web/ForgeTrust.RazorWire/RazorWireOptions.cs:303 |
Add and document form-loading options and precedence |
Web/ForgeTrust.RazorWire/TagHelpers/RazorWireFormTagHelper.cs:55 |
Emit independent loading ownership marker |
Web/ForgeTrust.RazorWire/assets/src/razorwire.ts:815 |
Add lifecycle/boundary/fallback behavior and separate it from failure handling |
Web/ForgeTrust.RazorWire/assets/contracts/razorwire-public-contracts.js:166 |
Document public DOM and CSS hooks |
Web/ForgeTrust.RazorWire/wwwroot/razorwire/razorwire.js |
Regenerate package output |
Web/ForgeTrust.RazorWire/test/razorwire-form-failure.test.mjs:521 |
Preserve failure behavior and add runtime loading coverage |
Web/ForgeTrust.RazorWire.Tests/RazorWireFormTagHelperTests.cs:6 |
Verify C# output and opt-outs |
Web/ForgeTrust.RazorWire.IntegrationTests/RazorWireMvcPlaywrightTests.cs:744 |
Add delayed-submission browser proof |
examples/razorwire-mvc/Views/Shared/Components/Counter/Default.cshtml:16 |
Show a local loading boundary in the runnable sample |
examples/razorwire-mvc/Views/Shared/_Layout.cshtml |
Show an optional site-wide boundary if suitable for the sample |
Web/ForgeTrust.RazorWire/README.md and Docs/form-failures.md |
Link a new loading reference and explain independence from failures |
Web/README.md and root README.md |
Add start-here wayfinding if adoption text is affected |
Out of Scope
- Navigation links, page visits, island fetches, background streams, and arbitrary app-owned
fetchcalls. - Detecting whether the serverless host is asleep or displaying a cold-start-specific message.
- Server-side idempotency, retries, or changing the underlying request protocol.
- Styling application-authored spinners or imposing a design system on host apps.
Activity