Skip to content

Commit e486c16

Browse files
author
Brian Vaughn
committed
Added test repro for FB error
1 parent 350e02d commit e486c16

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

packages/react-dom/src/__tests__/ReactDOMFiber-test.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1280,4 +1280,40 @@ describe('ReactDOMFiber', () => {
12801280
);
12811281
expect(didCallOnChange).toBe(true);
12821282
});
1283+
1284+
it('unmounted legacy roots should never clear newer root content from a container', () => {
1285+
const ref = React.createRef();
1286+
1287+
function OldApp() {
1288+
const hideOnFocus = () => {
1289+
// This app unmounts itself inside of a focus event.
1290+
ReactDOM.unmountComponentAtNode(container);
1291+
};
1292+
1293+
return (
1294+
<button onFocus={hideOnFocus} ref={ref}>
1295+
old
1296+
</button>
1297+
);
1298+
}
1299+
1300+
function NewApp() {
1301+
return (
1302+
<button tabIndex={0} ref={ref}>
1303+
new
1304+
</button>
1305+
);
1306+
}
1307+
1308+
ReactDOM.render(<OldApp />, container);
1309+
ref.current.focus();
1310+
1311+
ReactDOM.render(<NewApp />, container);
1312+
1313+
// Calling focus again will flush previously scheduled discerete work for the old root-
1314+
// but this should not clear out the newly mounted app.
1315+
ref.current.focus();
1316+
1317+
expect(container.textContent).toBe('new');
1318+
});
12831319
});

0 commit comments

Comments
 (0)