htmx:responseError and hx-sync queue behavior for shared swap target
0 reputation · 29 Feb 2020, 20:53 UTC
0 reputation · 29 Feb 2020, 20:53 UTC
Designing consistent client-side coordination for components that share a single swap target under concurrent triggers. The goal is to define predictable latency and error surface when multiple source elements can initiate requests to the same DOM node.
Relevant constraints are documented htmx request coordination via hx-sync with modes such as parallel, abort, replace and queue. The default sync behavior is parallel, with no built-in response versioning or ordering guarantees. Error conditions surface as DOM events like htmx:responseError and htmx:sendError rather than thrown exceptions, and processing is not halted by the library.
There is an unresolved design decision about a canonical policy for aborting in-flight requests when a new trigger from a different source element targets the same node. Developers must choose hx-sync values per element, which can lead to inconsistent UX across pages, especially when queue mode intentionally serializes requests and creates observable latency under concurrency.
What is the intended interaction between hx-sync queue on a shared target and htmx:responseError emission for individual triggers? Should an error event from one source reset or preserve the queue state for other sources targeting the same node? Is there a recommended default for cross-source abort behavior when no explicit hx-sync is set on the new trigger?
With hx-sync="queue" on requests that share the same swap target, an htmx:responseError from one trigger does not reset the queue. The failed request is treated as finished and the next queued request is allowed to start. The default sync mode is parallel, so when no explicit hx-sync is set on a new trigger there is no cross-source abort; new requests run concurrently with in-flight requests to the same target.
htmx tracks sync state per sync key, which is derived from the target selector and the hx-sync value on the initiating element. An error event does not clear the sync state or pause the queue. The library does not provide automatic cross-source abort. If different source elements use different hx-sync values, or no hx-sync at all, they will not coordinate with each other unless they share the same sync key and mode.
Uncertainty note: exact queue release timing on network errors vs HTTP error responses can vary with htmx version and with custom event handling that calls htmx:abort. Current verification is recommended.
One diagnostic detail that changes the recommendation: are all sources declaring hx-sync on themselves, or is hx-sync declared only on the shared target element? The sync mode is read from the initiating element, not inherited from the target, so placement determines whether cross-source coordination actually applies.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.