From fab27028a98ca2fd78e1ffb175f5bd65ded06baa Mon Sep 17 00:00:00 2001 From: Ricky Hanlon Date: Thu, 22 Feb 2024 10:47:57 -0500 Subject: [PATCH] unblocked may not === document --- .../react-dom-bindings/src/events/ReactDOMEventReplaying.js | 3 ++- .../ReactDOMFizzInstructionSetInlineCodeStrings.js | 2 +- .../fizz-instruction-set/ReactDOMFizzInstructionSetShared.js | 3 ++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/react-dom-bindings/src/events/ReactDOMEventReplaying.js b/packages/react-dom-bindings/src/events/ReactDOMEventReplaying.js index 5fa920a13f0fa..59c2920778008 100644 --- a/packages/react-dom-bindings/src/events/ReactDOMEventReplaying.js +++ b/packages/react-dom-bindings/src/events/ReactDOMEventReplaying.js @@ -537,7 +537,8 @@ export function retryIfBlockedOn( if (enableFormActions) { // Check the document if there are any queued form actions. - const root = unblocked === document ? unblocked : unblocked.ownerDocument; + // If there's no ownerDocument, then this is the document. + const root = unblocked.ownerDocument || unblocked; const formReplayingQueue: void | FormReplayingQueue = (root: any) .$$reactFormReplay; if (formReplayingQueue != null) { diff --git a/packages/react-dom-bindings/src/server/fizz-instruction-set/ReactDOMFizzInstructionSetInlineCodeStrings.js b/packages/react-dom-bindings/src/server/fizz-instruction-set/ReactDOMFizzInstructionSetInlineCodeStrings.js index c52ae5a3e34d9..44b624c736297 100644 --- a/packages/react-dom-bindings/src/server/fizz-instruction-set/ReactDOMFizzInstructionSetInlineCodeStrings.js +++ b/packages/react-dom-bindings/src/server/fizz-instruction-set/ReactDOMFizzInstructionSetInlineCodeStrings.js @@ -10,4 +10,4 @@ export const completeBoundaryWithStyles = export const completeSegment = '$RS=function(a,b){a=document.getElementById(a);b=document.getElementById(b);for(a.parentNode.removeChild(a);a.firstChild;)b.parentNode.insertBefore(a.firstChild,b);b.parentNode.removeChild(b)};'; export const formReplaying = - 'addEventListener("submit",function(a){if(!a.defaultPrevented){var c=a.target,d=a.submitter,e=c.action,b=d;if(d){var f=d.getAttribute("formAction");null!=f&&(e=f,b=null)}"javascript:throw new Error(\'A React form was unexpectedly submitted.\')"===e&&(a.preventDefault(),b?(a=document.createElement("input"),a.name=b.name,a.value=b.value,b.parentNode.insertBefore(a,b),b=new FormData(c),a.parentNode.removeChild(a)):b=new FormData(c),a=c===document?c:c.ownerDocument,(a.$$reactFormReplay=a.$$reactFormReplay||\n[]).push(c,d,b))}});'; + 'addEventListener("submit",function(a){if(!a.defaultPrevented){var c=a.target,d=a.submitter,e=c.action,b=d;if(d){var f=d.getAttribute("formAction");null!=f&&(e=f,b=null)}"javascript:throw new Error(\'A React form was unexpectedly submitted.\')"===e&&(a.preventDefault(),b?(a=document.createElement("input"),a.name=b.name,a.value=b.value,b.parentNode.insertBefore(a,b),b=new FormData(c),a.parentNode.removeChild(a)):b=new FormData(c),a=c.ownerDocument||c,(a.$$reactFormReplay=a.$$reactFormReplay||[]).push(c,\nd,b))}});'; diff --git a/packages/react-dom-bindings/src/server/fizz-instruction-set/ReactDOMFizzInstructionSetShared.js b/packages/react-dom-bindings/src/server/fizz-instruction-set/ReactDOMFizzInstructionSetShared.js index 73d1ccfd8ce4b..89f6c3cafe7ed 100644 --- a/packages/react-dom-bindings/src/server/fizz-instruction-set/ReactDOMFizzInstructionSetShared.js +++ b/packages/react-dom-bindings/src/server/fizz-instruction-set/ReactDOMFizzInstructionSetShared.js @@ -196,7 +196,8 @@ export function listenToFormSubmissionsForReplaying() { // javascript: URL placeholder value. So we might not be the first to declare it. // We attach it to the form's root node, which is the shared environment context // where we preserve sequencing and where we'll pick it up from during hydration. - const root = form === document ? form : form.ownerDocument; + // If there's no ownerDocument, then this is the document. + const root = form.ownerDocument || form; (root['$$reactFormReplay'] = root['$$reactFormReplay'] || []).push( form, submitter,