Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[backport][v1] Add capabilities to cancel an hx-trigger polling #2577

Open
wants to merge 1 commit into
base: v1
Choose a base branch
from

Conversation

xhaggi
Copy link
Contributor

@xhaggi xhaggi commented May 29, 2024

Description

This adds three ways to cancel an hx-trigger polling. The first is a new configuration option htmx.config.cancelPollingOnError, which can be activated to cancel an hx-trigger polling in case of an error (status not 200). The second is a new event htmx:cancelPolling and the third is a new response header HX-Cancel-Polling.

document.addEventListener('htmx:cancelPolling', function(evt) {
    if (evt.detail.xhr.status !== 200) {
      evt.preventDefault();
    }
});

Corresponding issue: #2489

Testing

Unit tests added.

Checklist

  • I have read the contribution guidelines
  • I have targeted this PR against the correct branch (master for website changes, dev for
    source changes)
  • This is either a bugfix, a documentation update, or a new feature that has been explicitly
    approved via an issue
  • I ran the test suite locally (npm run test) and verified that it succeeded

@xhaggi xhaggi force-pushed the v1/cancel-polling-on-error branch from 98dc62a to 08152d7 Compare May 29, 2024 14:34
@Telroshan Telroshan added enhancement New feature or request 1.0 labels May 30, 2024
@xhaggi xhaggi force-pushed the v1/cancel-polling-on-error branch from 08152d7 to f83ea62 Compare May 30, 2024 08:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1.0 enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants