From 885932a21356e31fcd53a2c67a351465991bf9da Mon Sep 17 00:00:00 2001
From: Dave Long <dave@longwaveconsulting.com>
Date: Sat, 17 Feb 2024 15:33:48 +0000
Subject: [PATCH] Issue #3416141 by gorkagr, Jaypan, Wim Leers, alexpott:
 big_pipe.js' checkMutation() does not check if node exists before using it

(cherry picked from commit da7f4e63275fbd9a2a33d7379ba617a4093f805c)
---
 core/modules/big_pipe/js/big_pipe.js | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/core/modules/big_pipe/js/big_pipe.js b/core/modules/big_pipe/js/big_pipe.js
index 5d592e72f16b..3c3e106e7037 100644
--- a/core/modules/big_pipe/js/big_pipe.js
+++ b/core/modules/big_pipe/js/big_pipe.js
@@ -113,7 +113,12 @@
     // occur if the script node was first observed with empty content and then
     // the child text node was added in full later.
     // @see `@ingroup large_chunk` for more information.
-    else if (checkMutation(node.parentNode)) {
+    // If an element is added and then immediately (faster than the next
+    // setImmediate is triggered) removed to a watched element of a
+    // MutationObserver, the observer will notice and add a mutation for both
+    // the addedNode and the removedNode - but the referenced element will not
+    // have a parent node.
+    else if (node.parentNode !== null && checkMutation(node.parentNode)) {
       processReplacement(node.parentNode);
     }
   }
-- 
GitLab