Skip to content

Commit 449d115

Browse files
authored
Remember parentNode in case onChange callback mutates DOM (#227)
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.
1 parent 3940696 commit 449d115

File tree

1 file changed

+3
-2
lines changed
  • lib/capybara/cuprite/javascripts

1 file changed

+3
-2
lines changed

lib/capybara/cuprite/javascripts/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,12 +356,13 @@ class Cuprite {
356356
} else if (value == false && !node.parentNode.multiple) {
357357
return false;
358358
} else {
359-
this.trigger(node.parentNode, "focus");
359+
let parentNode = node.parentNode;
360+
this.trigger(parentNode, "focus");
360361

361362
node.selected = value;
362363
this.changed(node);
363364

364-
this.trigger(node.parentNode, "blur");
365+
this.trigger(parentNode, "blur");
365366
return true;
366367
}
367368
}

0 commit comments

Comments
 (0)