michalsn / codeigniter-htmx

HTMX helper library for CodeIgniter 4 framework
https://michalsn.github.io/codeigniter-htmx/
MIT License
75 stars 15 forks source link

bug: Saving the previous URL #81

Closed neznaika0 closed 1 day ago

neznaika0 commented 2 days ago

Otherwise, the HTMX request may change the previous URL. While we are updating on the same page (tab), there is no problem. But if previous_url()returns another page, the result is unexpected. File vendor/codeigniter4/framework/system/CodeIgniter.php in storePreviousURL():

// Ignore AJAX requests
// Possible solution
// if ((method_exists($this->request, 'isHTMX') && $this->request->isHTMX()) || (method_exists($this->request, 'isAJAX') && $this->request->isAJAX())) {
if (method_exists($this->request, 'isAJAX') && $this->request->isAJAX()) {
    return;
}
...

or identify HTMX = AJAX. But it can introduce new dependencies.

michalsn commented 2 days ago

Well, I don't think there is currently anything that can be done about it. Adding customization options for this would be problematic.

The only workaround would be to use the ajax-header extension.

neznaika0 commented 2 days ago

the sick option is to change the service('codeigniter').

Perhaps it is worth writing recommendations? https://github.com/michalsn/codeigniter-htmx/blob/develop/docs/troubleshooting.md

michalsn commented 2 days ago

Oh, I forgot that CodeIgnter class is also a service. In that case, feel free to send a pull request.