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

Firefox Uncaught Error: Expected node to have parent #54

Closed
mocanew opened this issue Sep 22, 2022 · 1 comment · Fixed by #55
Closed

Firefox Uncaught Error: Expected node to have parent #54

mocanew opened this issue Sep 22, 2022 · 1 comment · Fixed by #55

Comments

@mocanew
Copy link
Contributor

mocanew commented Sep 22, 2022

Repro: https://jsfiddle.net/jmd4a2Lc/

console.log('start exec');

const outer = document.createElement('div');
document.body.append(outer);

const inner = document.createElement('div');
outer.append(inner);
outer.remove();

console.log('finished exec');

This code triggers a "Uncaught Error: Expected node to have parent" in Firefox (tested on versions 103 and 104). This does not happen on Chrome (105).

The problematic part seems to be the successive sync append and remove operations. The mutation observer (incorrectly?) emits a MutationRecord for the removed node.

@mocanew
Copy link
Contributor Author

mocanew commented Sep 22, 2022

Added a potential fix in #55.
The first two conditions may be redundant as document.documentElement.parentNode should never be null. https://dom.spec.whatwg.org/#document-element:

The document element of a document whose parent is that document, if it exists; otherwise null.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant