Wrap the bootstrap process in a function and expose it in the public api#3441
Wrap the bootstrap process in a function and expose it in the public api#3441maximebf wants to merge 1 commit intobigskysoftware:devfrom
Conversation
|
I think this could be a great change to resolve the loading issue htmx has always had with edge cases. see #2264 and the many linked issues and PR's we have tried in the past! The last proposal put forward was to implement a initialize() function so it could be good to rename your implementation to that maybe if it makes sense. don't think .init() would be good as it is already used in extensions etc. We have to make sure we don't cause any regressions or issues for existing users but I think your proposed change should be fully backwards compatible. The biggest issue is how to test and validate this solution is working? are you able to produce the most minimal html example that can show it is working as expected we can add to our manual tests? master...MichaelWest22:initialize Here is a quick stab at what other things might be needed you can borrow the good bits from. |
|
@maximebf I love this change! However, I would prefer the method be called |
Description
I'm working on implementing streaming responses in my app similarly to React Suspense. The main body of the page is returned first and then blocks of content are streamed and replaced in the page.
This method works great in practice but HTMX is not compatible with it because it waits on the DOMContentLoaded event to initialize itself. However, using this technique, the event only occurs once the request is finished. This is a problem as the user has a fully rendered page in front of his eyes, than can already be interacted with but HTMX is still not loaded.
My propose change exposes an htmx.bootstrap() function that allows to manually bootstrap htmx at a choosen time. The function can be safely called multiple times but it will only execute once. It will automatically trigger on DOMContentLoaded like it does today.
The change is minimal but allows greater control, needed for the streaming use case.
Testing
Tested manually + ran "npm run test"
Minimal change.
Checklist
masterfor website changes,devforsource changes)
approved via an issue
npm run test) and verified that it succeeded