Skip to content

Commit 0cf9335

Browse files
committed
fix(discord): preserve authored block order in presentation components
buildDiscordPresentationComponents rendered presentations in two passes - all text/context/divider blocks first, then every buttons/select block - so any block authored after a control was moved above it and controls always sank below all prose. Discord Components V2 layouts interleave freely and the deprecated single-pass renderer pins interleaving as the contract, so merge the passes into one order-preserving loop (title still pinned first).
1 parent dc93ea6 commit 0cf9335

2 files changed

Lines changed: 24 additions & 2 deletions

File tree

‎extensions/discord/src/shared-interactive.test.ts‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,30 @@ describe("buildDiscordInteractiveComponents", () => {
223223
expect(buildDiscordPresentationComponents(presentation)).toBeUndefined();
224224
});
225225

226+
it("preserves authored block order around controls", () => {
227+
expect(
228+
buildDiscordPresentationComponents({
229+
blocks: [
230+
{ type: "text", text: "First" },
231+
{
232+
type: "buttons",
233+
buttons: [{ label: "Approve", value: "approve", style: "success" }],
234+
},
235+
{ type: "text", text: "Last" },
236+
],
237+
}),
238+
).toEqual({
239+
blocks: [
240+
{ type: "text", text: "First" },
241+
{
242+
type: "actions",
243+
buttons: [{ label: "Approve", style: "success", callbackData: "approve" }],
244+
},
245+
{ type: "text", text: "Last" },
246+
],
247+
});
248+
});
249+
226250
it("renders typed approvals as actionable transport-private Discord controls", () => {
227251
const rendered = buildDiscordPresentationComponents({
228252
blocks: [

‎extensions/discord/src/shared-interactive.ts‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,6 @@ export function buildDiscordPresentationComponents(
229229
blocks.push({ type: "separator" });
230230
continue;
231231
}
232-
}
233-
for (const block of presentation.blocks) {
234232
if (block.type === "buttons") {
235233
appendDiscordButtonBlocks(blocks, block.buttons);
236234
continue;

0 commit comments

Comments
 (0)