From what I can tell, it's not possible to add any scrolling on swap with server-sent events. I'd like to be able to say hx-swap="beforeend scroll:bottom" and have it just work, but looking at the source code:
function processSSESwap(elt, sseEventName) {
var sseSourceElt = getClosestMatch(elt, hasEventSource);
if (sseSourceElt) {
var sseEventSource = getInternalData(sseSourceElt).sseEventSource;
var sseListener = function (event) {
if (maybeCloseSSESource(sseSourceElt)) {
sseEventSource.removeEventListener(sseEventName, sseListener);
return;
}
///////////////////////////
// TODO: merge this code with AJAX and WebSockets code in the future.
var response = event.data;
withExtensions(elt, function(extension){
response = extension.transformResponse(response, null, elt);
});
var swapSpec = getSwapSpecification(elt)
var target = getTarget(elt)
var settleInfo = makeSettleInfo(elt);
selectAndSwap(swapSpec.swapStyle, elt, target, response, settleInfo)
settleImmediately(settleInfo.tasks)
triggerEvent(elt, "htmx:sseMessage", event)
};
getInternalData(elt).sseListener = sseListener;
sseEventSource.addEventListener(sseEventName, sseListener);
} else {
triggerErrorEvent(elt, "htmx:noSSESourceError");
}
}
I notice that while the swapSpec is parsed correctly, we only ever use swapSpec.swapStyle - completely ignoring swapSpec.scroll.
From what I can tell, it's not possible to add any scrolling on swap with server-sent events. I'd like to be able to say
hx-swap="beforeend scroll:bottom"and have it just work, but looking at the source code:I notice that while the
swapSpecis parsed correctly, we only ever useswapSpec.swapStyle- completely ignoringswapSpec.scroll.