Skip to content

Commit fad1dba

Browse files
authored
Merge pull request microsoft#183272 from microsoft/aamunger/outputStreaming
clear stale outputs when previously appended
2 parents 2eb365c + 6243bec commit fad1dba

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

extensions/notebook-renderers/src/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,10 @@ function renderStream(outputInfo: OutputItem, outputElement: HTMLElement, error:
291291
const existing = existingContentParent.querySelector(`[output-item-id="${outputInfo.id}"]`) as HTMLElement | null;
292292
if (existing) {
293293
existing.replaceWith(content);
294+
while (content.nextSibling) {
295+
// clear out any stale content if we had previously combined streaming outputs into this one
296+
content.nextSibling.remove();
297+
}
294298
} else {
295299
existingContentParent.appendChild(content);
296300
}

extensions/notebook-renderers/src/test/notebookRenderer.test.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ suite('Notebook builtin output renderer', () => {
146146

147147
const inserted = outputElement.firstChild as HTMLElement;
148148
assert.ok(inserted, `nothing appended to output element: ${outputElement.innerHTML}`);
149-
assert.ok(!outputElement.classList.contains('remove-padding'), `Padding should not be removed for non-scrollable outputs: ${outputElement.classList}`);
149+
assert.ok(outputElement.classList.contains('remove-padding'), `Padding should be removed for non-scrollable outputs: ${outputElement.classList}`);
150150
assert.ok(!inserted.classList.contains('word-wrap') && !inserted.classList.contains('scrollable'),
151151
`output content classList should not contain word-wrap and scrollable ${inserted.classList}`);
152152
assert.ok(inserted.innerHTML.indexOf('>content</') > -1, `Content was not added to output element: ${outputElement.innerHTML}`);
@@ -225,5 +225,30 @@ suite('Notebook builtin output renderer', () => {
225225
assert.ok(inserted.innerHTML.indexOf('>second stream content</') > -1, `Content was not added to output element: ${outputElement.innerHTML}`);
226226
assert.ok(inserted.innerHTML.indexOf('>third stream content</') > -1, `Content was not added to output element: ${outputElement.innerHTML}`);
227227
});
228+
229+
test(`Multiple adjacent streaming outputs, rerendering the first should erase the rest`, async () => {
230+
const context = createContext();
231+
const renderer = await activate(context);
232+
assert.ok(renderer, 'Renderer not created');
233+
234+
const outputHtml = new OutputHtml();
235+
const outputElement = outputHtml.getFirstOuputElement();
236+
const outputItem1 = createOutputItem('first stream content', stdoutMimeType, '1');
237+
const outputItem2 = createOutputItem('second stream content', stdoutMimeType, '2');
238+
const outputItem3 = createOutputItem('third stream content', stderrMimeType, '3');
239+
await renderer!.renderOutputItem(outputItem1, outputElement);
240+
await renderer!.renderOutputItem(outputItem2, outputHtml.appendOutputElement());
241+
await renderer!.renderOutputItem(outputItem3, outputHtml.appendOutputElement());
242+
const newOutputItem1 = createOutputItem('replaced content', stderrMimeType, '1');
243+
await renderer!.renderOutputItem(newOutputItem1, outputElement);
244+
245+
246+
const inserted = outputElement.firstChild as HTMLElement;
247+
assert.ok(inserted, `nothing appended to output element: ${outputElement.innerHTML}`);
248+
assert.ok(inserted.innerHTML.indexOf('>replaced content</') > -1, `Content was not added to output element: ${outputElement.innerHTML}`);
249+
assert.ok(inserted.innerHTML.indexOf('>first stream content</') === -1, `Content was not cleared: ${outputElement.innerHTML}`);
250+
assert.ok(inserted.innerHTML.indexOf('>second stream content</') === -1, `Content was not cleared: ${outputElement.innerHTML}`);
251+
assert.ok(inserted.innerHTML.indexOf('>third stream content</') === -1, `Content was not cleared: ${outputElement.innerHTML}`);
252+
});
228253
});
229254

0 commit comments

Comments
 (0)