Skip to content

Commit b2278f3

Browse files
authored
fix-discord-preserve-component-waiter-owner (#117492)
Co-authored-by: IWhatsskill <[email protected]>
1 parent 6c9b388 commit b2278f3

2 files changed

Lines changed: 39 additions & 1 deletion

File tree

‎extensions/discord/src/internal/client.test.ts‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,44 @@ describe("ComponentRegistry", () => {
106106
);
107107
});
108108

109+
it("preserves each message owner when replacing a one-off component wait", async () => {
110+
const registry = new ComponentRegistry<Button>();
111+
const firstMessage = {
112+
id: "message-1",
113+
channelId: "channel-1",
114+
owner: "first",
115+
} as never;
116+
const secondMessage = {
117+
id: "message-1",
118+
channelId: "channel-1",
119+
owner: "second",
120+
} as never;
121+
122+
const first = registry.waitForMessageComponent(firstMessage, 5_000);
123+
const second = registry.waitForMessageComponent(secondMessage, 5_000);
124+
const firstResult = await first;
125+
const resolved = registry.resolveOneOffComponent({
126+
channelId: "channel-1",
127+
customId: "choice:one",
128+
messageId: "message-1",
129+
values: ["one"],
130+
});
131+
const secondResult = await second;
132+
133+
expect(firstResult).toMatchObject({
134+
success: false,
135+
reason: "timed out",
136+
});
137+
expect(firstResult.message).toBe(firstMessage);
138+
expect(resolved).toBe(true);
139+
expect(secondResult).toMatchObject({
140+
success: true,
141+
customId: "choice:one",
142+
values: ["one"],
143+
});
144+
expect(secondResult.message).toBe(secondMessage);
145+
});
146+
109147
it("caps oversized one-off component wait timers", () => {
110148
vi.useFakeTimers();
111149
const timeoutSpy = vi.spyOn(globalThis, "setTimeout");

‎extensions/discord/src/internal/component-registry.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export class ComponentRegistry<
5858
const existing = this.oneOffComponents.get(key);
5959
if (existing) {
6060
clearTimeout(existing.timer);
61-
existing.resolve({ success: false, message, reason: "timed out" });
61+
existing.resolve({ success: false, message: existing.message, reason: "timed out" });
6262
}
6363
const timer = setTimeout(
6464
() => {

0 commit comments

Comments
 (0)