Repository: facebook/react
Pull request: s/getRootNode/ownerDocument

getRootNode isn't always available, use ownerDocument instead

Changed files:
filename: packages/react-dom-bindings/src/client/ReactDOMComponent.js
patch: @@ -2273,7 +2273,7 @@ function diffHydratedCustomComponent(
 // as a shared module for that reason.
 const EXPECTED_FORM_ACTION_URL =
   // eslint-disable-next-line no-script-url
-  "javascript:throw new Error('A React form was unexpectedly submitted.')";
+  "javascript:throw new Error('React form unexpectedly submitted.')";
 
 function diffHydratedGenericElement(
   domElement: Element,

filename: packages/react-dom-bindings/src/events/ReactDOMEventReplaying.js
patch: @@ -537,7 +537,8 @@ export function retryIfBlockedOn(
 
   if (enableFormActions) {
     // Check the document if there are any queued form actions.
-    const root = unblocked.getRootNode();
+    // 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) {

filename: packages/react-dom-bindings/src/server/ReactFizzConfigDOM.js
patch: @@ -1015,7 +1015,7 @@ function makeFormFieldPrefix(resumableState: ResumableState): string {
 const actionJavaScriptURL = stringToPrecomputedChunk(
   escapeTextForBrowser(
     // eslint-disable-next-line no-script-url
-    "javascript:throw new Error('A React form was unexpectedly submitted.')",
+    "javascript:throw new Error('React form unexpectedly submitted.')",
   ),
 );
 

filename: packages/react-dom-bindings/src/server/fizz-instruction-set/ReactDOMFizzInstructionSetInlineCodeStrings.js
patch: @@ -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.getRootNode(),(a.$$reactFormReplay=a.$$reactFormReplay||[]).push(c,\nd,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(\'React form 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,d,b))}});';

filename: packages/react-dom-bindings/src/server/fizz-instruction-set/ReactDOMFizzInstructionSetShared.js
patch: @@ -131,7 +131,7 @@ export function completeSegment(containerID, placeholderID) {
 // as a shared module for that reason.
 const EXPECTED_FORM_ACTION_URL =
   // eslint-disable-next-line no-script-url
-  "javascript:throw new Error('A React form was unexpectedly submitted.')";
+  "javascript:throw new Error('React form unexpectedly submitted.')";
 
 export function listenToFormSubmissionsForReplaying() {
   // A global replay queue ensures actions are replayed in order.
@@ -196,9 +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.
-    // In practice, this is just the same as document but we might support shadow trees
-    // in the future.
-    const root = form.getRootNode();
+    // If there's no ownerDocument, then this is the document.
+    const root = form.ownerDocument || form;
     (root['$$reactFormReplay'] = root['$$reactFormReplay'] || []).push(
       form,
       submitter,