ui : measure assistant layout only for the last message

Every assistant message ran getComputedStyle, getBoundingClientRect and
a ResizeObserver over the previous user bubble at mount, even off-screen
ones, forcing a layout pass per message while a long conversation
renders. The measured vars only feed the :last-child min-height rule, so
gate the effect on isLastAssistantMessage; one measurement and one
observer remain, and the effect re-runs when the last message changes.

Assisted-by: pi:zai-org/GLM-5.3
This commit is contained in:
Aleksander Grygier
2026-09-06 01:47:54 +02:00
parent 7b00f950e5
commit 27091debfc
@@ -82,8 +82,11 @@
let lastUserMessageHeight = $state(0);
let assistantMarginTop = $state(0);
// The measured CSS vars feed the :last-child min-height rule only, so only
// the last assistant message needs them. Reading isLastAssistantMessage
// here also re-runs the effect when this message stops being the last.
$effect(() => {
if (!assistantEl) return;
if (!assistantEl || !isLastAssistantMessage) return;
assistantMarginTop = Math.round(parseFloat(getComputedStyle(assistantEl).marginTop));