-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
hx-history not working on partial content #3165
Comments
I have also noticed a condition that could be problematic. localStorage vs sessionStorage. |
By using a a temporary list of functions instead of adding the functions to the DOMContentLoaded, we can mitigate the issues where the event is sometimes not fired. Also, using the window.onload as a backup to trigger the functions.
Fixes case where htmx is loaded async and DOMContentLoaded is never fired.
Yeah there is a good argument to be made that htmx should use session storage instead of local. Are you linking to htmx in a head tag properly when you have this issue? I've seen similar issues in #2865 where the htmx script tag is not loaded correctly in the head tag. Htmx has to load and stay loaded all the time for history navigation to work as expected. Pushing back if historyCacheSize is not zero should just swap the body contents but retain the head scripts like htmx in place. I only got it to work properly when htmx was loaded in the body by testing modifying it to store it's saved history url value into sessionStorage from memory. |
No no, it's async.
async (basically script load with a script over in head/body - ie ... we do not have control of the page) It is loaded during page load basically. The problem is (see my bugfix) is the ready function never gets called when doing this. When looking into the code, the history/forward/backward functions are setup during the DOMContentLoaded - but since that event never fires in this case, it never sets the above up - thus a failure mode. |
For the referenced issue - it is possible that it's having a similar effect since it is at the end of the body instead. |
When using
hx-push-url
with partial content, pressing the back button does not actually work.From looking at the code, it seems that it's related to the context being on the body.
In the case where we do not actually control the body, the history aspect fails completely.
I have been digging and it seems there is a case where HTMX is loaded dynamically on page load where the DOMContentLoaded is never triggered.
If I instead push the events for the ready function into an array, and then manually call those functions, everything works perfectly.
htmx/src/htmx.js
Lines 4994 to 5014 in 10e8656
So, we need to find a way to reliably trigger that event... I'll keep looking and update this accordingly.
The text was updated successfully, but these errors were encountered: