Skip to content

Commit 9bb5ad2

Browse files
fix(mobile): removing a thumbnail with the card open no longer strands the draft in it
The compact slot is measured only while collapsed, so a measurement taken beside a thumbnail outlived the thumbnail when it was removed with the card open. Each measurement now records how many thumbnails sat in the row and is ignored for any other count, so the next collapsed layout measures the slot again. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 52ad83f commit 9bb5ad2

3 files changed

Lines changed: 24 additions & 2 deletions

File tree

‎apps/mobile/src/features/threads/ThreadComposer.tsx‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,11 @@ export function useCompactComposerEditor(
201201
editorX.set(x);
202202
editorWidth.set(width);
203203
const compactWidth = Math.max(0, width - 8);
204+
const attachmentCount = state.rowAttachmentCount;
204205
setSlot((current) =>
205-
current.compactWidth === compactWidth ? current : { ...current, compactWidth },
206+
current.compactWidth === compactWidth && current.attachmentCount === attachmentCount
207+
? current
208+
: { ...current, compactWidth, attachmentCount },
206209
);
207210
}
208211
},

‎apps/mobile/src/features/threads/compactComposerLayout.test.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,15 @@ function composer(
2323
readonly contentSize?: { readonly width: number; readonly height: number };
2424
readonly compactWidth?: number;
2525
readonly attachmentCount?: number;
26+
readonly measuredAttachmentCount?: number;
2627
} = {},
2728
) {
2829
const { isExpanded, modelIconOnly } = resolveCompactComposerLayout({
2930
slot: {
3031
...EMPTY_COMPACT_COMPOSER_SLOT,
3132
rowWidth: input.rowWidth ?? NARROW,
3233
compactWidth: input.compactWidth ?? 200,
34+
attachmentCount: input.measuredAttachmentCount ?? input.attachmentCount ?? 0,
3335
},
3436
isFocused: input.isFocused ?? false,
3537
isAndroid: input.isAndroid ?? false,
@@ -118,4 +120,16 @@ describe("compact composer layout", () => {
118120
slot = compactSlotAfterLabelLayout(slot, { ...label, width: 160 });
119121
expect(composer({ ...line, compactWidth: slot.compactWidth }).isExpanded).toBe(false);
120122
});
123+
124+
it("re-measures a narrow row's slot when its thumbnail is removed with the card open", () => {
125+
const line = { value: "a short line", contentSize: { width: 150, height: LINE_HEIGHT } };
126+
const measuredWithThumbnail = { compactWidth: 138, measuredAttachmentCount: 1 };
127+
expect(composer({ ...line, ...measuredWithThumbnail, attachmentCount: 1 }).isExpanded).toBe(
128+
true,
129+
);
130+
expect(composer({ ...line, ...measuredWithThumbnail, attachmentCount: 0 }).isExpanded).toBe(
131+
false,
132+
);
133+
expect(composer({ ...line, compactWidth: 172 }).isExpanded).toBe(false);
134+
});
121135
});

‎apps/mobile/src/features/threads/compactComposerLayout.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,15 @@ interface CompactComposerSlot {
88
readonly rowWidth: number;
99
/** The editor's collapsed width, or 0 until it is measured again. */
1010
readonly compactWidth: number;
11+
/** Thumbnails in the row when `compactWidth` was measured; it is stale for any other count. */
12+
readonly attachmentCount: number;
1113
readonly label: { readonly width: number; readonly isExpanded: boolean };
1214
}
1315

1416
export const EMPTY_COMPACT_COMPOSER_SLOT: CompactComposerSlot = {
1517
rowWidth: 0,
1618
compactWidth: 0,
19+
attachmentCount: 0,
1720
label: { width: 0, isExpanded: false },
1821
};
1922

@@ -64,7 +67,9 @@ export function resolveCompactComposerLayout(input: {
6467
readonly modelIconOnly: boolean;
6568
readonly labelShownAtRest: boolean;
6669
} {
67-
const { rowWidth, compactWidth } = input.slot;
70+
const { rowWidth } = input.slot;
71+
const compactWidth =
72+
input.slot.attachmentCount === input.rowAttachmentCount ? input.slot.compactWidth : 0;
6873
const isWide = isWideComposerRow(rowWidth);
6974
const opensOnFocus =
7075
rowWidth > 0 &&

0 commit comments

Comments
 (0)