Skip to content

Commit 2220d8e

Browse files
allensquareSquirtle Squadclaude
committed
fix(github): leave media network failures to the player's quiet reload
A network blip on a signed video renewed its link and remounted the player, which aborted the player's own quiet reload. Expired and missing links fail as unsupported (code 4) in Chromium and WebKit, so only those take another link. 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 15c823b commit 2220d8e

2 files changed

Lines changed: 44 additions & 1 deletion

File tree

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

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,41 @@ it("never schedules a retry for public media or media whose own link loads", asy
535535
expect(refresh).not.toHaveBeenCalled();
536536
});
537537

538+
it("leaves network failures on a signed video to the player's quiet reload", async () => {
539+
vi.useFakeTimers();
540+
const refresh = vi.fn(async () => {});
541+
const view = render(
542+
<GitHubBody
543+
url={url}
544+
body={before}
545+
bodyHtml={`<video src="${signedVideo("1")}"></video>`}
546+
refresh={refresh}
547+
/>,
548+
);
549+
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);
559+
const signed = video();
560+
expect(signed).toHaveAttribute("src", signedVideo("1"));
561+
fireEvent.loadedData(signed);
562+
// A network blip neither reads again nor remounts the player.
563+
fail(2);
564+
await settle();
565+
expect(video()).toBe(signed);
566+
expect(refresh).not.toHaveBeenCalled();
567+
// When the player's own reloads give up, the panel still reads nothing.
568+
await wait(5 * 60_000);
569+
expect(refresh).not.toHaveBeenCalled();
570+
expect(vi.getTimerCount()).toBe(0);
571+
});
572+
538573
it("tries a link a poll delivers before the retry instead of reading again", async () => {
539574
vi.useFakeTimers();
540575
const refresh = vi.fn(() => Promise.reject(new Error("Not Found")));

‎src/bundled/github/GitHubBody.tsx‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,15 @@ function EmbeddedAttachment({
215215
className={styles.attachment}
216216
onLoadCapture={() => show(true)}
217217
onLoadedDataCapture={() => show(true)}
218-
onErrorCapture={() => show(false)}
218+
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.
222+
const target = event.target;
223+
if (target instanceof HTMLMediaElement && target.error?.code === 2)
224+
return;
225+
show(false);
226+
}}
219227
>
220228
{/* Media keeps a failure until remounted with a new source. */}
221229
<Fragment key={shown}>{children(shown)}</Fragment>

0 commit comments

Comments
 (0)