Skip to content

Commit

Permalink
Remember parentNode in case onChange callback mutates DOM (#227)
Browse files Browse the repository at this point in the history
There's no guarantee that the onChange callback won't mutate the DOM in some way that removes the selected option node, thus creating a runtime error when null.dispatchEvent is called when trying to trigger the "blur" event on the parent. By saving the parentNode in a variable, we avoid this edge-case scenario.
  • Loading branch information
botandrose authored Nov 9, 2023
1 parent 3940696 commit 449d115
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/capybara/cuprite/javascripts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -356,12 +356,13 @@ class Cuprite {
} else if (value == false && !node.parentNode.multiple) {
return false;
} else {
this.trigger(node.parentNode, "focus");
let parentNode = node.parentNode;
this.trigger(parentNode, "focus");

node.selected = value;
this.changed(node);

this.trigger(node.parentNode, "blur");
this.trigger(parentNode, "blur");
return true;
}
}
Expand Down

0 comments on commit 449d115

Please sign in to comment.