Description
With global view transitions enabled, an HTMX swap that begins while the document is hidden produces an unhandledrejection even though HTMX treats a skipped transition as normal.
Observed with HTMX 4.0.0 and Firefox 152:
InvalidStateError: Skipped ViewTransition due to document being hidden
Chromium reports the same condition with different wording.
Reproduction
- Set
htmx.config.transitions = true.
- Add an HTMX request whose response is delayed briefly.
- Trigger the request and hide/switch away from the document before the response is swapped.
- Observe the
unhandledrejection event when the response arrives.
The underlying DOM update still completes.
Cause
HTMX awaits only finished:
await document.startViewTransition(detail.task).finished;
The View Transitions specification requires ready to reject when the document is hidden, while finished fulfills after the update callback completes. It also notes that ready is created immediately and will produce an unhandledrejection unless handled.
The surrounding HTMX catch only handles rejection from finished, so it cannot consume the rejected ready promise.
Relevant source:
https://github.com/bigskysoftware/htmx/blob/v4.0.0/src/htmx.js#L2279-L2303
Relevant specification sections:
https://drafts.csswg.org/css-view-transitions-1/#dom-document-startviewtransition
https://drafts.csswg.org/css-view-transitions-1/#viewtransition-interface
Expected behavior
A view transition skipped for normal lifecycle reasons should not emit an unhandled promise rejection. HTMX could retain the returned ViewTransition and attach a rejection handler to its ready promise before awaiting finished.
The same code path is present in 4.0.0-beta6, so this is not specific to the stable release.
Description
With global view transitions enabled, an HTMX swap that begins while the document is hidden produces an
unhandledrejectioneven though HTMX treats a skipped transition as normal.Observed with HTMX 4.0.0 and Firefox 152:
Chromium reports the same condition with different wording.
Reproduction
htmx.config.transitions = true.unhandledrejectionevent when the response arrives.The underlying DOM update still completes.
Cause
HTMX awaits only
finished:The View Transitions specification requires
readyto reject when the document is hidden, whilefinishedfulfills after the update callback completes. It also notes thatreadyis created immediately and will produce anunhandledrejectionunless handled.The surrounding HTMX
catchonly handles rejection fromfinished, so it cannot consume the rejectedreadypromise.Relevant source:
https://github.com/bigskysoftware/htmx/blob/v4.0.0/src/htmx.js#L2279-L2303
Relevant specification sections:
https://drafts.csswg.org/css-view-transitions-1/#dom-document-startviewtransition
https://drafts.csswg.org/css-view-transitions-1/#viewtransition-interface
Expected behavior
A view transition skipped for normal lifecycle reasons should not emit an unhandled promise rejection. HTMX could retain the returned
ViewTransitionand attach a rejection handler to itsreadypromise before awaitingfinished.The same code path is present in 4.0.0-beta6, so this is not specific to the stable release.