From f9c996e089e24fdb9fc618858f83aa00e9b608ed Mon Sep 17 00:00:00 2001 From: Fran Dios Date: Tue, 7 Jun 2022 11:37:49 +0900 Subject: [PATCH] Add highWaterMark default to React Flight readable --- .../cjs/react-server-dom-vite-plugin.js | 3 ++- ...-vite-writer.browser.development.server.js | 22 +++++++++++++------ ...te-writer.browser.production.min.server.js | 6 ++--- ...dom-vite-writer.node.development.server.js | 19 ++++++++++------ ...-vite-writer.node.production.min.server.js | 4 ++-- .../cjs/react-server-dom-vite.development.js | 6 ++--- .../react-server-dom-vite.production.min.js | 4 ++-- .../esm/react-server-dom-vite-plugin.js | 3 ++- ...t-server-dom-vite-writer.browser.server.js | 22 +++++++++++++------ ...eact-server-dom-vite-writer.node.server.js | 19 ++++++++++------ .../esm/react-server-dom-vite.js | 6 ++--- 11 files changed, 71 insertions(+), 43 deletions(-) diff --git a/packages/hydrogen/vendor/react-server-dom-vite/cjs/react-server-dom-vite-plugin.js b/packages/hydrogen/vendor/react-server-dom-vite/cjs/react-server-dom-vite-plugin.js index 0409bd99b8..3099146eac 100644 --- a/packages/hydrogen/vendor/react-server-dom-vite/cjs/react-server-dom-vite-plugin.js +++ b/packages/hydrogen/vendor/react-server-dom-vite/cjs/react-server-dom-vite-plugin.js @@ -293,6 +293,7 @@ async function proxyClientComponent(filepath, src) { var DEFAULT_EXPORT = 'default'; // Modify the import ID to avoid infinite wraps var importFrom = filepath + "?no-proxy"; + await esModuleLexer.init; if (!src) { src = await fs.promises.readFile(filepath, 'utf-8'); @@ -430,7 +431,7 @@ function isDirectImportInServer(currentMod, originalMod) { } function resolveModPath(modPath, dirname, retryExtension) { - var absolutePath; + var absolutePath = ''; try { absolutePath = modPath.startsWith('.') ? vite.normalizePath(path.resolve(dirname, modPath)) : modPath; diff --git a/packages/hydrogen/vendor/react-server-dom-vite/cjs/react-server-dom-vite-writer.browser.development.server.js b/packages/hydrogen/vendor/react-server-dom-vite/cjs/react-server-dom-vite-writer.browser.development.server.js index 25b72f8702..01456ef732 100644 --- a/packages/hydrogen/vendor/react-server-dom-vite/cjs/react-server-dom-vite-writer.browser.development.server.js +++ b/packages/hydrogen/vendor/react-server-dom-vite/cjs/react-server-dom-vite-writer.browser.development.server.js @@ -1017,13 +1017,13 @@ function attemptResolveElement(type, key, ref, props) { throw new Error('Refs cannot be used in server components, nor passed to client components.'); } - if (type != null && isModuleReference(type)) { - // This is a reference to a client component. - return [REACT_ELEMENT_TYPE, type, key, props]; - } - if (typeof type === 'function') { - // This is a server-side component. + if (isModuleReference(type)) { + // This is a reference to a client component. + return [REACT_ELEMENT_TYPE, type, key, props]; + } // This is a server-side component. + + return type(props); } else if (typeof type === 'string') { // This is a host element. E.g. HTML. @@ -1041,6 +1041,11 @@ function attemptResolveElement(type, key, ref, props) { return [REACT_ELEMENT_TYPE, type, key, props]; } else if (type != null && typeof type === 'object') { + if (isModuleReference(type)) { + // This is a reference to a client component. + return [REACT_ELEMENT_TYPE, type, key, props]; + } + switch (type.$$typeof) { case REACT_LAZY_TYPE: { @@ -1445,7 +1450,7 @@ function resolveModelToJSON(request, parent, key, value) { // Verify that this is a simple plain object. if (objectName(value) !== 'Object') { error('Only plain objects can be passed to client components from server components. ' + 'Built-ins like %s are not supported. ' + 'Remove %s from these props: %s', objectName(value), describeKeyForErrorMessage(key), describeObjectForErrorMessage(parent)); - } else if (!isSimpleObject(value)) { + } else if (typeof value === 'object' && !isSimpleObject(value)) { error('Only plain objects can be passed to client components from server components. ' + 'Classes or other objects with methods are not supported. ' + 'Remove %s from these props: %s', describeKeyForErrorMessage(key), describeObjectForErrorMessage(parent, key)); } else if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(value); @@ -1754,6 +1759,9 @@ function renderToReadableStream(model, options, context) { startFlowing(request, controller); }, cancel: function (reason) {} + }, // $FlowFixMe size() methods are not allowed on byte streams. + { + highWaterMark: 0 }); return stream; } diff --git a/packages/hydrogen/vendor/react-server-dom-vite/cjs/react-server-dom-vite-writer.browser.production.min.server.js b/packages/hydrogen/vendor/react-server-dom-vite/cjs/react-server-dom-vite-writer.browser.production.min.server.js index 3b80bc391a..564928f7b8 100644 --- a/packages/hydrogen/vendor/react-server-dom-vite/cjs/react-server-dom-vite-writer.browser.production.min.server.js +++ b/packages/hydrogen/vendor/react-server-dom-vite/cjs/react-server-dom-vite-writer.browser.production.min.server.js @@ -28,8 +28,8 @@ function ja(a){return a._currentValue} var ma={useMemo:function(a){return a()},useCallback:function(a){return a},useDebugValue:function(){},useDeferredValue:N,useTransition:N,getCacheForType:function(a){if(!O)throw Error("Reading the cache is only supported while rendering.");var b=O.get(a);void 0===b&&(b=a(),O.set(a,b));return b},readContext:ja,useContext:ja,useReducer:N,useRef:N,useState:N,useInsertionEffect:N,useLayoutEffect:N,useImperativeHandle:N,useEffect:N,useId:N,useMutableSource:N,useSyncExternalStore:N,useCacheRefresh:function(){return la}}; function N(){throw Error("This Hook is not supported in Server Components.");}function la(){if(!O)throw Error("Refreshing the cache is not supported in Server Components.");}var O=null,na=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,S=na.ContextRegistry,T=na.ReactCurrentDispatcher;function oa(a){console.error(a)} function pa(a,b,d,c){var f=[],g={status:0,fatalError:null,destination:null,bundlerConfig:b,cache:new Map,nextChunkId:0,pendingChunks:0,pingedSegments:f,completedModuleChunks:[],completedJSONChunks:[],completedErrorChunks:[],writtenSymbols:new Map,writtenModules:new Map,writtenProviders:new Map,onError:void 0===d?oa:d,toJSON:function(a,b){return qa(g,this,a,b)}};g.pendingChunks++;b=ra(c);a=sa(g,a,b);f.push(a);return g}var ta={}; -function U(a,b,d,c){if(null!==d&&void 0!==d)throw Error("Refs cannot be used in server components, nor passed to client components.");if(null!=a&&x(a))return[y,a,b,c];if("function"===typeof a)return a(c);if("string"===typeof a)return[y,a,b,c];if("symbol"===typeof a)return a===ba?c.children:[y,a,b,c];if(null!=a&&"object"===typeof a)switch(a.$$typeof){case A:var f=a._init;a=f(a._payload);return U(a,b,d,c);case ca:return b=a.render,b(c,void 0);case da:return U(a.type,b,d,c);case z:return ia(a._context, -c.value),[y,a,b,{value:c.value,children:c.children,__pop:ta}]}throw Error("Unsupported server component type: "+V(a));}function sa(a,b,d){var c={id:a.nextChunkId++,model:b,context:d,ping:function(){var b=a.pingedSegments;b.push(c);1===b.length&&ua(a)}};return c}function va(a){return Object.prototype.toString.call(a).replace(/^\[object (.*)\]$/,function(a,d){return d})}function W(a){var b=JSON.stringify(a);return'"'+a+'"'===b?a:b} +function U(a,b,d,c){if(null!==d&&void 0!==d)throw Error("Refs cannot be used in server components, nor passed to client components.");if("function"===typeof a)return x(a)?[y,a,b,c]:a(c);if("string"===typeof a)return[y,a,b,c];if("symbol"===typeof a)return a===ba?c.children:[y,a,b,c];if(null!=a&&"object"===typeof a){if(x(a))return[y,a,b,c];switch(a.$$typeof){case A:var f=a._init;a=f(a._payload);return U(a,b,d,c);case ca:return b=a.render,b(c,void 0);case da:return U(a.type,b,d,c);case z:return ia(a._context, +c.value),[y,a,b,{value:c.value,children:c.children,__pop:ta}]}}throw Error("Unsupported server component type: "+V(a));}function sa(a,b,d){var c={id:a.nextChunkId++,model:b,context:d,ping:function(){var b=a.pingedSegments;b.push(c);1===b.length&&ua(a)}};return c}function va(a){return Object.prototype.toString.call(a).replace(/^\[object (.*)\]$/,function(a,d){return d})}function W(a){var b=JSON.stringify(a);return'"'+a+'"'===b?a:b} function V(a){switch(typeof a){case "string":return JSON.stringify(10>=a.length?a:a.substr(0,10)+"...");case "object":if(H(a))return"[...]";a=va(a);return"Object"===a?"{...}":a;case "function":return"function";default:return String(a)}} function X(a,b){if(H(a)){for(var d="[",c=0;c=a.length?a:a.substr(0,10)+"...");case "object":if(I(a))return"[...]";a=xa(a);return"Object"===a?"{...}":a;case "function":return"function";default:return String(a)}} function X(a,b){if(I(a)){for(var d="[",c=0;c