Repository navigation
http: stop treating history restoration as an HTMX request - #98
Merged
Merged
Conversation
HTMX treats history restoration as a full page load, not as an HTMX request: HTMX 4.x omits HX-Request on it, and HTMX 2.x does the same when historyRestoreAsHxRequest is false. HTMX 1.9.x, and HTMX 2.x by default, still send the header, so IsHtmxRequest() returned true for the same request in some versions and false in others. With the common IsHtmxRequest() ? Partial(...) : View() pattern, HTMX 1.9.x and 2.x got a fragment in place of the page after a history cache miss. IsHtmxRequest() now returns false when HX-History-Restore-Request is true, so history restoration is not an HTMX request in any version. [HtmxRequest], Response.Htmx(...), and [HtmxResponse] follow it. HTMX 1.9.x and 2.x do not process response headers when they restore history, so skipping them loses nothing. HtmxRequestHeaders.Request still reports the HX-Request header alone. bigskysoftware/htmx#4139 (comment)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
HTMX treats history restoration as a full page load, not as an HTMX request bigskysoftware/htmx#4139. HTMX 4.x sends this request without
HX-Request, and so does HTMX 2.x withhistoryRestoreAsHxRequest: false. HTMX 1.9.x, and HTMX 2.x by default, still send the header, soIsHtmxRequest()gave different answers for the same request depending on the version.With HTMX 1.9.x and 2.x, after a history cache miss:
[HtmxRequest]withoutRequestType = Partialselects the HTMX-only action instead of the pageResponse.Htmx(...)and[HtmxResponse]add headers that HTMX ignores during history restoration.Fix:
IsHtmxRequest()now returnsfalsewhenHX-History-Restore-Requestistrue, so history restoration is not an HTMX request in any version.[HtmxRequest],Response.Htmx(...)and[HtmxResponse]follow it.HtmxRequestHeaders.Requeststill reports theHX-Requestheader alone.