fix(web): restore composer controls as space becomes available (#9539)

This commit is contained in:
Julius Marminge authored and GitHub committed 2026-09-03 18:55:43 -07:00
1 parent 5989de44a2
commit 54aef6fbe1
2 files changed
+34 -3

No files matched your search

@@ -333,6 +333,33 @@ describe("resolveRestingComposerControlsLayout hysteresis", () => {
).toEqual({ hiddenCount: 0, visible: true });
});
it("restores the blocks that fit when the full cluster has no slack", () => {
const partlyRestored = resolveRestingComposerControlsLayout({
...base,
hostWidth: 357,
previous: { hiddenCount: 2, visible: true },
});
expect(partlyRestored).toEqual({ hiddenCount: 1, visible: true });
expect(
resolveRestingComposerControlsLayout({ ...base, hostWidth: 357, previous: partlyRestored }),
).toEqual(partlyRestored);
expect(
resolveRestingComposerControlsLayout({ ...base, hostWidth: 358, previous: partlyRestored }),
).toEqual({ hiddenCount: 0, visible: true });
});
it("requires slack before partially restoring a cluster", () => {
// One inline block, the picker, and overflow need 149 + 60 + 24 + 8 = 241px.
const previous = { hiddenCount: 2, visible: true };
expect(resolveRestingComposerControlsLayout({ ...base, hostWidth: 241, previous })).toEqual(
previous,
);
expect(resolveRestingComposerControlsLayout({ ...base, hostWidth: 242, previous })).toEqual({
hiddenCount: 1,
visible: true,
});
});
it("still resolves from scratch when there is no previous layout", () => {
expect(resolveRestingComposerControlsLayout({ ...base, hostWidth: 357 })).toEqual({
hiddenCount: 0,
@@ -134,9 +134,13 @@ export function resolveRestingComposerControlsLayout(
// composer re-measures on every render, so without that margin a host
// sitting exactly on a threshold flips a block in and out until React
// gives up with "Maximum update depth exceeded".
if (previous && hiddenCount < previous.hiddenCount) {
if (restingComposerControlsWidth(input, hiddenCount) > hostWidth - RESTING_CONTROLS_SLACK_PX) {
hiddenCount = Math.min(previous.hiddenCount, blockWidths.length);
if (previous) {
const previousHiddenCount = Math.min(previous.hiddenCount, blockWidths.length);
while (
hiddenCount < previousHiddenCount &&
restingComposerControlsWidth(input, hiddenCount) > hostWidth - RESTING_CONTROLS_SLACK_PX
) {
hiddenCount += 1;
}
}
const minimumWidth = restingComposerControlsWidth(input, hiddenCount, input.minimumFixedWidth);