Skip to content

Commit 2632deb

Browse files
committed
make key required
1 parent 185eddc commit 2632deb

File tree

4 files changed

+12
-7
lines changed

4 files changed

+12
-7
lines changed

packages/browser-repl/src/components/shell-output-line.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ type ShellOutputEntryValue = any;
3535
type Glyph = 'ChevronRight' | 'XWithCircle' | 'ChevronLeft';
3636

3737
export interface ShellOutputEntry {
38-
key?: number | string;
38+
key: number | string;
3939
format: 'input' | 'output' | 'error';
4040
type?: string | null;
4141
value: ShellOutputEntryValue;

packages/browser-repl/src/components/shell-output.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,9 @@ export class ShellOutput extends Component<ShellOutputProps> {
1414
output: PropTypes.arrayOf(PropTypes.any).isRequired,
1515
};
1616

17-
renderLine = (entry: ShellOutputEntry, index: number): JSX.Element => {
17+
renderLine = (entry: ShellOutputEntry): JSX.Element => {
1818
return (
19-
<ShellOutputLine
20-
key={`shell-output-entry-${entry.key ?? index}`}
21-
entry={entry}
22-
/>
19+
<ShellOutputLine key={`shell-output-entry-${entry.key}`} entry={entry} />
2320
);
2421
};
2522

packages/browser-repl/src/components/shell.spec.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ function filterEvaluateCalls(calls: any) {
3737
});
3838
}
3939

40+
let lastKey = 0;
41+
4042
describe('shell', function () {
4143
let fakeRuntime;
4244
let scrollIntoView;
@@ -79,7 +81,7 @@ describe('shell', function () {
7981

8082
it('takes output', function () {
8183
const output: ShellOutputEntry[] = [
82-
{ format: 'output', value: 'Welcome message goes here' },
84+
{ key: lastKey++, format: 'output', value: 'Welcome message goes here' },
8385
];
8486

8587
render(<ShellWrapper runtime={fakeRuntime} output={output} />);
@@ -312,6 +314,7 @@ describe('shell', function () {
312314
let output: ShellOutputEntry[] = [];
313315
for (let i = 0; i < 1000; i++) {
314316
output.push({
317+
key: lastKey++,
315318
format: 'output',
316319
type: undefined,
317320
value: 'some result',
@@ -425,6 +428,7 @@ describe('shell', function () {
425428
it('clears the output when onClearCommand is called', async function () {
426429
let output: ShellOutputEntry[] = [
427430
{
431+
key: lastKey++,
428432
format: 'output',
429433
type: undefined,
430434
value: 'some result',

packages/browser-repl/src/components/shell.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,12 +357,14 @@ const _Shell: ForwardRefRenderFunction<EditorRef | null, ShellProps> = (
357357
runtime.setEvaluationListener(listener);
358358
const result = await runtime.evaluate(code);
359359
outputLine = {
360+
key: lastKey++,
360361
format: 'output',
361362
type: result.type,
362363
value: result.printable,
363364
};
364365
} catch (error) {
365366
outputLine = {
367+
key: lastKey++,
366368
format: 'error',
367369
value: error,
368370
};
@@ -383,6 +385,7 @@ const _Shell: ForwardRefRenderFunction<EditorRef | null, ShellProps> = (
383385
// don't evaluate empty input, but do add it to the output
384386
if (!code || code.trim() === '') {
385387
newOutputBeforeEval.push({
388+
key: lastKey++,
386389
format: 'input',
387390
value: ' ',
388391
});
@@ -394,6 +397,7 @@ const _Shell: ForwardRefRenderFunction<EditorRef | null, ShellProps> = (
394397

395398
// add input to output
396399
newOutputBeforeEval.push({
400+
key: lastKey++,
397401
format: 'input',
398402
value: code,
399403
});

0 commit comments

Comments
 (0)