-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
Don't load entire page when switching tabs in repo #28987
Conversation
Because of "don't block rendering" reasons I think. |
My suggestion is "do not do that". Even if you make it work by some hacky approaches, it would also break custom templates with custom scripts. |
Does index.js assume the entire DOM is loaded when it runs? If I replace an element is it sure to break? |
Don't think so. Everything should get loaded when the document is ready. |
So why is this change wrong I wonder. Something breaks when I replace the entire body. |
It has been documented by Add htmx guidelines #28993 And #28993 (comment) :
|
Can we generalize the init functions with a MutationObserver on the body? |
I haven't spent time on investigating it (the Gitea frontend init approaches), so no idea from my side at the moment. |
https://htmx.org/docs/#3rd-party Doesn't |
The thing is, if I rerun index.js I see this error: But everything works |
No, it doesn't. You would call many "init" functions twice, which would lead to unexpected results or behaviors. "Things seem to work" doesn't mean it really works without bugs. |
And the init methods would re-add click handlers for existing elements. |
But htmx replaces the entire body |
There is a lot of JS code which is "global", not only to "body". See the index.js |
This is (as of now a failed) attempt at using
hx-boost
to make the tab-switching experience more pleasant.hx-boost
takes normal anchor tags and issues an AJAX request instead, grabs the body of the response HTML, and replaces the body in the DOM. It doesn't reprocess the<head>
so we save time on loading styles and javascript.The problem I am facing is our index.js initialization. It's at the bottom of our

<body>
so it gets executed twice. When it does, I get the following error:If I disable the
index.js
on boosted requests withthe page loses some functionality such as clicking the avatar and getting a dropdown.
Why is
index.js
imported in the body and not in the head?BTW this is how it looks
Before, look at the avatars jumping
After, reactive buttons, the avatars are not jumping