cuddly-keyboard-70746
10/09/2022, 1:08 AMcuddly-keyboard-70746
10/09/2022, 1:09 AMcuddly-keyboard-70746
10/09/2022, 1:10 AMcuddly-keyboard-70746
10/09/2022, 1:11 AMcuddly-keyboard-70746
10/09/2022, 1:11 AMcuddly-keyboard-70746
10/09/2022, 1:12 AMbrainy-ice-92385
10/09/2022, 1:29 AMcuddly-keyboard-70746
10/09/2022, 1:48 AMcuddly-keyboard-70746
10/09/2022, 1:49 AMcuddly-keyboard-70746
10/09/2022, 1:50 AMcuddly-keyboard-70746
10/09/2022, 1:53 AMcuddly-keyboard-70746
10/09/2022, 4:20 AMcuddly-keyboard-70746
10/09/2022, 4:20 AMcuddly-keyboard-70746
10/09/2022, 4:21 AMbrainy-ice-92385
10/09/2022, 7:20 AMsquare-oyster-36295
10/09/2022, 1:18 PMmergeHead
function and related functions - https://github.com/hotwired/turbo/blob/4e8ba783419cc01c0aa42d01cbca313e28b35016/src/core/drive/page_renderer.ts#L62
Their implementation even manages to perfectly merge, for example, in the case of the DEV mode of web development in Astro, which inserts inline or tags into the in addition to external links to JS/CSS. Everything is inserted and interpreted correctly. Duplicate content is not inserted there when browsing the web. At the same time, what happens is that the and tags are not removed, only added, because that would cause flickering and broken content when replaced.
Unlike HTMX, Turbo has a very limited use, but it can merge headers flawlessly.
By the way, I've mentioned it somewhere before, but we're looking to use HTMX by having a headless CMS and using Astro for the frontend. We use it for projects either in SSG mode, or for more dynamic projects with filter forms, in SSR mode. We generate 99% of HTML code only in SSR mode. In any case, we no longer want to strive for an isomorphic code, which is why we choose the Astro + HTMX way.
All pages and their URLs return complete HTML. Astro uses Vite and generates in the only the CSS and JS needed on the page. The production build includes a couple of external JS/CSS chunks in the related to current page. We also have little inline JS/CSS in selected components.square-oyster-36295
10/09/2022, 1:19 PMsquare-oyster-36295
10/09/2022, 1:34 PM<a href="/" hx-replace="#content,#sidebar:morphdom,#list:beforeend">
... so #content will be replaced by default swapping method, #sidebar by morphdom extension and #list by beforeend. This nifty functionality would solve many, many useful scenarios.mysterious-toddler-20573
10/09/2022, 2:38 PMmulti-swap
?
html
<button hx-get="/whatever" hx-ext="multi-swap" hx-swap="multi: #foo:innerHTML, #bar:outerHTML">
Multi-Swap It
</button>
Once we prove it with an extension, I could see moving this into core as well.mysterious-toddler-20573
10/09/2022, 2:40 PMsquare-oyster-36295
10/09/2022, 5:25 PMability to avoid being removed?
, it is really desirable to be able to disable removing. Removing style/link tags can trigger content flickering, so it is better to not removing them in some scenarios.square-oyster-36295
10/09/2022, 5:28 PMsquare-oyster-36295
10/09/2022, 5:35 PMbrainy-ice-92385
10/09/2022, 6:49 PM<script src="base.js" hx-preserve></script>
Then L47 here you should just be able to add a guard like if (! currentHeadChild.hasAttribute('hx-preserve')) { ... do the removal ...}
square-oyster-36295
10/09/2022, 6:53 PMhx-preserve
to these tags because they are generated by Astro/Vite. However, it should be easy to write a piece of your own JS code that would add hx-preserve
in the browser. But the option to disable tag removal would be simpler.brainy-ice-92385
10/09/2022, 6:57 PMsquare-oyster-36295
10/09/2022, 6:58 PMjavascript
htmx.defineExtension('multi-swap', {
isInlineSwap: function (swapStyle) {
return swapStyle.indexOf('multi:') === 0;
},
handleSwap: function (swapStyle, target, fragment, settleInfo) {
if (swapStyle.indexOf('multi:') === 0) {
var elements = {};
var elementsSplit = swapStyle.replace(/^multi\s*:\s*/, '').split(/\s*,\s*/);
elementsSplit.map(function (element) {
var elementSplit = element.split(/\s*:\s*/);
if (elementSplit.length == 2) {
elements[elementSplit[0]] = elementSplit[1];
} else if (elementSplit.length == 1) {
elements[elementSplit[0]] = "innerHTML";
}
});
for (var elementSelector in elements) {
var elementSwapStyle = elements[elementSelector];
// TODO: HOW TO CALL SWAP?
// swap(elementSwapStyle, elementSelector, target, fragment, settleInfo);
}
}
}
});
square-oyster-36295
10/09/2022, 7:05 PMhx-swap
attribute must not contain spaces, otherwise only e.g. "multi:" will be passed to the handleSwap
method. Below is an example.
For this , latest for
cycle in the code contains parsed elements and it's swap styles from hx-swap
, but now I don't know how to call swapping of these elements. If you don't have time to advise me, I will try to understand from the htmx.js code tomorrow how to implement it.
html
<a href="/contact" hx-ext="multi-swap" hx-swap="multi:#content:innerHTML,.exampleWithoutSwapStyle,#menu:outerHTML">Contact</a>
brainy-ice-92385
10/09/2022, 7:06 PMsquare-oyster-36295
10/09/2022, 7:08 PMselectAndSwap()
method, but I don't know if is this method usable in this case.