Skip to content

loading-states are persisted for preloaded requests #182

Description

@adamjhf

When using the loading-states extension with the preload extension, loading states are triggered by the preloaded requests, but the preloaded requests do not undo the loading states. This causes loading states to persist even after the request has completed.

This is caused by preloaded requests firing htmx:beforeRequest which triggers the loading state, but preloaded requests do not trigger htmx:beforeOnLoad which is used to undo the loading state in loading-states.

This is replicated by:

<html>

<head>
	<script src="https://unpkg.com/htmx.org@2.0.7/dist/htmx.min.js"></script>
	<script src="https://unpkg.com/htmx-ext-preload@2.1.1/preload.js"></script>
	<script src="https://unpkg.com/htmx-ext-loading-states@2.0.1/loading-states.js"></script>
	<style>[data-loading] { display: none; }</style>
</head>

<body hx-ext="loading-states,preload">
	<button hx-get="?" preload="mouseover"
		style="display: block; background: blue; color: white; height: 250px; width: 250px;">
		Mouse over to preload
	</button>
	<div data-loading>Loading...</div>
</body>

</html>

As preloaded requests are not intentionally initiated by the user and not necessarily needed, I suggest that preloaded requests should not trigger loading states at all.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions