Skip to content

Commit

Permalink
Remember parentNode in case onChange callback mutates DOM
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 Feb 24, 2023
1 parent c7dc979 commit 048880c
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 @@ -350,12 +350,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 048880c

Please sign in to comment.