Reimplement Turbo support using MutationObserver #807
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.
My attempt to tackle #796.
There are many changed files, but the bulk of them are to allow initializing only a subtree of the DOM instead of the whole document. The actual core of the functionality is in
src/dom/observer.ts
.The only Turbo-specific code is the initial load event. After that, all new elements are initialized automatically, regardless how they entered the DOM (Turbo Frame, Turbo Stream, jQuery, innerHTML, insertAdjacentHTML, append, appendChild, Vue, React, ...)
Similiarly, whenever a DOM element gets removed, and it had an ID, and that ID responds to any component instance, that instance is removed and destroyed.
Components from unchanged parts of the DOM are not touched. (This is the deciding difference, compared with the previous event-based "sledgehammer" approach)
I tested this successfully, with a simple app, where a Flowbite modal is created on-the-fly with HTML sent via both Turbo frame and Turbo stream actions.
Unfortunately, I don't have a larger Flowbite-and-Turbo-based app to play around with, so I'm hoping for feedback on how well (or not) this behaves in a larger app with many components and/or heavy Turbo frame or Turbo stream usage.