Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions frontend/src/core/executions/__tests__/output-lifecycle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,22 @@ describe("output lifetime", () => {
}
});

it.each([text("43"), { mimetype: "text/html", data: "42" }])(
"keeps equivalent output cleared until the media changes to %o",
async (changed) => {
const { store, emit, snapshot } = await setup();
const [result, output] = MockExecutions.shown(C1, text("42"));
snapshot([result, output]);
clearCellOutputs(store, [C1]);

emit(MockExecutions.output(result, text("42")));
expect(store.get(cellOutputAtom(C1))).toBeNull();

emit(MockExecutions.output(result, changed));
expect(store.get(cellOutputAtom(C1))).toMatchObject(changed);
},
);

it("keeps a changed display visible after its execution retires", async () => {
const { store, replica, emit, remove, snapshot } = await setup();
const [result, output] = MockExecutions.shown(C1, text("A"));
Expand Down
17 changes: 16 additions & 1 deletion frontend/src/core/notebook/replica/resources/executions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,22 @@ function sameShown(
a: Pick<Result, "record" | "output">,
b: Pick<Result, "record" | "output">,
): boolean {
return JSON.stringify(shown(a)) === JSON.stringify(shown(b));
const left = shown(a);
const right = shown(b);
if (left === right) {
return true;
}
if (left === null || right === null || left.kind !== right.kind) {
return false;
}
if (left.kind === "output" && right.kind === "output") {
return (
left.media === right.media ||
(left.media?.mimetype === right.media?.mimetype &&
left.media?.data === right.media?.data)
);
}
return JSON.stringify(left) === JSON.stringify(right);
}

/** Replace an execution and keep its retained copies in step. */
Expand Down
Loading