Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

suspense fix: Cannot read property 'insertBefore' of undefined #4141

Merged
merged 3 commits into from
Sep 24, 2023
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
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
26 changes: 26 additions & 0 deletions compat/test/browser/suspense.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2100,4 +2100,30 @@ describe('suspense', () => {
expect(scratch.innerHTML).to.eql(`<p>hello new world</p>`);
});
});

it('should not crash if fallback has same DOM as suspended nodes', () => {
const [Lazy, resolveLazy] = createLazy();

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

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

render(<App />, scratch);
expect(scratch.innerHTML).to.equal('<div></div>');
rerender();

return resolveLazy(() => <p>hello world</p>).then(() => {
rerender();
expect(scratch.innerHTML).to.equal('<div><p>hello world</p></div>');
});
});
});
Loading