Fix composer toolbar collapse flicker on tab switch (#2937)

Retained tabs stay mounted under display:none while inactive, which
reports a zero-width onLayout. ControlledAgentControls fed that
straight into its density resolver, so a hidden tab's toolbar
collapsed to its tightest density and painted one frame collapsed
before re-expanding when the tab became visible again.

Extract the zero-width guard that useContainerWidthBelow already had
into a shared readMeasuredWidth helper, and use it in the composer
toolbar's own layout handler so a display:none measurement can never
drive its density.

Also bump the chat outline rail's MIN_PANEL_WIDTH breakpoint (818 ->
918) so the rail disappears earlier under a narrower panel, and widen
the chat-outline e2e spec's viewport so its panel keeps healthy margin
over the new threshold.
This commit is contained in:
Mohamed Boudra
2026-08-06 18:37:38 +08:00
committed by GitHub
parent f2054cc701
commit 2298e9efdf
7 changed files with 179 additions and 6 deletions
@@ -64,6 +64,7 @@ import {
resolveAgentModelSelection,
} from "@/composer/agent-controls/utils";
import { useIsCompactFormFactor } from "@/constants/layout";
import { readMeasuredWidth } from "@/hooks/use-container-width";
import { useToast } from "@/contexts/toast-context";
import { toErrorMessage } from "@/utils/error-messages";
import { showProviderNoticeToast } from "@/utils/provider-notice-toast";
@@ -520,7 +521,8 @@ function ControlledAgentControls({
const handleLayout = useCallback(
(event: LayoutChangeEvent) => {
const availableWidth = event.nativeEvent.layout.width;
const availableWidth = readMeasuredWidth(event);
if (availableWidth === null) return;
availableWidthRef.current = availableWidth;
updateDensityForWidth(availableWidth);
},