Skip to content

Commit d057182

Browse files
allensquareSquirtle Squadclaude
committed
fix(github): keep audio failures and the original link on media errors
Only video reloads quietly after a network error, so audio network errors take the normal failure path again. A video network error now shows the original link until the video loads again, so it stays beside "Video unavailable" when the player's reloads give up. Co-authored-by: Squirtle Squad <ec57954349ef49ce554b9cda062c34933dd3a085cf82278bb0e955efea492c7e@buzz.block.builderlab.xyz> Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Allen Tsai <[email protected]>
1 parent 2220d8e commit d057182

2 files changed

Lines changed: 49 additions & 18 deletions

File tree

‎src/bundled/github/GitHubBody.test.tsx‎

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,13 @@ const privateImage = (jwt: string) =>
317317
`<img src="${signedImage(jwt)}" alt="Screenshot">`;
318318
const privateBody = `![Screenshot](${image})`;
319319
const settle = () => act(async () => {});
320+
const fail = (element: HTMLMediaElement, code: number) => {
321+
Object.defineProperty(element, "error", {
322+
configurable: true,
323+
value: { code },
324+
});
325+
fireEvent.error(element);
326+
};
320327
const wait = (ms: number) =>
321328
act(async () => {
322329
await vi.advanceTimersByTimeAsync(ms);
@@ -541,35 +548,54 @@ it("leaves network failures on a signed video to the player's quiet reload", asy
541548
const view = render(
542549
<GitHubBody
543550
url={url}
544-
body={before}
551+
body={`[Movie](${before})`}
545552
bodyHtml={`<video src="${signedVideo("1")}"></video>`}
546553
refresh={refresh}
547554
/>,
548555
);
549556
const video = () => view.container.querySelector("video") as HTMLVideoElement;
550-
const fail = (code: number) => {
551-
const shown = video();
552-
Object.defineProperty(shown, "error", {
553-
configurable: true,
554-
value: { code },
555-
});
556-
fireEvent.error(shown);
557-
};
558-
fail(4);
557+
const movie = () => screen.queryByRole("link", { name: "Movie" });
558+
fail(video(), 4);
559559
const signed = video();
560560
expect(signed).toHaveAttribute("src", signedVideo("1"));
561561
fireEvent.loadedData(signed);
562-
// A network blip neither reads again nor remounts the player.
563-
fail(2);
562+
expect(movie()).not.toBeInTheDocument();
563+
// A network blip neither reads again nor remounts the player, and shows
564+
// the original link until the video loads again.
565+
fail(signed, 2);
564566
await settle();
565567
expect(video()).toBe(signed);
566-
expect(refresh).not.toHaveBeenCalled();
567-
// When the player's own reloads give up, the panel still reads nothing.
568+
expect(movie()).toHaveAttribute("href", before);
569+
fireEvent.loadedMetadata(signed);
570+
expect(movie()).not.toBeInTheDocument();
571+
// When the player's own reloads give up, the original link stays and the
572+
// panel still reads nothing.
573+
fail(signed, 2);
568574
await wait(5 * 60_000);
575+
expect(screen.getByText("Video unavailable")).toBeVisible();
576+
expect(movie()).toHaveAttribute("href", before);
569577
expect(refresh).not.toHaveBeenCalled();
570578
expect(vi.getTimerCount()).toBe(0);
571579
});
572580

581+
it("shows the original link when loaded audio fails on a network error", () => {
582+
const { container } = render(
583+
<GitHubBody url={url} body={`[Audio recording](${audio})`} />,
584+
);
585+
const element = container.querySelector("audio");
586+
if (!element) throw new Error("Missing audio");
587+
fireEvent.loadedData(element);
588+
expect(
589+
screen.queryByRole("link", { name: "Audio recording" }),
590+
).not.toBeInTheDocument();
591+
fail(element, 2);
592+
expect(screen.getByText("Audio unavailable")).toBeVisible();
593+
expect(screen.getByRole("link", { name: "Audio recording" })).toHaveAttribute(
594+
"href",
595+
audio,
596+
);
597+
});
598+
573599
it("tries a link a poll delivers before the retry instead of reading again", async () => {
574600
vi.useFakeTimers();
575601
const refresh = vi.fn(() => Promise.reject(new Error("Not Found")));

‎src/bundled/github/GitHubBody.tsx‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -215,13 +215,18 @@ function EmbeddedAttachment({
215215
className={styles.attachment}
216216
onLoadCapture={() => show(true)}
217217
onLoadedDataCapture={() => show(true)}
218+
// A video player reloads after a network failure (code 2) on its own,
219+
// so that keeps its link and only shows the original link until the
220+
// video loads again. An expired or missing link fails as unsupported
221+
// (code 4) in Chromium and WebKit, and takes another link. Audio has no
222+
// quiet reload, so any audio failure does.
223+
onLoadedMetadataCapture={() => setLoaded(true)}
218224
onErrorCapture={(event) => {
219-
// Players reload a network failure quietly. An expired or missing
220-
// link fails as unsupported (code 4) in Chromium and WebKit, so only
221-
// that takes another link.
222225
const target = event.target;
223-
if (target instanceof HTMLMediaElement && target.error?.code === 2)
226+
if (target instanceof HTMLVideoElement && target.error?.code === 2) {
227+
setLoaded(false);
224228
return;
229+
}
225230
show(false);
226231
}}
227232
>

0 commit comments

Comments
 (0)