Re:Show HN: I made a better DOM morphing algorithm
by fpsvogel on Sunday November 16, 2025 @07:24AM
(#45944593)
Do you have an example of this technique that you can link to, or a fuller discussion of it?
I have a soft spot for Alpine and Iām always on the lookout for things I can do with just Alpine.
The way I do it is to update everything _except_ for the DOM nodes that need to be excluded (via data attributes), e.g. the sidebar or a video player. I have found no problems with this approach as I maintain state since the JS is already running before clicking a link, and everything else is updated.
I think this is for if you absolutely have to SSR your markup at all times (e.g. using HTMX), but with something like Alpine.js and using <template> elements, there is no reason to DOM morph.
And like you say, if you need to use crazy advanced DOM morphing, you should probably be using a client side framework anyway. If not, I've gotten away with some very tricky state updates with just Alpine.js.