From 40965ebd27a60bb9ca12994f2f338a24333851db Mon Sep 17 00:00:00 2001 From: Josh Story Date: Wed, 18 Oct 2023 15:03:42 -0700 Subject: [PATCH] Patch React with fix for write-after-close for ReadableStream (#57011) --- ...t-dom-server-legacy.browser.development.js | 21 +++++++++++++++---- ...om-server-legacy.browser.production.min.js | 4 ++-- ...eact-dom-server-legacy.node.development.js | 21 +++++++++++++++---- ...t-dom-server-legacy.node.production.min.js | 4 ++-- ...t-dom-server-rendering-stub.development.js | 2 +- ...om-server-rendering-stub.production.min.js | 2 +- .../react-dom-server.browser.development.js | 18 ++++++++++++---- ...react-dom-server.browser.production.min.js | 6 +++--- .../cjs/react-dom-server.edge.development.js | 18 ++++++++++++---- .../react-dom-server.edge.production.min.js | 6 +++--- .../cjs/react-dom-server.node.development.js | 18 ++++++++++++---- .../react-dom-server.node.production.min.js | 6 +++--- .../react-dom-unstable_testing.development.js | 2 +- ...act-dom-unstable_testing.production.min.js | 6 +++--- .../cjs/react-dom.development.js | 2 +- .../cjs/react-dom.production.min.js | 6 +++--- .../cjs/react-dom.profiling.min.js | 6 +++--- .../react-dom-experimental/package.json | 4 ++-- ...t-dom-server-legacy.browser.development.js | 21 +++++++++++++++---- ...om-server-legacy.browser.production.min.js | 4 ++-- ...eact-dom-server-legacy.node.development.js | 21 +++++++++++++++---- ...t-dom-server-legacy.node.production.min.js | 6 +++--- ...t-dom-server-rendering-stub.development.js | 2 +- ...om-server-rendering-stub.production.min.js | 2 +- .../react-dom-server.browser.development.js | 18 ++++++++++++---- ...react-dom-server.browser.production.min.js | 6 +++--- .../cjs/react-dom-server.edge.development.js | 18 ++++++++++++---- .../react-dom-server.edge.production.min.js | 6 +++--- .../cjs/react-dom-server.node.development.js | 18 ++++++++++++---- .../react-dom-server.node.production.min.js | 6 +++--- .../react-dom/cjs/react-dom.development.js | 2 +- .../react-dom/cjs/react-dom.production.min.js | 6 +++--- .../react-dom/cjs/react-dom.profiling.min.js | 6 +++--- .../next/src/compiled/react-dom/package.json | 4 ++-- 34 files changed, 205 insertions(+), 93 deletions(-) diff --git a/packages/next/src/compiled/react-dom-experimental/cjs/react-dom-server-legacy.browser.development.js b/packages/next/src/compiled/react-dom-experimental/cjs/react-dom-server-legacy.browser.development.js index d19392ed8d2cd..f67e6999ff45b 100644 --- a/packages/next/src/compiled/react-dom-experimental/cjs/react-dom-server-legacy.browser.development.js +++ b/packages/next/src/compiled/react-dom-experimental/cjs/react-dom-server-legacy.browser.development.js @@ -17,7 +17,7 @@ if (process.env.NODE_ENV !== "production") { var React = require("next/dist/compiled/react-experimental"); var ReactDOM = require('react-dom'); -var ReactVersion = '18.3.0-experimental-d900fadbf-20230929'; +var ReactVersion = '18.3.0-experimental-3cfcbc5bc-20231018'; var ReactSharedInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED; @@ -11264,7 +11264,10 @@ function flushCompletedQueues(request, destination) { } // We're done. - close(destination); + close(destination); // We need to stop flowing now because we do not want any async contexts which might call + // float methods to initiate any flushes after this point + + stopFlowing(request); } } } @@ -11284,10 +11287,17 @@ function enqueueFlush(request) { request.pingedTasks.length === 0 && // If there is no destination there is nothing we can flush to. A flush will // happen when we start flowing again request.destination !== null) { - var destination = request.destination; request.flushScheduled = true; scheduleWork(function () { - return flushCompletedQueues(request, destination); + // We need to existence check destination again here because it might go away + // in between the enqueueFlush call and the work execution + var destination = request.destination; + + if (destination) { + flushCompletedQueues(request, destination); + } else { + request.flushScheduled = false; + } }); } } @@ -11317,6 +11327,9 @@ function startFlowing(request, destination) { fatalError(request, error); } } +function stopFlowing(request) { + request.destination = null; +} // This is called to early terminate a request. It puts all pending boundaries in client rendered state. function abort(request, reason) { try { diff --git a/packages/next/src/compiled/react-dom-experimental/cjs/react-dom-server-legacy.browser.production.min.js b/packages/next/src/compiled/react-dom-experimental/cjs/react-dom-server-legacy.browser.production.min.js index 3bfe9118b1b45..97e2e177fc4ea 100644 --- a/packages/next/src/compiled/react-dom-experimental/cjs/react-dom-server-legacy.browser.production.min.js +++ b/packages/next/src/compiled/react-dom-experimental/cjs/react-dom-server-legacy.browser.production.min.js @@ -189,8 +189,8 @@ b);n.highImagePreloads.clear();n.styles.forEach(lc,b);n.scripts.forEach(N,b);n.s (n.push(K.startInlineScript),0===(C.instructions&4)?(C.instructions|=4,n.push('$RX=function(b,c,d,e){var a=document.getElementById(b);a&&(b=a.previousSibling,b.data="$!",a=a.dataset,c&&(a.dgst=c),d&&(a.msg=d),e&&(a.stck=e),b._reactRetry&&b._reactRetry())};;$RX("')):n.push('$RX("')):n.push('')){a.destination=null;c++;x.splice(0,c);return}}x.splice(0,c);var V=a.completedBoundaries;for(c=0;c")),a.hasHtml&&(b.push(""))),b.push(null))}}function oc(a){if(!1===a.flushScheduled&&0===a.pingedTasks.length&&null!==a.destination){var b=a.destination;a.flushScheduled=!0;Ne(a,b)}} +0===a.clientRenderedBoundaries.length&&0===a.completedBoundaries.length&&(a.flushScheduled=!1,null===a.trackedPostpones&&(c=a.resumableState,c.hasBody&&(b.push("")),c.hasHtml&&(b.push(""))),b.push(null),a.destination=null)}}function oc(a){if(!1===a.flushScheduled&&0===a.pingedTasks.length&&null!==a.destination){a.flushScheduled=!0;var b=a.destination;b?Ne(a,b):a.flushScheduled=!1}} function Te(a,b){try{var c=a.abortableTasks;if(0"):!n.push('">')){a.destination=null;c++;w.splice(0,c);return}}w.splice(0,c);var U=a.completedBoundaries;for(c=0;c")),a.hasHtml&&(b.push(""))),b.push(null))}}function pc(a){if(!1===a.flushScheduled&&0===a.pingedTasks.length&&null!==a.destination){var b=a.destination;a.flushScheduled=!0;Oe(a,b)}} +0===a.clientRenderedBoundaries.length&&0===a.completedBoundaries.length&&(a.flushScheduled=!1,null===a.trackedPostpones&&(c=a.resumableState,c.hasBody&&(b.push("")),c.hasHtml&&(b.push(""))),b.push(null),a.destination=null)}}function pc(a){if(!1===a.flushScheduled&&0===a.pingedTasks.length&&null!==a.destination){a.flushScheduled=!0;var b=a.destination;b?Oe(a,b):a.flushScheduled=!1}} function Ue(a,b){if(1===a.status)a.status=2,b.destroy(a.fatalError);else if(2!==a.status&&null===a.destination){a.destination=b;try{Oe(a,b)}catch(c){V(a,c),ze(a,c)}}}function Ve(a,b){try{var c=a.abortableTasks;if(0"):!q.push('">')){a.destination=null;c++;Q.splice(0,c);return}}Q.splice(0,c);var Y=a.completedBoundaries;for(c=0;c")),a.hasHtml&&(b.push("")),b.push(null))}}function fc(a){if(!1===a.flushScheduled&&0===a.pingedTasks.length&&null!==a.destination){var b=a.destination;a.flushScheduled=!0;ve(a,b)}} +0===a.completedBoundaries.length&&(a.flushScheduled=!1,c=a.resumableState,c.hasBody&&(b.push("")),c.hasHtml&&(b.push("")),b.push(null),a.destination=null)}}function fc(a){if(!1===a.flushScheduled&&0===a.pingedTasks.length&&null!==a.destination){a.flushScheduled=!0;var b=a.destination;b?ve(a,b):a.flushScheduled=!1}} function Be(a,b){try{var c=a.abortableTasks;if(0"):!p.push('">')){a.destination=null;c++;P.splice(0,c);return}}P.splice(0,c);var X=a.completedBoundaries;for(c=0;c")),a.hasHtml&&(b.push("")),b.push(null))}}function hc(a){if(!1===a.flushScheduled&&0===a.pingedTasks.length&&null!==a.destination){var b=a.destination;a.flushScheduled=!0;we(a,b)}}function Ce(a,b){if(1===a.status)a.status=2,b.destroy(a.fatalError);else if(2!==a.status&&null===a.destination){a.destination=b;try{we(a,b)}catch(c){U(a,c),ke(a,c)}}} -function De(a,b){try{var c=a.abortableTasks;if(0")),c.hasHtml&&(b.push("")),b.push(null),a.destination=null)}}function hc(a){if(!1===a.flushScheduled&&0===a.pingedTasks.length&&null!==a.destination){a.flushScheduled=!0;var b=a.destination;b?we(a,b):a.flushScheduled=!1}} +function Ce(a,b){if(1===a.status)a.status=2,b.destroy(a.fatalError);else if(2!==a.status&&null===a.destination){a.destination=b;try{we(a,b)}catch(c){U(a,c),ke(a,c)}}}function De(a,b){try{var c=a.abortableTasks;if(0'),q=c.idPrefix,t=[],p=null;void 0!==f&&t.push(n,(""+f).replace(rb,sb),kb);void 0!==l&&("string"===typeof l?(p={src:l,chunks:[]},mc(p.chunks,{src:l,async:!0,integrity:void 0,nonce:e})):(p={src:l.src,chunks:[]},mc(p.chunks,{src:l.src,async:!0,integrity:l.integrity,nonce:e})));f=[];void 0!==d&&(f.push(tb),f.push((""+JSON.stringify(d)).replace(rb,sb)),f.push(ub)); @@ -173,4 +173,4 @@ A(q));e&&t.push(nb,A(e));"string"===typeof f&&t.push(ob,A(f));"string"===typeof null,l=[],Q(l,f),d.bootstrapScripts.add(l),t.push(mb,A(n)),e&&t.push(nb,A(e)),"string"===typeof p&&t.push(ob,A(p)),"string"===typeof q&&t.push(pb,A(q)),t.push(qb);e=b?b.namespaceURI:void 0;e=B("http://www.w3.org/2000/svg"===e?3:"http://www.w3.org/1998/Math/MathML"===e?4:0,null,0);t=b?b.progressiveChunkSize:void 0;g=b?b.onError:void 0;n=b?b.onAllReady:void 0;q=b?b.onShellReady:void 0;p=b?b.onShellError:void 0;f=b?b.onPostpone:void 0;l=b?b.experimental_formState:void 0;Ka.current=Wa;b=[];h=new Set; c={destination:null,flushScheduled:!1,resumableState:c,renderState:d,rootFormatContext:e,progressiveChunkSize:void 0===t?12800:t,status:0,fatalError:null,nextSegmentId:0,allPendingTasks:0,pendingRootTasks:0,completedRootSegment:null,abortableTasks:h,pingedTasks:b,clientRenderedBoundaries:[],completedBoundaries:[],partialBoundaries:[],trackedPostpones:null,onError:void 0===g?ig:g,onPostpone:void 0===f?jg:f,onAllReady:void 0===n?jg:n,onShellReady:void 0===q?jg:q,onShellError:void 0===p?jg:p,onFatalError:jg, formState:void 0===l?null:l};d=qg(c,0,null,e,!1,!1);d.parentFlushed=!0;a=og(c,null,a,-1,null,d,h,null,e,ff,null,rf);b.push(a);return c} -exports.renderToPipeableStream=function(a,b){var c=Pg(a,b),d=!1;Kg(c);return{pipe:function(e){if(d)throw Error("React currently only supports piping to one writable stream.");d=!0;Lg(c,e);e.on("drain",Ng(e,c));e.on("error",Og(c,"The destination stream errored while writing data."));e.on("close",Og(c,"The destination stream closed early."));return e},abort:function(e){Mg(c,e)}}};exports.version="18.3.0-canary-d900fadbf-20230929"; +exports.renderToPipeableStream=function(a,b){var c=Pg(a,b),d=!1;Kg(c);return{pipe:function(e){if(d)throw Error("React currently only supports piping to one writable stream.");d=!0;Lg(c,e);e.on("drain",Ng(e,c));e.on("error",Og(c,"The destination stream errored while writing data."));e.on("close",Og(c,"The destination stream closed early."));return e},abort:function(e){Mg(c,e)}}};exports.version="18.3.0-canary-3cfcbc5bc-20231018"; diff --git a/packages/next/src/compiled/react-dom/cjs/react-dom.development.js b/packages/next/src/compiled/react-dom/cjs/react-dom.development.js index c160110408b1b..fd890ef9565e8 100644 --- a/packages/next/src/compiled/react-dom/cjs/react-dom.development.js +++ b/packages/next/src/compiled/react-dom/cjs/react-dom.development.js @@ -27000,7 +27000,7 @@ identifierPrefix, onRecoverableError, transitionCallbacks, formState) { return root; } -var ReactVersion = '18.3.0-canary-d900fadbf-20230929'; +var ReactVersion = '18.3.0-canary-3cfcbc5bc-20231018'; function createPortal$1(children, containerInfo, // TODO: figure out the API for cross-renderer implementation. implementation) { diff --git a/packages/next/src/compiled/react-dom/cjs/react-dom.production.min.js b/packages/next/src/compiled/react-dom/cjs/react-dom.production.min.js index 3bb4071fbdec0..b5a11684bb207 100644 --- a/packages/next/src/compiled/react-dom/cjs/react-dom.production.min.js +++ b/packages/next/src/compiled/react-dom/cjs/react-dom.production.min.js @@ -398,9 +398,9 @@ d);f?f.parentNode.insertBefore(e,f.nextSibling):(a=9===a.nodeType?a.head:a,a.ins Wn.prototype.unmount=Vn.prototype.unmount=function(){var a=this._internalRoot;if(null!==a){this._internalRoot=null;var b=a.containerInfo;Yj(function(){Bk(null,a,null,null)});b[vb]=null}};function Wn(a){this._internalRoot=a}Wn.prototype.unstable_scheduleHydration=function(a){if(a){var b=H;a={blockedOn:null,target:a,priority:b};for(var c=0;c