Wrap the bootstrap process in a function and expose it in the public api #3441
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
master
for website changes,dev
forsource changes)
approved via an issue
npm run test
) and verified that it succeeded