diff --git a/packages/react-dom-bindings/src/client/ReactDOMComponent.js b/packages/react-dom-bindings/src/client/ReactDOMComponent.js index 46bdd05f627d6..cc773dea4de36 100644 --- a/packages/react-dom-bindings/src/client/ReactDOMComponent.js +++ b/packages/react-dom-bindings/src/client/ReactDOMComponent.js @@ -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, diff --git a/packages/react-dom-bindings/src/events/ReactDOMEventReplaying.js b/packages/react-dom-bindings/src/events/ReactDOMEventReplaying.js index a7846ab455214..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.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) { diff --git a/packages/react-dom-bindings/src/server/ReactFizzConfigDOM.js b/packages/react-dom-bindings/src/server/ReactFizzConfigDOM.js index 388491a79fd38..411e81180d9cf 100644 --- a/packages/react-dom-bindings/src/server/ReactFizzConfigDOM.js +++ b/packages/react-dom-bindings/src/server/ReactFizzConfigDOM.js @@ -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.')", ), ); 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 d7195d43ca063..042cfb23fefcd 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.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))}});'; 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 4d826753dc097..a41c7d6f362ff 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 @@ -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,