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

proposal: preserve fetching order #736

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

flochtililoch
Copy link
Collaborator

This PR introduce a new behavior boolean attribute, preserve-order. This attribute is used by behaviors that "fetch" content, i.e. anytime there's a href attribute set, with an update action such as replace, replace-inner, etc. When present, we compute a unique id before the request is emitted, and store it on an attribute of the target element. When the response arrives, we read the attribute of the target element and compare it to the one we generated before the request was sent. If the attribute is set with a value that's different from the one set before the request, we assume this means another request/response cycle took place, and the response we're presently dealing with is "outdated", so we discard it.

To be discussed:

  • naming: is "preserve-order" descriptive enough? should we use a boolean or an enum?
  • visibility: should we make this feature public / documented or keep it "dark" for now?
  • scope: should we think of this capability to be applied to other, non-fetching behaviors?

This PR introduce a new behavior boolean attribute, `preserve-order`.
This attribute is used by behaviors that "fetch" content, i.e. anytime there's a `href` attribute set, with an update action such as `replace`, `replace-inner`, etc. When present, we compute an unique id before the request is emitted, and store it on an attribute of the target element. When the response arrives, we read the attribute of the target element and compare it to the one we generated before the request was sent. If the attribute is set with a value that's different from the one set before the request, we assume this means another request/response cycle took place, and the response we're presently dealing with is "outdated", so we discard it.
@palaparthi
Copy link
Contributor

naming: is "preserve-order" descriptive enough?

"cancel-stale-requests" or "discard-stale-requests" might be more descriptive?

@adamstep
Copy link
Contributor

adamstep commented Nov 1, 2023

I was curious how this is implemented in htmx. Looks like that library stores a queue of requests, and using an attribute there are different strategies for managing the queue if the element issues multiple requests. See the docs here: https://htmx.org/attributes/hx-sync/

Do you think a similar approach could work in Hyperview?

@adamstep
Copy link
Contributor

adamstep commented Nov 3, 2023

Source code from htmx to deal with this: https://github.com/bigskysoftware/htmx/blob/master/src/htmx.js#L2980

@palaparthi palaparthi removed their request for review February 20, 2024 21:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants