-
Hi there, I'm using Is there an equivalent to htmx's https://htmx.org/attributes/hx-preserve/ for example? Is this possible with diffhtml? Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi @yatesco I've written a middleware in the past for this, I'm about to take off on a flight, but it was something like this working solution: import { createTree, innerHTML, toString, use } from 'diffhtml';
use({
syncTreeHook(vTree) {
if (vTree.attributes && 'x-preserve' in vTree.attributes) {
return vTree;
}
},
});
const out = createTree();
innerHTML(out, `<b preserve>test</ba>`);
innerHTML(out, `<b preserve>never changed</ba>`);
console.log(toString(out), 'contents will not update', 'test'); The idea is to skip diffing (sync phase) and simply return the previously rendered node with the attribute |
Beta Was this translation helpful? Give feedback.
Hi @yatesco I've written a middleware in the past for this, I'm about to take off on a flight, but it was something like this working solution:
The idea is to skip diffing (sync phase) and simply return the previously rendered node with the attribute
x-preserve
or whatever you want to call it.