Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Pull Request: Integrate morphdom for surgical DOM patching in LiveComponents
Summary
Replaces the brute-force
replaceChildstrategy inObsidianComponents.updateComponent()with [morphdom](https://github.com/patrick-steele-idem/morphdom) for surgical DOM diffing/patching. Only the nodes that actually changed are mutated — focus, cursor position, scroll state, CSS animations, and event listeners on unchanged nodes are preserved automatically. Morphdom is inlined (~4 KB minified) at the top of the file — zero external dependency.Changes
1. Morphdom inlined at top of file
Modified:
livecomponents.jsmorphdom()function — no CDN, no bundler required2. updateComponent() — rewritten with morphdom
Modified:
ObsidianComponents.updateComponent()replaceChild+ manual focus/cursor/value restoration (~30 lines)attachModelBindings()andattachSubmit()re-binding callsmorphdom(component.element, html, options)with two callbacks:onBeforeElUpdated— skips the actively focused input/textarea/select to preserve typingonNodeAdded— attacheslive:modelandlive:submitbindings on freshly created nodes only3. Anti-duplicate binding guards
Modified:
attachModelBindings(),attachSubmit()_liveModelBoundflag on inputs to prevent re-attaching listeners on morphdom-preserved nodes_liveSubmitBoundflag on forms for the same reason4. Stale reference fix in call()
Modified:
ObsidianComponents.call()updateComponent(), morphdom may replace the root element —component.elementbecomes staledisplayValidationErrors,showError, andhideLoadingnow re-fetch the reference viathis.components.get(componentId)after each update5. mountLazyComponents() — minor cleanup
Modified:
ObsidianComponents.mountLazyComponents()skeletonvariableNo Backend Changes
The server contract is unchanged — POST → JSON
{ success, html, event, state }. Morphdom operates entirely client-side on the samedata.htmlpayload.Breaking Changes
None. This is a transparent upgrade — all existing
live:attributes, actions, and server responses work identically.