-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Open
Description
HX-Location and HX-Redirect headers ignored during history restoration (back button navigation)
When htmx loads history from the server using the loadHistoryFromServer function, response headers like HX-Location and HX-Redirect are ignored.
This causes authentication applications to display blank pages when users press the back button after login.
Affected use case
This issue occurs when using hx-history="false", which forces htmx to load history from the server.
The following is an example flow that triggers this issue:
- User displays login form
- User successfully logs in and gets redirected to dashboard page that requires authentication
- User presses browser back button
- Browser returns to login form URL, htmx loads history from server (calls the
loadHistoryFromServerfunction) - Server detects user is already authenticated, responds with
HX-Locationheader to redirect to dashboard instead of returning login form HTML - htmx ignores the
HX-Locationheader and swaps the empty HTTP response body - Result: the login form becomes blank instead of proper redirect
Suggested solution
Added header processing logic in the loadHistoryFromServer function that follows similar logic to the existing handleAjaxResponse function.
This ensures that HX-Location and HX-Redirect headers are properly handled during back button navigation, resolving the authentication flow issue that I described above.
oles
Metadata
Metadata
Assignees
Labels
No labels