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

No error handler for history cache miss and send error #3192

Open
WattsUp opened this issue Feb 16, 2025 · 1 comment
Open

No error handler for history cache miss and send error #3192

WattsUp opened this issue Feb 16, 2025 · 1 comment

Comments

@WattsUp
Copy link

WattsUp commented Feb 16, 2025

When a cache miss occurs, htmx will fetch content from the server. If the server replies with an >=200 && <400 status, then htmx:historyCacheMissLoadError fires. This works as expected.

However when I shutdown my server and initiate a cache miss fetch, no events are triggered (I checked htmx.logAll()). When the server is shutdown and a request is made then htmx:sendError gets triggered. I am expecting some similar event during cache miss to be fired.

It seems loadHistoryFromServer creates a new XHR without the helper function issueAjaxRequest that adds a xhr.onerror callback.

Side note: the docs say htmx:historyCacheMissError not htmx:historyCacheMissLoadError`

@MichaelWest22
Copy link
Contributor

I think this is expected from the way this feature is setup right now which may not be ideal in all situations. The history restore function is currently not compatible with the issue ajax request method and implementing the 1000+ line of code for this edge case is not going to be easy. I recommend trying to set htmx.config.refreshOnHistoryMiss to true which avoids all the custom handling and lets the browser handle what actually should be a full page load normally. The only other option is to listen for htmx:historyCacheMiss and do a few second setTimeout to retry if the htmx:historyCacheMissLoad event doesn't fire

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants