Skip to content

Commit

Permalink
suspense fix: Cannot read property 'insertBefore' of undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
zakstucke committed Sep 24, 2023
1 parent 64be3cb commit 8029d17
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion compat/src/suspense.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ function detachedClone(vnode, detachedParent, parentDom) {
}

function removeOriginal(vnode, detachedParent, originalParent) {
if (vnode) {
if (vnode && originalParent) {
vnode._original = null;
vnode._children =
vnode._children &&
Expand Down
25 changes: 25 additions & 0 deletions compat/test/browser/suspense.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2100,4 +2100,29 @@ describe('suspense', () => {
expect(scratch.innerHTML).to.eql(`<p>hello new world</p>`);
});
});

it('originalParent undefined should not crash', () => {
const C = lazy(async () => {
await new Promise(r => setTimeout(r, 1000));
const Comp = () => <p>hello world</p>;
return {
default: Comp
};
});

const App = () => {
const [, setTest] = useState(false);
useLayoutEffect(() => setTest(true), []);

return (
<Suspense fallback={<div />}>
<div>
<C />
</div>
</Suspense>
);
};

render(<App />, scratch);
});
});

0 comments on commit 8029d17

Please sign in to comment.