@samitouri / QOS-React / commits / e4b816ba1a

s/getRootNode/ownerDocument (#28412)

getRootNode isn't always available, use ownerDocument instead

Ricky committed Feb 22, 2024 at 14:53 UTC e4b816ba1a1ea7c1874cf3f82dd841830b71341a
5 files changed +8 -8
packages/react-dom-bindings/src/client/ReactDOMComponent.js
+1 -1
@@ -2273,7 +2273,7 @@ function diffHydratedCustomComponent(
2273 // as a shared module for that reason.
2274 const EXPECTED_FORM_ACTION_URL =
2275 // eslint-disable-next-line no-script-url
2276 - "javascript:throw new Error('A React form was unexpectedly submitted.')";
2276 + "javascript:throw new Error('React form unexpectedly submitted.')";
2277
2278 function diffHydratedGenericElement(
2279 domElement: Element,
packages/react-dom-bindings/src/events/ReactDOMEventReplaying.js
+2 -1
@@ -537,7 +537,8 @@ export function retryIfBlockedOn(
537
538 if (enableFormActions) {
539 // Check the document if there are any queued form actions.
540 - const root = unblocked.getRootNode();
540 + // If there's no ownerDocument, then this is the document.
541 + const root = unblocked.ownerDocument || unblocked;
542 const formReplayingQueue: void | FormReplayingQueue = (root: any)
543 .$$reactFormReplay;
544 if (formReplayingQueue != null) {
packages/react-dom-bindings/src/server/ReactFizzConfigDOM.js
+1 -1
@@ -1015,7 +1015,7 @@ function makeFormFieldPrefix(resumableState: ResumableState): string {
1015 const actionJavaScriptURL = stringToPrecomputedChunk(
1016 escapeTextForBrowser(
1017 // eslint-disable-next-line no-script-url
1018 - "javascript:throw new Error('A React form was unexpectedly submitted.')",
1018 + "javascript:throw new Error('React form unexpectedly submitted.')",
1019 ),
1020 );
1021
packages/react-dom-bindings/src/server/fizz-instruction-set/ReactDOMFizzInstructionSetInlineCodeStrings.js
+1 -1
@@ -10,4 +10,4 @@ export const completeBoundaryWithStyles =
10 export const completeSegment =
11 '$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)};';
12 export const formReplaying =
13 - '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))}});';
13 + '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))}});';
packages/react-dom-bindings/src/server/fizz-instruction-set/ReactDOMFizzInstructionSetShared.js
+3 -4
@@ -131,7 +131,7 @@ export function completeSegment(containerID, placeholderID) {
131 // as a shared module for that reason.
132 const EXPECTED_FORM_ACTION_URL =
133 // eslint-disable-next-line no-script-url
134 - "javascript:throw new Error('A React form was unexpectedly submitted.')";
134 + "javascript:throw new Error('React form unexpectedly submitted.')";
135
136 export function listenToFormSubmissionsForReplaying() {
137 // A global replay queue ensures actions are replayed in order.
@@ -196,9 +196,8 @@ export function listenToFormSubmissionsForReplaying() {
196 // javascript: URL placeholder value. So we might not be the first to declare it.
197 // We attach it to the form's root node, which is the shared environment context
198 // where we preserve sequencing and where we'll pick it up from during hydration.
199 - // In practice, this is just the same as document but we might support shadow trees
200 - // in the future.
201 - const root = form.getRootNode();
199 + // If there's no ownerDocument, then this is the document.
200 + const root = form.ownerDocument || form;
201 (root['$$reactFormReplay'] = root['$$reactFormReplay'] || []).push(
202 form,
203 submitter,