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

loading-states.js data-loading-states scope not working properly #85

Open
Odas0R opened this issue Aug 19, 2024 · 3 comments
Open

loading-states.js data-loading-states scope not working properly #85

Odas0R opened this issue Aug 19, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@Odas0R
Copy link

Odas0R commented Aug 19, 2024

// <a> is boosted
<a href="/path"

// <a> request must not affect elements inside this div
// but it is, at the moment. All elements inside this div
// are affected by the outside <a> GET request
<div data-loading-states>
  <form
  hx-post="/api/v1/auth/sign-in"
  hx-trigger="submit">
  ...
  </form>
</div>

The problem is in:

function loadingStateContainer(target) {
  return htmx.closest(target, "[data-loading-states]") || document.body;
}


function getLoadingStateElts(loadingScope, type, path) {
  return Array.from(htmx.findAll(loadingScope, "[" + type + "]")).filter(
    function (elt) {
      return mayProcessLoadingStateByPath(elt, path);
    },
  );
}

The fix:

function loadingStateContainer(target) {
  return htmx.closest(target, "[data-loading-states]") || document.body;
}

function getLoadingStateElts(loadingScope, type, path) {
  return Array.from(htmx.findAll(loadingScope, "[" + type + "]")).filter(
    function (elt) {
      return (
        mayProcessLoadingStateByPath(elt, path) &&
        // ensure that the loadingScope is the same as the specified scope
        loadingStateContainer(elt) === loadingScope 
      );
    },
  );
}
@Odas0R Odas0R changed the title loading-states.js scopes not working properly loading-states.js data-loading-states scope not working properly Aug 19, 2024
@Telroshan Telroshan added the bug Something isn't working label Aug 20, 2024
@Telroshan
Copy link
Collaborator

Hey, feel free to submit bugfix pull requests directly!

@Odas0R
Copy link
Author

Odas0R commented Aug 22, 2024

Hey, feel free to submit bugfix pull requests directly!

Hey, I'm playing with it. Stumbled on #78 too. Will fix it, and after some tinkering, will open a PR.

This can stay open just for info purposes.

@Odas0R
Copy link
Author

Odas0R commented Aug 23, 2024

Found that loading state is still activated when cached responses are being used (in the browser). Also might have some suggestions in the future for the API

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants