-
-
Notifications
You must be signed in to change notification settings - Fork 927
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
Fix domFor hitting null dom elements in while loop #3013
Conversation
641cddc
to
b9d2bfd
Compare
Could you confirm how Keep in mind, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comment
I can try but it's hard to trace this. It seems to only happen when deeply nested DOM elements are removed during m.mount. is it possible that a nextSibling could become null during the loop? I agree that this is likely a happy dom bug, but idk what I'm looking for on their end. I haven't been able to create reproducible version of this in a single JS file. |
Edit: improve examples
@thequailman Even a many-file repro is fine, and I was hoping for at least a repo to pull. I've even dealt with a few bug reports here where people outright linked websites because they weren't sure where to start. For minimizing repros, I approach it algorithmically and systematically. Remove a bit if code, test, keep if bug continues to repro, and repeat with something else until nothing else can be removed. Rarely, I find myself copying dependency code during this process, but it does sometimes help, especially if it's not framework code. I've gotten some very large minimal repros out of that process, but they were in fact minimal or close to it. It also helped me narrow down this bug report to a very subtle spec detail that only the browser we were buggy in was correctly implementing. And the tests for this PR are all fairly subtle and involved. But yeah, best way to find and minimize repros in my experience is to be as scientific as possible about it. |
Was able to reproduce it, it appears to be something with the import m from "mithril";
import { GlobalRegistrator } from "@happy-dom/global-registrator";
GlobalRegistrator.register();
function component() {
return {
view: () => {
return [m("select"), m("div")];
},
};
}
m.mount(document.body, component);
m.mount(document.body, null); This should produce an error: You can "fix" it by changing the tag from |
Closing, this is related to a happy-dom bug: capricorn86/happy-dom#1532 |
Description
The
domFor
while loop assumes that dom will always be not null, but it seems like some environments (like happy-dom) may incorrectly report the domSize when the underlying siblings contain nulls.Motivation and Context
I believe this fixes #2990, at least based on my testing.
Also, looking at the diff between 2.2.2 and 2.2.3 (when I think this behavior was introduced), the loop here that
domFor
replaced seems to check the child nodes for nulls:v2.2.2...v2.2.3#diff-f50a6d08fa58d22d2e71df97ae8fc5727ea53bc49c69f457ef12bc6df3c6870bL583
I think this behavior was missed in the
domFor
implementation.How Has This Been Tested?
I previously had a bunch of breaking components with Mithril 2.2.3+ and happy-dom. Upon investigation, it was happening with conditional component removals via ternaries. This change fixes all of my tests.
Types of changes
Checklist