From 449d11568c471676c3672b11df019d734ab1593f Mon Sep 17 00:00:00 2001 From: Micah Geisel Date: Thu, 9 Nov 2023 08:06:01 +0000 Subject: [PATCH] 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. --- lib/capybara/cuprite/javascripts/index.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/capybara/cuprite/javascripts/index.js b/lib/capybara/cuprite/javascripts/index.js index 3657add..2bab946 100644 --- a/lib/capybara/cuprite/javascripts/index.js +++ b/lib/capybara/cuprite/javascripts/index.js @@ -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; } }