react-server-dom-webpack
Advanced tools
Comparing version 19.0.0-rc-49496d49-20240814 to 19.0.0-rc-4beb1fd8-20241118
@@ -17,6 +17,6 @@ /** | ||
var moduleExports = bundlerConfig[metadata[0]]; | ||
if ((bundlerConfig = moduleExports[metadata[2]])) | ||
if ((bundlerConfig = moduleExports && moduleExports[metadata[2]])) | ||
moduleExports = bundlerConfig.name; | ||
else { | ||
bundlerConfig = moduleExports["*"]; | ||
bundlerConfig = moduleExports && moduleExports["*"]; | ||
if (!bundlerConfig) | ||
@@ -26,3 +26,3 @@ throw Error( | ||
metadata[0] + | ||
'" in the React SSR Manifest. This is probably a bug in the React Server Components bundler.' | ||
'" in the React Server Consumer Manifest. This is probably a bug in the React Server Components bundler.' | ||
); | ||
@@ -37,2 +37,22 @@ moduleExports = metadata[2]; | ||
} | ||
function resolveServerReference(bundlerConfig, id) { | ||
var name = "", | ||
resolvedModuleData = bundlerConfig[id]; | ||
if (resolvedModuleData) name = resolvedModuleData.name; | ||
else { | ||
var idx = id.lastIndexOf("#"); | ||
-1 !== idx && | ||
((name = id.slice(idx + 1)), | ||
(resolvedModuleData = bundlerConfig[id.slice(0, idx)])); | ||
if (!resolvedModuleData) | ||
throw Error( | ||
'Could not find the module "' + | ||
id + | ||
'" in the React Server Manifest. This is probably a bug in the React Server Components bundler.' | ||
); | ||
} | ||
return resolvedModuleData.async | ||
? [resolvedModuleData.id, resolvedModuleData.chunks, name, 1] | ||
: [resolvedModuleData.id, resolvedModuleData.chunks, name]; | ||
} | ||
var chunkCache = new Map(); | ||
@@ -80,2 +100,16 @@ function requireAsyncModule(id) { | ||
} | ||
function requireModule(metadata) { | ||
var moduleExports = __webpack_require__(metadata[0]); | ||
if (4 === metadata.length && "function" === typeof moduleExports.then) | ||
if ("fulfilled" === moduleExports.status) | ||
moduleExports = moduleExports.value; | ||
else throw moduleExports.reason; | ||
return "*" === metadata[2] | ||
? moduleExports | ||
: "" === metadata[2] | ||
? moduleExports.__esModule | ||
? moduleExports.default | ||
: moduleExports | ||
: moduleExports[metadata[2]]; | ||
} | ||
var chunkMap = new Map(), | ||
@@ -464,8 +498,13 @@ webpackGetChunkFilename = __webpack_require__.u; | ||
writtenObjects = new WeakMap(), | ||
modelRoot = root; | ||
root = serializeModel(root, 0); | ||
modelRoot = root, | ||
json = serializeModel(root, 0); | ||
null === formData | ||
? resolve(root) | ||
: (formData.set(formFieldPrefix + "0", root), | ||
? resolve(json) | ||
: (formData.set(formFieldPrefix + "0", json), | ||
0 === pendingParts && resolve(formData)); | ||
return function () { | ||
0 < pendingParts && | ||
((pendingParts = 0), | ||
null === formData ? resolve(json) : resolve(formData)); | ||
}; | ||
} | ||
@@ -475,3 +514,19 @@ function registerServerReference(proxy, reference) { | ||
} | ||
function Chunk(status, value, reason, response) { | ||
function createBoundServerReference(metaData, callServer) { | ||
function action() { | ||
var args = Array.prototype.slice.call(arguments); | ||
return bound | ||
? "fulfilled" === bound.status | ||
? callServer(id, bound.value.concat(args)) | ||
: Promise.resolve(bound).then(function (boundArgs) { | ||
return callServer(id, boundArgs.concat(args)); | ||
}) | ||
: callServer(id, args); | ||
} | ||
var id = metaData.id, | ||
bound = metaData.bound; | ||
registerServerReference(action, { id: id, bound: bound }); | ||
return action; | ||
} | ||
function ReactPromise(status, value, reason, response) { | ||
this.status = status; | ||
@@ -482,4 +537,4 @@ this.value = value; | ||
} | ||
Chunk.prototype = Object.create(Promise.prototype); | ||
Chunk.prototype.then = function (resolve, reject) { | ||
ReactPromise.prototype = Object.create(Promise.prototype); | ||
ReactPromise.prototype.then = function (resolve, reject) { | ||
switch (this.status) { | ||
@@ -526,3 +581,3 @@ case "resolved_model": | ||
function createPendingChunk(response) { | ||
return new Chunk("pending", null, null, response); | ||
return new ReactPromise("pending", null, null, response); | ||
} | ||
@@ -568,3 +623,3 @@ function wakeChunk(listeners, value) { | ||
function createResolvedIteratorResultChunk(response, value, done) { | ||
return new Chunk( | ||
return new ReactPromise( | ||
"resolved_model", | ||
@@ -638,18 +693,5 @@ (done ? '{"done":true,"value":' : '{"done":false,"value":') + value + "}", | ||
try { | ||
var metadata = chunk.value, | ||
moduleExports = __webpack_require__(metadata[0]); | ||
if (4 === metadata.length && "function" === typeof moduleExports.then) | ||
if ("fulfilled" === moduleExports.status) | ||
moduleExports = moduleExports.value; | ||
else throw moduleExports.reason; | ||
var JSCompiler_inline_result = | ||
"*" === metadata[2] | ||
? moduleExports | ||
: "" === metadata[2] | ||
? moduleExports.__esModule | ||
? moduleExports.default | ||
: moduleExports | ||
: moduleExports[metadata[2]]; | ||
var value = requireModule(chunk.value); | ||
chunk.status = "fulfilled"; | ||
chunk.value = JSCompiler_inline_result; | ||
chunk.value = value; | ||
} catch (error) { | ||
@@ -694,11 +736,15 @@ (chunk.status = "rejected"), (chunk.reason = error); | ||
} | ||
parentObject[key] = map(response, value); | ||
"" === key && null === handler.value && (handler.value = parentObject[key]); | ||
parentObject[0] === REACT_ELEMENT_TYPE && | ||
"3" === key && | ||
i = map(response, value, parentObject, key); | ||
parentObject[key] = i; | ||
"" === key && null === handler.value && (handler.value = i); | ||
if ( | ||
parentObject[0] === REACT_ELEMENT_TYPE && | ||
"object" === typeof handler.value && | ||
null !== handler.value && | ||
handler.value.$$typeof === REACT_ELEMENT_TYPE && | ||
null === handler.value.props && | ||
(handler.value.props = parentObject[key]); | ||
handler.value.$$typeof === REACT_ELEMENT_TYPE | ||
) | ||
switch (((value = handler.value), key)) { | ||
case "3": | ||
value.props = i; | ||
} | ||
handler.deps--; | ||
@@ -738,17 +784,66 @@ 0 === handler.deps && | ||
} | ||
function createServerReferenceProxy(response, metaData) { | ||
function proxy() { | ||
var args = Array.prototype.slice.call(arguments), | ||
p = metaData.bound; | ||
return p | ||
? "fulfilled" === p.status | ||
? callServer(metaData.id, p.value.concat(args)) | ||
: Promise.resolve(p).then(function (bound) { | ||
return callServer(metaData.id, bound.concat(args)); | ||
}) | ||
: callServer(metaData.id, args); | ||
} | ||
var callServer = response._callServer; | ||
knownServerReferences.set(proxy, metaData); | ||
return proxy; | ||
function loadServerReference(response, metaData, parentObject, key) { | ||
if (!response._serverReferenceConfig) | ||
return createBoundServerReference(metaData, response._callServer); | ||
var serverReference = resolveServerReference( | ||
response._serverReferenceConfig, | ||
metaData.id | ||
); | ||
if ((response = preloadModule(serverReference))) | ||
metaData.bound && (response = Promise.all([response, metaData.bound])); | ||
else if (metaData.bound) response = Promise.resolve(metaData.bound); | ||
else return requireModule(serverReference); | ||
if (initializingHandler) { | ||
var handler = initializingHandler; | ||
handler.deps++; | ||
} else | ||
handler = initializingHandler = { | ||
parent: null, | ||
chunk: null, | ||
value: null, | ||
deps: 1, | ||
errored: !1 | ||
}; | ||
response.then( | ||
function () { | ||
var resolvedValue = requireModule(serverReference); | ||
if (metaData.bound) { | ||
var boundArgs = metaData.bound.value.slice(0); | ||
boundArgs.unshift(null); | ||
resolvedValue = resolvedValue.bind.apply(resolvedValue, boundArgs); | ||
} | ||
parentObject[key] = resolvedValue; | ||
"" === key && null === handler.value && (handler.value = resolvedValue); | ||
if ( | ||
parentObject[0] === REACT_ELEMENT_TYPE && | ||
"object" === typeof handler.value && | ||
null !== handler.value && | ||
handler.value.$$typeof === REACT_ELEMENT_TYPE | ||
) | ||
switch (((boundArgs = handler.value), key)) { | ||
case "3": | ||
boundArgs.props = resolvedValue; | ||
} | ||
handler.deps--; | ||
0 === handler.deps && | ||
((resolvedValue = handler.chunk), | ||
null !== resolvedValue && | ||
"blocked" === resolvedValue.status && | ||
((boundArgs = resolvedValue.value), | ||
(resolvedValue.status = "fulfilled"), | ||
(resolvedValue.value = handler.value), | ||
null !== boundArgs && wakeChunk(boundArgs, handler.value))); | ||
}, | ||
function (error) { | ||
if (!handler.errored) { | ||
handler.errored = !0; | ||
handler.value = error; | ||
var chunk = handler.chunk; | ||
null !== chunk && | ||
"blocked" === chunk.status && | ||
triggerErrorOnChunk(chunk, error); | ||
} | ||
} | ||
); | ||
return null; | ||
} | ||
@@ -769,6 +864,4 @@ function getOutlinedModel(response, reference, parentObject, key, map) { | ||
var value = id.value; | ||
for (id = 1; id < reference.length; id++) | ||
if ( | ||
((value = value[reference[id]]), value.$$typeof === REACT_LAZY_TYPE) | ||
) | ||
for (id = 1; id < reference.length; id++) { | ||
for (; value.$$typeof === REACT_LAZY_TYPE; ) | ||
if (((value = value._payload), "fulfilled" === value.status)) | ||
@@ -783,5 +876,7 @@ value = value.value; | ||
map, | ||
reference.slice(id) | ||
reference.slice(id - 1) | ||
); | ||
return map(response, value); | ||
value = value[reference[id]]; | ||
} | ||
return map(response, value, parentObject, key); | ||
case "pending": | ||
@@ -865,3 +960,3 @@ case "blocked": | ||
key, | ||
createServerReferenceProxy | ||
loadServerReference | ||
) | ||
@@ -897,2 +992,4 @@ ); | ||
); | ||
case "Z": | ||
return resolveErrorProd(); | ||
case "i": | ||
@@ -931,2 +1028,3 @@ return ( | ||
bundlerConfig, | ||
serverReferenceConfig, | ||
moduleLoading, | ||
@@ -940,2 +1038,3 @@ callServer, | ||
this._bundlerConfig = bundlerConfig; | ||
this._serverReferenceConfig = serverReferenceConfig; | ||
this._moduleLoading = moduleLoading; | ||
@@ -958,3 +1057,3 @@ this._callServer = void 0 !== callServer ? callServer : missingCall; | ||
? chunk.reason.enqueueValue(buffer) | ||
: chunks.set(id, new Chunk("fulfilled", buffer, null, response)); | ||
: chunks.set(id, new ReactPromise("fulfilled", buffer, null, response)); | ||
} | ||
@@ -971,3 +1070,3 @@ function resolveModule(response, id, model) { | ||
} else | ||
(blockedChunk = new Chunk("blocked", null, null, response)), | ||
(blockedChunk = new ReactPromise("blocked", null, null, response)), | ||
chunks.set(id, blockedChunk); | ||
@@ -987,3 +1086,3 @@ model.then( | ||
id, | ||
new Chunk("resolved_module", clientReference, null, response) | ||
new ReactPromise("resolved_module", clientReference, null, response) | ||
); | ||
@@ -1001,3 +1100,6 @@ } | ||
null !== response && wakeChunk(response, chunk.value)) | ||
: chunks.set(id, new Chunk("fulfilled", stream, controller, response)); | ||
: chunks.set( | ||
id, | ||
new ReactPromise("fulfilled", stream, controller, response) | ||
); | ||
} | ||
@@ -1023,3 +1125,3 @@ function startReadableStream(response, id, type) { | ||
if (null === previousBlockedChunk) { | ||
var chunk = new Chunk("resolved_model", json, null, response); | ||
var chunk = new ReactPromise("resolved_model", json, null, response); | ||
initializeModelChunk(chunk); | ||
@@ -1100,3 +1202,3 @@ "fulfilled" === chunk.status | ||
if (closed) | ||
return new Chunk( | ||
return new ReactPromise( | ||
"fulfilled", | ||
@@ -1120,3 +1222,3 @@ { done: !0, value: void 0 }, | ||
if (nextWriteIndex === buffer.length) | ||
buffer[nextWriteIndex] = new Chunk( | ||
buffer[nextWriteIndex] = new ReactPromise( | ||
"fulfilled", | ||
@@ -1177,2 +1279,9 @@ { done: !1, value: value }, | ||
} | ||
function resolveErrorProd() { | ||
var error = Error( | ||
"An error occurred in the Server Components render. The specific message is omitted in production builds to avoid leaking sensitive details. A digest property is included on this error instance which may provide additional details about the nature of the error." | ||
); | ||
error.stack = "Error: " + error.message; | ||
return error; | ||
} | ||
function mergeBuffer(buffer, lastChunk) { | ||
@@ -1313,12 +1422,9 @@ for (var l = buffer.length, byteLength = lastChunk.length, i = 0; i < l; i++) | ||
case 69: | ||
tag = JSON.parse(buffer).digest; | ||
buffer = Error( | ||
"An error occurred in the Server Components render. The specific message is omitted in production builds to avoid leaking sensitive details. A digest property is included on this error instance which may provide additional details about the nature of the error." | ||
); | ||
buffer.stack = "Error: " + buffer.message; | ||
buffer.digest = tag; | ||
tag = JSON.parse(buffer); | ||
buffer = resolveErrorProd(); | ||
buffer.digest = tag.digest; | ||
tag = response._chunks; | ||
(chunk = tag.get(id)) | ||
? triggerErrorOnChunk(chunk, buffer) | ||
: tag.set(id, new Chunk("rejected", null, buffer, response)); | ||
: tag.set(id, new ReactPromise("rejected", null, buffer, response)); | ||
break; | ||
@@ -1329,3 +1435,3 @@ case 84: | ||
? chunk.reason.enqueueValue(buffer) | ||
: tag.set(id, new Chunk("fulfilled", buffer, null, response)); | ||
: tag.set(id, new ReactPromise("fulfilled", buffer, null, response)); | ||
break; | ||
@@ -1358,3 +1464,6 @@ case 68: | ||
? resolveModelChunk(chunk, buffer) | ||
: tag.set(id, new Chunk("resolved_model", buffer, null, response)); | ||
: tag.set( | ||
id, | ||
new ReactPromise("resolved_model", buffer, null, response) | ||
); | ||
} | ||
@@ -1383,6 +1492,11 @@ } | ||
) | ||
(key = new Chunk("rejected", null, value.value, response)), | ||
(key = new ReactPromise("rejected", null, value.value, response)), | ||
(key = createLazyChunkWrapper(key)); | ||
else if (0 < value.deps) { | ||
var blockedChunk = new Chunk("blocked", null, null, response); | ||
var blockedChunk = new ReactPromise( | ||
"blocked", | ||
null, | ||
null, | ||
response | ||
); | ||
value.value = key; | ||
@@ -1402,2 +1516,3 @@ value.chunk = blockedChunk; | ||
null, | ||
null, | ||
options && options.callServer ? options.callServer : void 0, | ||
@@ -1454,2 +1569,3 @@ void 0, | ||
: (64 < rowState && 91 > rowState) || | ||
35 === rowState || | ||
114 === rowState || | ||
@@ -1520,8 +1636,8 @@ 120 === rowState | ||
exports.createServerReference = function (id, callServer) { | ||
function proxy() { | ||
function action() { | ||
var args = Array.prototype.slice.call(arguments); | ||
return callServer(id, args); | ||
} | ||
registerServerReference(proxy, { id: id, bound: null }); | ||
return proxy; | ||
registerServerReference(action, { id: id, bound: null }); | ||
return action; | ||
}; | ||
@@ -1533,3 +1649,3 @@ exports.createTemporaryReferenceSet = function () { | ||
return new Promise(function (resolve, reject) { | ||
processReply( | ||
var abort = processReply( | ||
value, | ||
@@ -1543,3 +1659,14 @@ "", | ||
); | ||
if (options && options.signal) { | ||
var signal = options.signal; | ||
if (signal.aborted) abort(signal.reason); | ||
else { | ||
var listener = function () { | ||
abort(signal.reason); | ||
signal.removeEventListener("abort", listener); | ||
}; | ||
signal.addEventListener("abort", listener); | ||
} | ||
} | ||
}); | ||
}; |
@@ -17,6 +17,6 @@ /** | ||
var moduleExports = bundlerConfig[metadata[0]]; | ||
if ((bundlerConfig = moduleExports[metadata[2]])) | ||
if ((bundlerConfig = moduleExports && moduleExports[metadata[2]])) | ||
moduleExports = bundlerConfig.name; | ||
else { | ||
bundlerConfig = moduleExports["*"]; | ||
bundlerConfig = moduleExports && moduleExports["*"]; | ||
if (!bundlerConfig) | ||
@@ -26,3 +26,3 @@ throw Error( | ||
metadata[0] + | ||
'" in the React SSR Manifest. This is probably a bug in the React Server Components bundler.' | ||
'" in the React Server Consumer Manifest. This is probably a bug in the React Server Components bundler.' | ||
); | ||
@@ -37,2 +37,22 @@ moduleExports = metadata[2]; | ||
} | ||
function resolveServerReference(bundlerConfig, id) { | ||
var name = "", | ||
resolvedModuleData = bundlerConfig[id]; | ||
if (resolvedModuleData) name = resolvedModuleData.name; | ||
else { | ||
var idx = id.lastIndexOf("#"); | ||
-1 !== idx && | ||
((name = id.slice(idx + 1)), | ||
(resolvedModuleData = bundlerConfig[id.slice(0, idx)])); | ||
if (!resolvedModuleData) | ||
throw Error( | ||
'Could not find the module "' + | ||
id + | ||
'" in the React Server Manifest. This is probably a bug in the React Server Components bundler.' | ||
); | ||
} | ||
return resolvedModuleData.async | ||
? [resolvedModuleData.id, resolvedModuleData.chunks, name, 1] | ||
: [resolvedModuleData.id, resolvedModuleData.chunks, name]; | ||
} | ||
var chunkCache = new Map(); | ||
@@ -79,2 +99,16 @@ function requireAsyncModule(id) { | ||
} | ||
function requireModule(metadata) { | ||
var moduleExports = __webpack_require__(metadata[0]); | ||
if (4 === metadata.length && "function" === typeof moduleExports.then) | ||
if ("fulfilled" === moduleExports.status) | ||
moduleExports = moduleExports.value; | ||
else throw moduleExports.reason; | ||
return "*" === metadata[2] | ||
? moduleExports | ||
: "" === metadata[2] | ||
? moduleExports.__esModule | ||
? moduleExports.default | ||
: moduleExports | ||
: moduleExports[metadata[2]]; | ||
} | ||
function prepareDestinationWithChunks(moduleLoading, chunks, nonce$jscomp$0) { | ||
@@ -476,8 +510,13 @@ if (null !== moduleLoading) | ||
writtenObjects = new WeakMap(), | ||
modelRoot = root; | ||
root = serializeModel(root, 0); | ||
modelRoot = root, | ||
json = serializeModel(root, 0); | ||
null === formData | ||
? resolve(root) | ||
: (formData.set(formFieldPrefix + "0", root), | ||
? resolve(json) | ||
: (formData.set(formFieldPrefix + "0", json), | ||
0 === pendingParts && resolve(formData)); | ||
return function () { | ||
0 < pendingParts && | ||
((pendingParts = 0), | ||
null === formData ? resolve(json) : resolve(formData)); | ||
}; | ||
} | ||
@@ -621,11 +660,27 @@ var boundCache = new WeakMap(); | ||
} | ||
function createBoundServerReference(metaData, callServer, encodeFormAction) { | ||
function action() { | ||
var args = Array.prototype.slice.call(arguments); | ||
return bound | ||
? "fulfilled" === bound.status | ||
? callServer(id, bound.value.concat(args)) | ||
: Promise.resolve(bound).then(function (boundArgs) { | ||
return callServer(id, boundArgs.concat(args)); | ||
}) | ||
: callServer(id, args); | ||
} | ||
var id = metaData.id, | ||
bound = metaData.bound; | ||
registerServerReference(action, { id: id, bound: bound }, encodeFormAction); | ||
return action; | ||
} | ||
function createServerReference$1(id, callServer, encodeFormAction) { | ||
function proxy() { | ||
function action() { | ||
var args = Array.prototype.slice.call(arguments); | ||
return callServer(id, args); | ||
} | ||
registerServerReference(proxy, { id: id, bound: null }, encodeFormAction); | ||
return proxy; | ||
registerServerReference(action, { id: id, bound: null }, encodeFormAction); | ||
return action; | ||
} | ||
function Chunk(status, value, reason, response) { | ||
function ReactPromise(status, value, reason, response) { | ||
this.status = status; | ||
@@ -636,4 +691,4 @@ this.value = value; | ||
} | ||
Chunk.prototype = Object.create(Promise.prototype); | ||
Chunk.prototype.then = function (resolve, reject) { | ||
ReactPromise.prototype = Object.create(Promise.prototype); | ||
ReactPromise.prototype.then = function (resolve, reject) { | ||
switch (this.status) { | ||
@@ -680,3 +735,3 @@ case "resolved_model": | ||
function createPendingChunk(response) { | ||
return new Chunk("pending", null, null, response); | ||
return new ReactPromise("pending", null, null, response); | ||
} | ||
@@ -722,3 +777,3 @@ function wakeChunk(listeners, value) { | ||
function createResolvedIteratorResultChunk(response, value, done) { | ||
return new Chunk( | ||
return new ReactPromise( | ||
"resolved_model", | ||
@@ -792,18 +847,5 @@ (done ? '{"done":true,"value":' : '{"done":false,"value":') + value + "}", | ||
try { | ||
var metadata = chunk.value, | ||
moduleExports = __webpack_require__(metadata[0]); | ||
if (4 === metadata.length && "function" === typeof moduleExports.then) | ||
if ("fulfilled" === moduleExports.status) | ||
moduleExports = moduleExports.value; | ||
else throw moduleExports.reason; | ||
var JSCompiler_inline_result = | ||
"*" === metadata[2] | ||
? moduleExports | ||
: "" === metadata[2] | ||
? moduleExports.__esModule | ||
? moduleExports.default | ||
: moduleExports | ||
: moduleExports[metadata[2]]; | ||
var value = requireModule(chunk.value); | ||
chunk.status = "fulfilled"; | ||
chunk.value = JSCompiler_inline_result; | ||
chunk.value = value; | ||
} catch (error) { | ||
@@ -848,11 +890,15 @@ (chunk.status = "rejected"), (chunk.reason = error); | ||
} | ||
parentObject[key] = map(response, value); | ||
"" === key && null === handler.value && (handler.value = parentObject[key]); | ||
parentObject[0] === REACT_ELEMENT_TYPE && | ||
"3" === key && | ||
i = map(response, value, parentObject, key); | ||
parentObject[key] = i; | ||
"" === key && null === handler.value && (handler.value = i); | ||
if ( | ||
parentObject[0] === REACT_ELEMENT_TYPE && | ||
"object" === typeof handler.value && | ||
null !== handler.value && | ||
handler.value.$$typeof === REACT_ELEMENT_TYPE && | ||
null === handler.value.props && | ||
(handler.value.props = parentObject[key]); | ||
handler.value.$$typeof === REACT_ELEMENT_TYPE | ||
) | ||
switch (((value = handler.value), key)) { | ||
case "3": | ||
value.props = i; | ||
} | ||
handler.deps--; | ||
@@ -892,17 +938,70 @@ 0 === handler.deps && | ||
} | ||
function createServerReferenceProxy(response, metaData) { | ||
function proxy() { | ||
var args = Array.prototype.slice.call(arguments), | ||
p = metaData.bound; | ||
return p | ||
? "fulfilled" === p.status | ||
? callServer(metaData.id, p.value.concat(args)) | ||
: Promise.resolve(p).then(function (bound) { | ||
return callServer(metaData.id, bound.concat(args)); | ||
}) | ||
: callServer(metaData.id, args); | ||
} | ||
var callServer = response._callServer; | ||
registerServerReference(proxy, metaData, response._encodeFormAction); | ||
return proxy; | ||
function loadServerReference(response, metaData, parentObject, key) { | ||
if (!response._serverReferenceConfig) | ||
return createBoundServerReference( | ||
metaData, | ||
response._callServer, | ||
response._encodeFormAction | ||
); | ||
var serverReference = resolveServerReference( | ||
response._serverReferenceConfig, | ||
metaData.id | ||
); | ||
if ((response = preloadModule(serverReference))) | ||
metaData.bound && (response = Promise.all([response, metaData.bound])); | ||
else if (metaData.bound) response = Promise.resolve(metaData.bound); | ||
else return requireModule(serverReference); | ||
if (initializingHandler) { | ||
var handler = initializingHandler; | ||
handler.deps++; | ||
} else | ||
handler = initializingHandler = { | ||
parent: null, | ||
chunk: null, | ||
value: null, | ||
deps: 1, | ||
errored: !1 | ||
}; | ||
response.then( | ||
function () { | ||
var resolvedValue = requireModule(serverReference); | ||
if (metaData.bound) { | ||
var boundArgs = metaData.bound.value.slice(0); | ||
boundArgs.unshift(null); | ||
resolvedValue = resolvedValue.bind.apply(resolvedValue, boundArgs); | ||
} | ||
parentObject[key] = resolvedValue; | ||
"" === key && null === handler.value && (handler.value = resolvedValue); | ||
if ( | ||
parentObject[0] === REACT_ELEMENT_TYPE && | ||
"object" === typeof handler.value && | ||
null !== handler.value && | ||
handler.value.$$typeof === REACT_ELEMENT_TYPE | ||
) | ||
switch (((boundArgs = handler.value), key)) { | ||
case "3": | ||
boundArgs.props = resolvedValue; | ||
} | ||
handler.deps--; | ||
0 === handler.deps && | ||
((resolvedValue = handler.chunk), | ||
null !== resolvedValue && | ||
"blocked" === resolvedValue.status && | ||
((boundArgs = resolvedValue.value), | ||
(resolvedValue.status = "fulfilled"), | ||
(resolvedValue.value = handler.value), | ||
null !== boundArgs && wakeChunk(boundArgs, handler.value))); | ||
}, | ||
function (error) { | ||
if (!handler.errored) { | ||
handler.errored = !0; | ||
handler.value = error; | ||
var chunk = handler.chunk; | ||
null !== chunk && | ||
"blocked" === chunk.status && | ||
triggerErrorOnChunk(chunk, error); | ||
} | ||
} | ||
); | ||
return null; | ||
} | ||
@@ -923,6 +1022,4 @@ function getOutlinedModel(response, reference, parentObject, key, map) { | ||
var value = id.value; | ||
for (id = 1; id < reference.length; id++) | ||
if ( | ||
((value = value[reference[id]]), value.$$typeof === REACT_LAZY_TYPE) | ||
) | ||
for (id = 1; id < reference.length; id++) { | ||
for (; value.$$typeof === REACT_LAZY_TYPE; ) | ||
if (((value = value._payload), "fulfilled" === value.status)) | ||
@@ -937,5 +1034,7 @@ value = value.value; | ||
map, | ||
reference.slice(id) | ||
reference.slice(id - 1) | ||
); | ||
return map(response, value); | ||
value = value[reference[id]]; | ||
} | ||
return map(response, value, parentObject, key); | ||
case "pending": | ||
@@ -1019,3 +1118,3 @@ case "blocked": | ||
key, | ||
createServerReferenceProxy | ||
loadServerReference | ||
) | ||
@@ -1051,2 +1150,4 @@ ); | ||
); | ||
case "Z": | ||
return resolveErrorProd(); | ||
case "i": | ||
@@ -1085,2 +1186,3 @@ return ( | ||
bundlerConfig, | ||
serverReferenceConfig, | ||
moduleLoading, | ||
@@ -1094,2 +1196,3 @@ callServer, | ||
this._bundlerConfig = bundlerConfig; | ||
this._serverReferenceConfig = serverReferenceConfig; | ||
this._moduleLoading = moduleLoading; | ||
@@ -1112,3 +1215,3 @@ this._callServer = void 0 !== callServer ? callServer : missingCall; | ||
? chunk.reason.enqueueValue(buffer) | ||
: chunks.set(id, new Chunk("fulfilled", buffer, null, response)); | ||
: chunks.set(id, new ReactPromise("fulfilled", buffer, null, response)); | ||
} | ||
@@ -1130,3 +1233,3 @@ function resolveModule(response, id, model) { | ||
} else | ||
(blockedChunk = new Chunk("blocked", null, null, response)), | ||
(blockedChunk = new ReactPromise("blocked", null, null, response)), | ||
chunks.set(id, blockedChunk); | ||
@@ -1146,3 +1249,3 @@ model.then( | ||
id, | ||
new Chunk("resolved_module", clientReference, null, response) | ||
new ReactPromise("resolved_module", clientReference, null, response) | ||
); | ||
@@ -1160,3 +1263,6 @@ } | ||
null !== response && wakeChunk(response, chunk.value)) | ||
: chunks.set(id, new Chunk("fulfilled", stream, controller, response)); | ||
: chunks.set( | ||
id, | ||
new ReactPromise("fulfilled", stream, controller, response) | ||
); | ||
} | ||
@@ -1182,3 +1288,3 @@ function startReadableStream(response, id, type) { | ||
if (null === previousBlockedChunk) { | ||
var chunk = new Chunk("resolved_model", json, null, response); | ||
var chunk = new ReactPromise("resolved_model", json, null, response); | ||
initializeModelChunk(chunk); | ||
@@ -1259,3 +1365,3 @@ "fulfilled" === chunk.status | ||
if (closed) | ||
return new Chunk( | ||
return new ReactPromise( | ||
"fulfilled", | ||
@@ -1279,3 +1385,3 @@ { done: !0, value: void 0 }, | ||
if (nextWriteIndex === buffer.length) | ||
buffer[nextWriteIndex] = new Chunk( | ||
buffer[nextWriteIndex] = new ReactPromise( | ||
"fulfilled", | ||
@@ -1336,2 +1442,9 @@ { done: !1, value: value }, | ||
} | ||
function resolveErrorProd() { | ||
var error = Error( | ||
"An error occurred in the Server Components render. The specific message is omitted in production builds to avoid leaking sensitive details. A digest property is included on this error instance which may provide additional details about the nature of the error." | ||
); | ||
error.stack = "Error: " + error.message; | ||
return error; | ||
} | ||
function mergeBuffer(buffer, lastChunk) { | ||
@@ -1472,12 +1585,9 @@ for (var l = buffer.length, byteLength = lastChunk.length, i = 0; i < l; i++) | ||
case 69: | ||
tag = JSON.parse(buffer).digest; | ||
buffer = Error( | ||
"An error occurred in the Server Components render. The specific message is omitted in production builds to avoid leaking sensitive details. A digest property is included on this error instance which may provide additional details about the nature of the error." | ||
); | ||
buffer.stack = "Error: " + buffer.message; | ||
buffer.digest = tag; | ||
tag = JSON.parse(buffer); | ||
buffer = resolveErrorProd(); | ||
buffer.digest = tag.digest; | ||
tag = response._chunks; | ||
(chunk = tag.get(id)) | ||
? triggerErrorOnChunk(chunk, buffer) | ||
: tag.set(id, new Chunk("rejected", null, buffer, response)); | ||
: tag.set(id, new ReactPromise("rejected", null, buffer, response)); | ||
break; | ||
@@ -1488,3 +1598,3 @@ case 84: | ||
? chunk.reason.enqueueValue(buffer) | ||
: tag.set(id, new Chunk("fulfilled", buffer, null, response)); | ||
: tag.set(id, new ReactPromise("fulfilled", buffer, null, response)); | ||
break; | ||
@@ -1517,3 +1627,6 @@ case 68: | ||
? resolveModelChunk(chunk, buffer) | ||
: tag.set(id, new Chunk("resolved_model", buffer, null, response)); | ||
: tag.set( | ||
id, | ||
new ReactPromise("resolved_model", buffer, null, response) | ||
); | ||
} | ||
@@ -1542,6 +1655,11 @@ } | ||
) | ||
(key = new Chunk("rejected", null, value.value, response)), | ||
(key = new ReactPromise("rejected", null, value.value, response)), | ||
(key = createLazyChunkWrapper(key)); | ||
else if (0 < value.deps) { | ||
var blockedChunk = new Chunk("blocked", null, null, response); | ||
var blockedChunk = new ReactPromise( | ||
"blocked", | ||
null, | ||
null, | ||
response | ||
); | ||
value.value = key; | ||
@@ -1564,4 +1682,5 @@ value.chunk = blockedChunk; | ||
return new ResponseInstance( | ||
options.ssrManifest.moduleMap, | ||
options.ssrManifest.moduleLoading, | ||
options.serverConsumerManifest.moduleMap, | ||
options.serverConsumerManifest.serverModuleMap, | ||
options.serverConsumerManifest.moduleLoading, | ||
noServerCall, | ||
@@ -1618,2 +1737,3 @@ options.encodeFormAction, | ||
: (64 < rowState && 91 > rowState) || | ||
35 === rowState || | ||
114 === rowState || | ||
@@ -1691,3 +1811,3 @@ 120 === rowState | ||
return new Promise(function (resolve, reject) { | ||
processReply( | ||
var abort = processReply( | ||
value, | ||
@@ -1701,3 +1821,14 @@ "", | ||
); | ||
if (options && options.signal) { | ||
var signal = options.signal; | ||
if (signal.aborted) abort(signal.reason); | ||
else { | ||
var listener = function () { | ||
abort(signal.reason); | ||
signal.removeEventListener("abort", listener); | ||
}; | ||
signal.addEventListener("abort", listener); | ||
} | ||
} | ||
}); | ||
}; |
@@ -18,6 +18,6 @@ /** | ||
var moduleExports = bundlerConfig[metadata[0]]; | ||
if ((bundlerConfig = moduleExports[metadata[2]])) | ||
if ((bundlerConfig = moduleExports && moduleExports[metadata[2]])) | ||
moduleExports = bundlerConfig.name; | ||
else { | ||
bundlerConfig = moduleExports["*"]; | ||
bundlerConfig = moduleExports && moduleExports["*"]; | ||
if (!bundlerConfig) | ||
@@ -27,3 +27,3 @@ throw Error( | ||
metadata[0] + | ||
'" in the React SSR Manifest. This is probably a bug in the React Server Components bundler.' | ||
'" in the React Server Consumer Manifest. This is probably a bug in the React Server Components bundler.' | ||
); | ||
@@ -38,2 +38,22 @@ moduleExports = metadata[2]; | ||
} | ||
function resolveServerReference(bundlerConfig, id) { | ||
var name = "", | ||
resolvedModuleData = bundlerConfig[id]; | ||
if (resolvedModuleData) name = resolvedModuleData.name; | ||
else { | ||
var idx = id.lastIndexOf("#"); | ||
-1 !== idx && | ||
((name = id.slice(idx + 1)), | ||
(resolvedModuleData = bundlerConfig[id.slice(0, idx)])); | ||
if (!resolvedModuleData) | ||
throw Error( | ||
'Could not find the module "' + | ||
id + | ||
'" in the React Server Manifest. This is probably a bug in the React Server Components bundler.' | ||
); | ||
} | ||
return resolvedModuleData.async | ||
? [resolvedModuleData.id, resolvedModuleData.chunks, name, 1] | ||
: [resolvedModuleData.id, resolvedModuleData.chunks, name]; | ||
} | ||
var chunkCache = new Map(); | ||
@@ -80,2 +100,16 @@ function requireAsyncModule(id) { | ||
} | ||
function requireModule(metadata) { | ||
var moduleExports = __webpack_require__(metadata[0]); | ||
if (4 === metadata.length && "function" === typeof moduleExports.then) | ||
if ("fulfilled" === moduleExports.status) | ||
moduleExports = moduleExports.value; | ||
else throw moduleExports.reason; | ||
return "*" === metadata[2] | ||
? moduleExports | ||
: "" === metadata[2] | ||
? moduleExports.__esModule | ||
? moduleExports.default | ||
: moduleExports | ||
: moduleExports[metadata[2]]; | ||
} | ||
function prepareDestinationWithChunks(moduleLoading, chunks, nonce$jscomp$0) { | ||
@@ -477,8 +511,13 @@ if (null !== moduleLoading) | ||
writtenObjects = new WeakMap(), | ||
modelRoot = root; | ||
root = serializeModel(root, 0); | ||
modelRoot = root, | ||
json = serializeModel(root, 0); | ||
null === formData | ||
? resolve(root) | ||
: (formData.set(formFieldPrefix + "0", root), | ||
? resolve(json) | ||
: (formData.set(formFieldPrefix + "0", json), | ||
0 === pendingParts && resolve(formData)); | ||
return function () { | ||
0 < pendingParts && | ||
((pendingParts = 0), | ||
null === formData ? resolve(json) : resolve(formData)); | ||
}; | ||
} | ||
@@ -622,11 +661,27 @@ var boundCache = new WeakMap(); | ||
} | ||
function createBoundServerReference(metaData, callServer, encodeFormAction) { | ||
function action() { | ||
var args = Array.prototype.slice.call(arguments); | ||
return bound | ||
? "fulfilled" === bound.status | ||
? callServer(id, bound.value.concat(args)) | ||
: Promise.resolve(bound).then(function (boundArgs) { | ||
return callServer(id, boundArgs.concat(args)); | ||
}) | ||
: callServer(id, args); | ||
} | ||
var id = metaData.id, | ||
bound = metaData.bound; | ||
registerServerReference(action, { id: id, bound: bound }, encodeFormAction); | ||
return action; | ||
} | ||
function createServerReference$1(id, callServer, encodeFormAction) { | ||
function proxy() { | ||
function action() { | ||
var args = Array.prototype.slice.call(arguments); | ||
return callServer(id, args); | ||
} | ||
registerServerReference(proxy, { id: id, bound: null }, encodeFormAction); | ||
return proxy; | ||
registerServerReference(action, { id: id, bound: null }, encodeFormAction); | ||
return action; | ||
} | ||
function Chunk(status, value, reason, response) { | ||
function ReactPromise(status, value, reason, response) { | ||
this.status = status; | ||
@@ -637,4 +692,4 @@ this.value = value; | ||
} | ||
Chunk.prototype = Object.create(Promise.prototype); | ||
Chunk.prototype.then = function (resolve, reject) { | ||
ReactPromise.prototype = Object.create(Promise.prototype); | ||
ReactPromise.prototype.then = function (resolve, reject) { | ||
switch (this.status) { | ||
@@ -681,3 +736,3 @@ case "resolved_model": | ||
function createPendingChunk(response) { | ||
return new Chunk("pending", null, null, response); | ||
return new ReactPromise("pending", null, null, response); | ||
} | ||
@@ -723,3 +778,3 @@ function wakeChunk(listeners, value) { | ||
function createResolvedIteratorResultChunk(response, value, done) { | ||
return new Chunk( | ||
return new ReactPromise( | ||
"resolved_model", | ||
@@ -793,18 +848,5 @@ (done ? '{"done":true,"value":' : '{"done":false,"value":') + value + "}", | ||
try { | ||
var metadata = chunk.value, | ||
moduleExports = __webpack_require__(metadata[0]); | ||
if (4 === metadata.length && "function" === typeof moduleExports.then) | ||
if ("fulfilled" === moduleExports.status) | ||
moduleExports = moduleExports.value; | ||
else throw moduleExports.reason; | ||
var JSCompiler_inline_result = | ||
"*" === metadata[2] | ||
? moduleExports | ||
: "" === metadata[2] | ||
? moduleExports.__esModule | ||
? moduleExports.default | ||
: moduleExports | ||
: moduleExports[metadata[2]]; | ||
var value = requireModule(chunk.value); | ||
chunk.status = "fulfilled"; | ||
chunk.value = JSCompiler_inline_result; | ||
chunk.value = value; | ||
} catch (error) { | ||
@@ -849,11 +891,15 @@ (chunk.status = "rejected"), (chunk.reason = error); | ||
} | ||
parentObject[key] = map(response, value); | ||
"" === key && null === handler.value && (handler.value = parentObject[key]); | ||
parentObject[0] === REACT_ELEMENT_TYPE && | ||
"3" === key && | ||
i = map(response, value, parentObject, key); | ||
parentObject[key] = i; | ||
"" === key && null === handler.value && (handler.value = i); | ||
if ( | ||
parentObject[0] === REACT_ELEMENT_TYPE && | ||
"object" === typeof handler.value && | ||
null !== handler.value && | ||
handler.value.$$typeof === REACT_ELEMENT_TYPE && | ||
null === handler.value.props && | ||
(handler.value.props = parentObject[key]); | ||
handler.value.$$typeof === REACT_ELEMENT_TYPE | ||
) | ||
switch (((value = handler.value), key)) { | ||
case "3": | ||
value.props = i; | ||
} | ||
handler.deps--; | ||
@@ -893,17 +939,70 @@ 0 === handler.deps && | ||
} | ||
function createServerReferenceProxy(response, metaData) { | ||
function proxy() { | ||
var args = Array.prototype.slice.call(arguments), | ||
p = metaData.bound; | ||
return p | ||
? "fulfilled" === p.status | ||
? callServer(metaData.id, p.value.concat(args)) | ||
: Promise.resolve(p).then(function (bound) { | ||
return callServer(metaData.id, bound.concat(args)); | ||
}) | ||
: callServer(metaData.id, args); | ||
} | ||
var callServer = response._callServer; | ||
registerServerReference(proxy, metaData, response._encodeFormAction); | ||
return proxy; | ||
function loadServerReference(response, metaData, parentObject, key) { | ||
if (!response._serverReferenceConfig) | ||
return createBoundServerReference( | ||
metaData, | ||
response._callServer, | ||
response._encodeFormAction | ||
); | ||
var serverReference = resolveServerReference( | ||
response._serverReferenceConfig, | ||
metaData.id | ||
); | ||
if ((response = preloadModule(serverReference))) | ||
metaData.bound && (response = Promise.all([response, metaData.bound])); | ||
else if (metaData.bound) response = Promise.resolve(metaData.bound); | ||
else return requireModule(serverReference); | ||
if (initializingHandler) { | ||
var handler = initializingHandler; | ||
handler.deps++; | ||
} else | ||
handler = initializingHandler = { | ||
parent: null, | ||
chunk: null, | ||
value: null, | ||
deps: 1, | ||
errored: !1 | ||
}; | ||
response.then( | ||
function () { | ||
var resolvedValue = requireModule(serverReference); | ||
if (metaData.bound) { | ||
var boundArgs = metaData.bound.value.slice(0); | ||
boundArgs.unshift(null); | ||
resolvedValue = resolvedValue.bind.apply(resolvedValue, boundArgs); | ||
} | ||
parentObject[key] = resolvedValue; | ||
"" === key && null === handler.value && (handler.value = resolvedValue); | ||
if ( | ||
parentObject[0] === REACT_ELEMENT_TYPE && | ||
"object" === typeof handler.value && | ||
null !== handler.value && | ||
handler.value.$$typeof === REACT_ELEMENT_TYPE | ||
) | ||
switch (((boundArgs = handler.value), key)) { | ||
case "3": | ||
boundArgs.props = resolvedValue; | ||
} | ||
handler.deps--; | ||
0 === handler.deps && | ||
((resolvedValue = handler.chunk), | ||
null !== resolvedValue && | ||
"blocked" === resolvedValue.status && | ||
((boundArgs = resolvedValue.value), | ||
(resolvedValue.status = "fulfilled"), | ||
(resolvedValue.value = handler.value), | ||
null !== boundArgs && wakeChunk(boundArgs, handler.value))); | ||
}, | ||
function (error) { | ||
if (!handler.errored) { | ||
handler.errored = !0; | ||
handler.value = error; | ||
var chunk = handler.chunk; | ||
null !== chunk && | ||
"blocked" === chunk.status && | ||
triggerErrorOnChunk(chunk, error); | ||
} | ||
} | ||
); | ||
return null; | ||
} | ||
@@ -924,6 +1023,4 @@ function getOutlinedModel(response, reference, parentObject, key, map) { | ||
var value = id.value; | ||
for (id = 1; id < reference.length; id++) | ||
if ( | ||
((value = value[reference[id]]), value.$$typeof === REACT_LAZY_TYPE) | ||
) | ||
for (id = 1; id < reference.length; id++) { | ||
for (; value.$$typeof === REACT_LAZY_TYPE; ) | ||
if (((value = value._payload), "fulfilled" === value.status)) | ||
@@ -938,5 +1035,7 @@ value = value.value; | ||
map, | ||
reference.slice(id) | ||
reference.slice(id - 1) | ||
); | ||
return map(response, value); | ||
value = value[reference[id]]; | ||
} | ||
return map(response, value, parentObject, key); | ||
case "pending": | ||
@@ -1020,3 +1119,3 @@ case "blocked": | ||
key, | ||
createServerReferenceProxy | ||
loadServerReference | ||
) | ||
@@ -1052,2 +1151,4 @@ ); | ||
); | ||
case "Z": | ||
return resolveErrorProd(); | ||
case "i": | ||
@@ -1086,2 +1187,3 @@ return ( | ||
bundlerConfig, | ||
serverReferenceConfig, | ||
moduleLoading, | ||
@@ -1095,2 +1197,3 @@ callServer, | ||
this._bundlerConfig = bundlerConfig; | ||
this._serverReferenceConfig = serverReferenceConfig; | ||
this._moduleLoading = moduleLoading; | ||
@@ -1113,3 +1216,3 @@ this._callServer = void 0 !== callServer ? callServer : missingCall; | ||
? chunk.reason.enqueueValue(buffer) | ||
: chunks.set(id, new Chunk("fulfilled", buffer, null, response)); | ||
: chunks.set(id, new ReactPromise("fulfilled", buffer, null, response)); | ||
} | ||
@@ -1131,3 +1234,3 @@ function resolveModule(response, id, model) { | ||
} else | ||
(blockedChunk = new Chunk("blocked", null, null, response)), | ||
(blockedChunk = new ReactPromise("blocked", null, null, response)), | ||
chunks.set(id, blockedChunk); | ||
@@ -1147,3 +1250,3 @@ model.then( | ||
id, | ||
new Chunk("resolved_module", clientReference, null, response) | ||
new ReactPromise("resolved_module", clientReference, null, response) | ||
); | ||
@@ -1161,3 +1264,6 @@ } | ||
null !== response && wakeChunk(response, chunk.value)) | ||
: chunks.set(id, new Chunk("fulfilled", stream, controller, response)); | ||
: chunks.set( | ||
id, | ||
new ReactPromise("fulfilled", stream, controller, response) | ||
); | ||
} | ||
@@ -1183,3 +1289,3 @@ function startReadableStream(response, id, type) { | ||
if (null === previousBlockedChunk) { | ||
var chunk = new Chunk("resolved_model", json, null, response); | ||
var chunk = new ReactPromise("resolved_model", json, null, response); | ||
initializeModelChunk(chunk); | ||
@@ -1260,3 +1366,3 @@ "fulfilled" === chunk.status | ||
if (closed) | ||
return new Chunk( | ||
return new ReactPromise( | ||
"fulfilled", | ||
@@ -1280,3 +1386,3 @@ { done: !0, value: void 0 }, | ||
if (nextWriteIndex === buffer.length) | ||
buffer[nextWriteIndex] = new Chunk( | ||
buffer[nextWriteIndex] = new ReactPromise( | ||
"fulfilled", | ||
@@ -1337,2 +1443,9 @@ { done: !1, value: value }, | ||
} | ||
function resolveErrorProd() { | ||
var error = Error( | ||
"An error occurred in the Server Components render. The specific message is omitted in production builds to avoid leaking sensitive details. A digest property is included on this error instance which may provide additional details about the nature of the error." | ||
); | ||
error.stack = "Error: " + error.message; | ||
return error; | ||
} | ||
function mergeBuffer(buffer, lastChunk) { | ||
@@ -1474,8 +1587,5 @@ for (var l = buffer.length, byteLength = lastChunk.length, i = 0; i < l; i++) | ||
case 69: | ||
tag = JSON.parse(row).digest; | ||
row = Error( | ||
"An error occurred in the Server Components render. The specific message is omitted in production builds to avoid leaking sensitive details. A digest property is included on this error instance which may provide additional details about the nature of the error." | ||
); | ||
row.stack = "Error: " + row.message; | ||
row.digest = tag; | ||
tag = JSON.parse(row); | ||
row = resolveErrorProd(); | ||
row.digest = tag.digest; | ||
tag = response._chunks; | ||
@@ -1485,3 +1595,3 @@ var chunk = tag.get(id); | ||
? triggerErrorOnChunk(chunk, row) | ||
: tag.set(id, new Chunk("rejected", null, row, response)); | ||
: tag.set(id, new ReactPromise("rejected", null, row, response)); | ||
break; | ||
@@ -1492,3 +1602,3 @@ case 84: | ||
? chunk.reason.enqueueValue(row) | ||
: tag.set(id, new Chunk("fulfilled", row, null, response)); | ||
: tag.set(id, new ReactPromise("fulfilled", row, null, response)); | ||
break; | ||
@@ -1521,3 +1631,6 @@ case 68: | ||
? resolveModelChunk(chunk, row) | ||
: tag.set(id, new Chunk("resolved_model", row, null, response)); | ||
: tag.set( | ||
id, | ||
new ReactPromise("resolved_model", row, null, response) | ||
); | ||
} | ||
@@ -1546,6 +1659,11 @@ } | ||
) | ||
(key = new Chunk("rejected", null, value.value, response)), | ||
(key = new ReactPromise("rejected", null, value.value, response)), | ||
(key = createLazyChunkWrapper(key)); | ||
else if (0 < value.deps) { | ||
var blockedChunk = new Chunk("blocked", null, null, response); | ||
var blockedChunk = new ReactPromise( | ||
"blocked", | ||
null, | ||
null, | ||
response | ||
); | ||
value.value = key; | ||
@@ -1566,6 +1684,11 @@ value.chunk = blockedChunk; | ||
} | ||
exports.createFromNodeStream = function (stream, ssrManifest, options) { | ||
exports.createFromNodeStream = function ( | ||
stream, | ||
serverConsumerManifest, | ||
options | ||
) { | ||
var response = new ResponseInstance( | ||
ssrManifest.moduleMap, | ||
ssrManifest.moduleLoading, | ||
serverConsumerManifest.moduleMap, | ||
serverConsumerManifest.serverModuleMap, | ||
serverConsumerManifest.moduleLoading, | ||
noServerCall, | ||
@@ -1698,2 +1821,3 @@ options ? options.encodeFormAction : void 0, | ||
: (64 < chunkLength && 91 > chunkLength) || | ||
35 === chunkLength || | ||
114 === chunkLength || | ||
@@ -1700,0 +1824,0 @@ 120 === chunkLength |
@@ -17,6 +17,6 @@ /** | ||
var moduleExports = bundlerConfig[metadata[0]]; | ||
if ((bundlerConfig = moduleExports[metadata[2]])) | ||
if ((bundlerConfig = moduleExports && moduleExports[metadata[2]])) | ||
moduleExports = bundlerConfig.name; | ||
else { | ||
bundlerConfig = moduleExports["*"]; | ||
bundlerConfig = moduleExports && moduleExports["*"]; | ||
if (!bundlerConfig) | ||
@@ -26,3 +26,3 @@ throw Error( | ||
metadata[0] + | ||
'" in the React SSR Manifest. This is probably a bug in the React Server Components bundler.' | ||
'" in the React Server Consumer Manifest. This is probably a bug in the React Server Components bundler.' | ||
); | ||
@@ -37,2 +37,8 @@ moduleExports = metadata[2]; | ||
} | ||
function resolveServerReference(bundlerConfig, id) { | ||
var idx = id.lastIndexOf("#"); | ||
bundlerConfig = id.slice(0, idx); | ||
id = id.slice(idx + 1); | ||
return { specifier: bundlerConfig, name: id }; | ||
} | ||
var asyncModuleCache = new Map(); | ||
@@ -63,2 +69,12 @@ function preloadModule(metadata) { | ||
} | ||
function requireModule(metadata) { | ||
var moduleExports = asyncModuleCache.get(metadata.specifier); | ||
if ("fulfilled" === moduleExports.status) moduleExports = moduleExports.value; | ||
else throw moduleExports.reason; | ||
return "*" === metadata.name | ||
? moduleExports | ||
: "" === metadata.name | ||
? moduleExports.default | ||
: moduleExports[metadata.name]; | ||
} | ||
function prepareDestinationWithChunks(moduleLoading, chunks, nonce$jscomp$0) { | ||
@@ -460,8 +476,13 @@ if (null !== moduleLoading) | ||
writtenObjects = new WeakMap(), | ||
modelRoot = root; | ||
root = serializeModel(root, 0); | ||
modelRoot = root, | ||
json = serializeModel(root, 0); | ||
null === formData | ||
? resolve(root) | ||
: (formData.set(formFieldPrefix + "0", root), | ||
? resolve(json) | ||
: (formData.set(formFieldPrefix + "0", json), | ||
0 === pendingParts && resolve(formData)); | ||
return function () { | ||
0 < pendingParts && | ||
((pendingParts = 0), | ||
null === formData ? resolve(json) : resolve(formData)); | ||
}; | ||
} | ||
@@ -605,11 +626,27 @@ var boundCache = new WeakMap(); | ||
} | ||
function createBoundServerReference(metaData, callServer, encodeFormAction) { | ||
function action() { | ||
var args = Array.prototype.slice.call(arguments); | ||
return bound | ||
? "fulfilled" === bound.status | ||
? callServer(id, bound.value.concat(args)) | ||
: Promise.resolve(bound).then(function (boundArgs) { | ||
return callServer(id, boundArgs.concat(args)); | ||
}) | ||
: callServer(id, args); | ||
} | ||
var id = metaData.id, | ||
bound = metaData.bound; | ||
registerServerReference(action, { id: id, bound: bound }, encodeFormAction); | ||
return action; | ||
} | ||
function createServerReference$1(id, callServer, encodeFormAction) { | ||
function proxy() { | ||
function action() { | ||
var args = Array.prototype.slice.call(arguments); | ||
return callServer(id, args); | ||
} | ||
registerServerReference(proxy, { id: id, bound: null }, encodeFormAction); | ||
return proxy; | ||
registerServerReference(action, { id: id, bound: null }, encodeFormAction); | ||
return action; | ||
} | ||
function Chunk(status, value, reason, response) { | ||
function ReactPromise(status, value, reason, response) { | ||
this.status = status; | ||
@@ -620,4 +657,4 @@ this.value = value; | ||
} | ||
Chunk.prototype = Object.create(Promise.prototype); | ||
Chunk.prototype.then = function (resolve, reject) { | ||
ReactPromise.prototype = Object.create(Promise.prototype); | ||
ReactPromise.prototype.then = function (resolve, reject) { | ||
switch (this.status) { | ||
@@ -664,3 +701,3 @@ case "resolved_model": | ||
function createPendingChunk(response) { | ||
return new Chunk("pending", null, null, response); | ||
return new ReactPromise("pending", null, null, response); | ||
} | ||
@@ -706,3 +743,3 @@ function wakeChunk(listeners, value) { | ||
function createResolvedIteratorResultChunk(response, value, done) { | ||
return new Chunk( | ||
return new ReactPromise( | ||
"resolved_model", | ||
@@ -776,14 +813,5 @@ (done ? '{"done":true,"value":' : '{"done":false,"value":') + value + "}", | ||
try { | ||
var metadata = chunk.value, | ||
promise = asyncModuleCache.get(metadata.specifier); | ||
if ("fulfilled" === promise.status) var moduleExports = promise.value; | ||
else throw promise.reason; | ||
var JSCompiler_inline_result = | ||
"*" === metadata.name | ||
? moduleExports | ||
: "" === metadata.name | ||
? moduleExports.default | ||
: moduleExports[metadata.name]; | ||
var value = requireModule(chunk.value); | ||
chunk.status = "fulfilled"; | ||
chunk.value = JSCompiler_inline_result; | ||
chunk.value = value; | ||
} catch (error) { | ||
@@ -828,11 +856,15 @@ (chunk.status = "rejected"), (chunk.reason = error); | ||
} | ||
parentObject[key] = map(response, value); | ||
"" === key && null === handler.value && (handler.value = parentObject[key]); | ||
parentObject[0] === REACT_ELEMENT_TYPE && | ||
"3" === key && | ||
i = map(response, value, parentObject, key); | ||
parentObject[key] = i; | ||
"" === key && null === handler.value && (handler.value = i); | ||
if ( | ||
parentObject[0] === REACT_ELEMENT_TYPE && | ||
"object" === typeof handler.value && | ||
null !== handler.value && | ||
handler.value.$$typeof === REACT_ELEMENT_TYPE && | ||
null === handler.value.props && | ||
(handler.value.props = parentObject[key]); | ||
handler.value.$$typeof === REACT_ELEMENT_TYPE | ||
) | ||
switch (((value = handler.value), key)) { | ||
case "3": | ||
value.props = i; | ||
} | ||
handler.deps--; | ||
@@ -872,17 +904,70 @@ 0 === handler.deps && | ||
} | ||
function createServerReferenceProxy(response, metaData) { | ||
function proxy() { | ||
var args = Array.prototype.slice.call(arguments), | ||
p = metaData.bound; | ||
return p | ||
? "fulfilled" === p.status | ||
? callServer(metaData.id, p.value.concat(args)) | ||
: Promise.resolve(p).then(function (bound) { | ||
return callServer(metaData.id, bound.concat(args)); | ||
}) | ||
: callServer(metaData.id, args); | ||
} | ||
var callServer = response._callServer; | ||
registerServerReference(proxy, metaData, response._encodeFormAction); | ||
return proxy; | ||
function loadServerReference(response, metaData, parentObject, key) { | ||
if (!response._serverReferenceConfig) | ||
return createBoundServerReference( | ||
metaData, | ||
response._callServer, | ||
response._encodeFormAction | ||
); | ||
var serverReference = resolveServerReference( | ||
response._serverReferenceConfig, | ||
metaData.id | ||
); | ||
if ((response = preloadModule(serverReference))) | ||
metaData.bound && (response = Promise.all([response, metaData.bound])); | ||
else if (metaData.bound) response = Promise.resolve(metaData.bound); | ||
else return requireModule(serverReference); | ||
if (initializingHandler) { | ||
var handler = initializingHandler; | ||
handler.deps++; | ||
} else | ||
handler = initializingHandler = { | ||
parent: null, | ||
chunk: null, | ||
value: null, | ||
deps: 1, | ||
errored: !1 | ||
}; | ||
response.then( | ||
function () { | ||
var resolvedValue = requireModule(serverReference); | ||
if (metaData.bound) { | ||
var boundArgs = metaData.bound.value.slice(0); | ||
boundArgs.unshift(null); | ||
resolvedValue = resolvedValue.bind.apply(resolvedValue, boundArgs); | ||
} | ||
parentObject[key] = resolvedValue; | ||
"" === key && null === handler.value && (handler.value = resolvedValue); | ||
if ( | ||
parentObject[0] === REACT_ELEMENT_TYPE && | ||
"object" === typeof handler.value && | ||
null !== handler.value && | ||
handler.value.$$typeof === REACT_ELEMENT_TYPE | ||
) | ||
switch (((boundArgs = handler.value), key)) { | ||
case "3": | ||
boundArgs.props = resolvedValue; | ||
} | ||
handler.deps--; | ||
0 === handler.deps && | ||
((resolvedValue = handler.chunk), | ||
null !== resolvedValue && | ||
"blocked" === resolvedValue.status && | ||
((boundArgs = resolvedValue.value), | ||
(resolvedValue.status = "fulfilled"), | ||
(resolvedValue.value = handler.value), | ||
null !== boundArgs && wakeChunk(boundArgs, handler.value))); | ||
}, | ||
function (error) { | ||
if (!handler.errored) { | ||
handler.errored = !0; | ||
handler.value = error; | ||
var chunk = handler.chunk; | ||
null !== chunk && | ||
"blocked" === chunk.status && | ||
triggerErrorOnChunk(chunk, error); | ||
} | ||
} | ||
); | ||
return null; | ||
} | ||
@@ -903,6 +988,4 @@ function getOutlinedModel(response, reference, parentObject, key, map) { | ||
var value = id.value; | ||
for (id = 1; id < reference.length; id++) | ||
if ( | ||
((value = value[reference[id]]), value.$$typeof === REACT_LAZY_TYPE) | ||
) | ||
for (id = 1; id < reference.length; id++) { | ||
for (; value.$$typeof === REACT_LAZY_TYPE; ) | ||
if (((value = value._payload), "fulfilled" === value.status)) | ||
@@ -917,5 +1000,7 @@ value = value.value; | ||
map, | ||
reference.slice(id) | ||
reference.slice(id - 1) | ||
); | ||
return map(response, value); | ||
value = value[reference[id]]; | ||
} | ||
return map(response, value, parentObject, key); | ||
case "pending": | ||
@@ -999,3 +1084,3 @@ case "blocked": | ||
key, | ||
createServerReferenceProxy | ||
loadServerReference | ||
) | ||
@@ -1031,2 +1116,4 @@ ); | ||
); | ||
case "Z": | ||
return resolveErrorProd(); | ||
case "i": | ||
@@ -1065,2 +1152,3 @@ return ( | ||
bundlerConfig, | ||
serverReferenceConfig, | ||
moduleLoading, | ||
@@ -1074,2 +1162,3 @@ callServer, | ||
this._bundlerConfig = bundlerConfig; | ||
this._serverReferenceConfig = serverReferenceConfig; | ||
this._moduleLoading = moduleLoading; | ||
@@ -1092,3 +1181,3 @@ this._callServer = void 0 !== callServer ? callServer : missingCall; | ||
? chunk.reason.enqueueValue(buffer) | ||
: chunks.set(id, new Chunk("fulfilled", buffer, null, response)); | ||
: chunks.set(id, new ReactPromise("fulfilled", buffer, null, response)); | ||
} | ||
@@ -1110,3 +1199,3 @@ function resolveModule(response, id, model) { | ||
} else | ||
(blockedChunk = new Chunk("blocked", null, null, response)), | ||
(blockedChunk = new ReactPromise("blocked", null, null, response)), | ||
chunks.set(id, blockedChunk); | ||
@@ -1126,3 +1215,3 @@ model.then( | ||
id, | ||
new Chunk("resolved_module", clientReference, null, response) | ||
new ReactPromise("resolved_module", clientReference, null, response) | ||
); | ||
@@ -1140,3 +1229,6 @@ } | ||
null !== response && wakeChunk(response, chunk.value)) | ||
: chunks.set(id, new Chunk("fulfilled", stream, controller, response)); | ||
: chunks.set( | ||
id, | ||
new ReactPromise("fulfilled", stream, controller, response) | ||
); | ||
} | ||
@@ -1162,3 +1254,3 @@ function startReadableStream(response, id, type) { | ||
if (null === previousBlockedChunk) { | ||
var chunk = new Chunk("resolved_model", json, null, response); | ||
var chunk = new ReactPromise("resolved_model", json, null, response); | ||
initializeModelChunk(chunk); | ||
@@ -1239,3 +1331,3 @@ "fulfilled" === chunk.status | ||
if (closed) | ||
return new Chunk( | ||
return new ReactPromise( | ||
"fulfilled", | ||
@@ -1259,3 +1351,3 @@ { done: !0, value: void 0 }, | ||
if (nextWriteIndex === buffer.length) | ||
buffer[nextWriteIndex] = new Chunk( | ||
buffer[nextWriteIndex] = new ReactPromise( | ||
"fulfilled", | ||
@@ -1316,2 +1408,9 @@ { done: !1, value: value }, | ||
} | ||
function resolveErrorProd() { | ||
var error = Error( | ||
"An error occurred in the Server Components render. The specific message is omitted in production builds to avoid leaking sensitive details. A digest property is included on this error instance which may provide additional details about the nature of the error." | ||
); | ||
error.stack = "Error: " + error.message; | ||
return error; | ||
} | ||
function mergeBuffer(buffer, lastChunk) { | ||
@@ -1453,8 +1552,5 @@ for (var l = buffer.length, byteLength = lastChunk.length, i = 0; i < l; i++) | ||
case 69: | ||
tag = JSON.parse(row).digest; | ||
row = Error( | ||
"An error occurred in the Server Components render. The specific message is omitted in production builds to avoid leaking sensitive details. A digest property is included on this error instance which may provide additional details about the nature of the error." | ||
); | ||
row.stack = "Error: " + row.message; | ||
row.digest = tag; | ||
tag = JSON.parse(row); | ||
row = resolveErrorProd(); | ||
row.digest = tag.digest; | ||
tag = response._chunks; | ||
@@ -1464,3 +1560,3 @@ var chunk = tag.get(id); | ||
? triggerErrorOnChunk(chunk, row) | ||
: tag.set(id, new Chunk("rejected", null, row, response)); | ||
: tag.set(id, new ReactPromise("rejected", null, row, response)); | ||
break; | ||
@@ -1471,3 +1567,3 @@ case 84: | ||
? chunk.reason.enqueueValue(row) | ||
: tag.set(id, new Chunk("fulfilled", row, null, response)); | ||
: tag.set(id, new ReactPromise("fulfilled", row, null, response)); | ||
break; | ||
@@ -1500,3 +1596,6 @@ case 68: | ||
? resolveModelChunk(chunk, row) | ||
: tag.set(id, new Chunk("resolved_model", row, null, response)); | ||
: tag.set( | ||
id, | ||
new ReactPromise("resolved_model", row, null, response) | ||
); | ||
} | ||
@@ -1525,6 +1624,11 @@ } | ||
) | ||
(key = new Chunk("rejected", null, value.value, response)), | ||
(key = new ReactPromise("rejected", null, value.value, response)), | ||
(key = createLazyChunkWrapper(key)); | ||
else if (0 < value.deps) { | ||
var blockedChunk = new Chunk("blocked", null, null, response); | ||
var blockedChunk = new ReactPromise( | ||
"blocked", | ||
null, | ||
null, | ||
response | ||
); | ||
value.value = key; | ||
@@ -1545,6 +1649,11 @@ value.chunk = blockedChunk; | ||
} | ||
exports.createFromNodeStream = function (stream, ssrManifest, options) { | ||
exports.createFromNodeStream = function ( | ||
stream, | ||
serverConsumerManifest, | ||
options | ||
) { | ||
var response = new ResponseInstance( | ||
ssrManifest.moduleMap, | ||
ssrManifest.moduleLoading, | ||
serverConsumerManifest.moduleMap, | ||
serverConsumerManifest.serverModuleMap, | ||
serverConsumerManifest.moduleLoading, | ||
noServerCall, | ||
@@ -1677,2 +1786,3 @@ options ? options.encodeFormAction : void 0, | ||
: (64 < chunkLength && 91 > chunkLength) || | ||
35 === chunkLength || | ||
114 === chunkLength || | ||
@@ -1679,0 +1789,0 @@ 120 === chunkLength |
@@ -98,3 +98,3 @@ /** | ||
constructor(options) { | ||
this.ssrManifestFilename = | ||
this.serverConsumerManifestFilename = | ||
this.clientManifestFilename = | ||
@@ -124,4 +124,4 @@ this.chunkName = | ||
options.clientManifestFilename || "react-client-manifest.json"; | ||
this.ssrManifestFilename = | ||
options.ssrManifestFilename || "react-ssr-manifest.json"; | ||
this.serverConsumerManifestFilename = | ||
options.serverConsumerManifestFilename || "react-ssr-manifest.json"; | ||
} | ||
@@ -291,3 +291,3 @@ apply(compiler) { | ||
compilation.emitAsset( | ||
_this.ssrManifestFilename, | ||
_this.serverConsumerManifestFilename, | ||
new webpack.sources.RawSource(configuredCrossOriginLoading, !1) | ||
@@ -294,0 +294,0 @@ ); |
@@ -12,2 +12,4 @@ /** | ||
import * as acorn from 'acorn-loose'; | ||
import readMappings from 'webpack-sources/lib/helpers/readMappings.js'; | ||
import createMappingsSerializer from 'webpack-sources/lib/helpers/createMappingsSerializer.js'; | ||
@@ -43,10 +45,28 @@ const assign = Object.assign; | ||
function addLocalExportedNames(names, node) { | ||
function addExportedEntry(exportedEntries, localNames, localName, exportedName, type, loc) { | ||
if (localNames.has(localName)) { | ||
// If the same local name is exported more than once, we only need one of the names. | ||
return; | ||
} | ||
exportedEntries.push({ | ||
localName, | ||
exportedName, | ||
type, | ||
loc, | ||
originalLine: -1, | ||
originalColumn: -1, | ||
originalSource: -1, | ||
nameIndex: -1 | ||
}); | ||
} | ||
function addLocalExportedNames(exportedEntries, localNames, node) { | ||
switch (node.type) { | ||
case 'Identifier': | ||
names.set(node.name, node.name); | ||
addExportedEntry(exportedEntries, localNames, node.name, node.name, null, node.loc); | ||
return; | ||
case 'ObjectPattern': | ||
for (let i = 0; i < node.properties.length; i++) addLocalExportedNames(names, node.properties[i]); | ||
for (let i = 0; i < node.properties.length; i++) addLocalExportedNames(exportedEntries, localNames, node.properties[i]); | ||
@@ -58,3 +78,3 @@ return; | ||
const element = node.elements[i]; | ||
if (element) addLocalExportedNames(names, element); | ||
if (element) addLocalExportedNames(exportedEntries, localNames, element); | ||
} | ||
@@ -65,15 +85,15 @@ | ||
case 'Property': | ||
addLocalExportedNames(names, node.value); | ||
addLocalExportedNames(exportedEntries, localNames, node.value); | ||
return; | ||
case 'AssignmentPattern': | ||
addLocalExportedNames(names, node.left); | ||
addLocalExportedNames(exportedEntries, localNames, node.left); | ||
return; | ||
case 'RestElement': | ||
addLocalExportedNames(names, node.argument); | ||
addLocalExportedNames(exportedEntries, localNames, node.argument); | ||
return; | ||
case 'ParenthesizedExpression': | ||
addLocalExportedNames(names, node.expression); | ||
addLocalExportedNames(exportedEntries, localNames, node.expression); | ||
return; | ||
@@ -83,7 +103,9 @@ } | ||
function transformServerModule(source, body, url, loader) { | ||
// If the same local name is exported more than once, we only need one of the names. | ||
const localNames = new Map(); | ||
const localTypes = new Map(); | ||
function transformServerModule(source, program, url, sourceMap, loader) { | ||
const body = program.body; // This entry list needs to be in source location order. | ||
const exportedEntries = []; // Dedupe set. | ||
const localNames = new Set(); | ||
for (let i = 0; i < body.length; i++) { | ||
@@ -99,7 +121,6 @@ const node = body[i]; | ||
if (node.declaration.type === 'Identifier') { | ||
localNames.set(node.declaration.name, 'default'); | ||
addExportedEntry(exportedEntries, localNames, node.declaration.name, 'default', null, node.declaration.loc); | ||
} else if (node.declaration.type === 'FunctionDeclaration') { | ||
if (node.declaration.id) { | ||
localNames.set(node.declaration.id.name, 'default'); | ||
localTypes.set(node.declaration.id.name, 'function'); | ||
addExportedEntry(exportedEntries, localNames, node.declaration.id.name, 'default', 'function', node.declaration.id.loc); | ||
} | ||
@@ -116,11 +137,7 @@ } | ||
for (let j = 0; j < declarations.length; j++) { | ||
addLocalExportedNames(localNames, declarations[j].id); | ||
addLocalExportedNames(exportedEntries, localNames, declarations[j].id); | ||
} | ||
} else { | ||
const name = node.declaration.id.name; | ||
localNames.set(name, name); | ||
if (node.declaration.type === 'FunctionDeclaration') { | ||
localTypes.set(name, 'function'); | ||
} | ||
addExportedEntry(exportedEntries, localNames, name, name, node.declaration.type === 'FunctionDeclaration' ? 'function' : null, node.declaration.id.loc); | ||
} | ||
@@ -134,3 +151,3 @@ } | ||
const specifier = specifiers[j]; | ||
localNames.set(specifier.local.name, specifier.exported.name); | ||
addExportedEntry(exportedEntries, localNames, specifier.local.name, specifier.exported.name, null, specifier.local.loc); | ||
} | ||
@@ -143,18 +160,155 @@ } | ||
if (localNames.size === 0) { | ||
return source; | ||
} | ||
let mappings = sourceMap && typeof sourceMap.mappings === 'string' ? sourceMap.mappings : ''; | ||
let newSrc = source; | ||
let newSrc = source + '\n\n;'; | ||
newSrc += 'import {registerServerReference} from "react-server-dom-webpack/server";\n'; | ||
localNames.forEach(function (exported, local) { | ||
if (localTypes.get(local) !== 'function') { | ||
// We first check if the export is a function and if so annotate it. | ||
newSrc += 'if (typeof ' + local + ' === "function") '; | ||
if (exportedEntries.length > 0) { | ||
let lastSourceIndex = 0; | ||
let lastOriginalLine = 0; | ||
let lastOriginalColumn = 0; | ||
let lastNameIndex = 0; | ||
let sourceLineCount = 0; | ||
let lastMappedLine = 0; | ||
if (sourceMap) { | ||
// We iterate source mapping entries and our matched exports in parallel to source map | ||
// them to their original location. | ||
let nextEntryIdx = 0; | ||
let nextEntryLine = exportedEntries[nextEntryIdx].loc.start.line; | ||
let nextEntryColumn = exportedEntries[nextEntryIdx].loc.start.column; | ||
readMappings(mappings, (generatedLine, generatedColumn, sourceIndex, originalLine, originalColumn, nameIndex) => { | ||
if (generatedLine > nextEntryLine || generatedLine === nextEntryLine && generatedColumn > nextEntryColumn) { | ||
// We're past the entry which means that the best match we have is the previous entry. | ||
if (lastMappedLine === nextEntryLine) { | ||
// Match | ||
exportedEntries[nextEntryIdx].originalLine = lastOriginalLine; | ||
exportedEntries[nextEntryIdx].originalColumn = lastOriginalColumn; | ||
exportedEntries[nextEntryIdx].originalSource = lastSourceIndex; | ||
exportedEntries[nextEntryIdx].nameIndex = lastNameIndex; | ||
} | ||
nextEntryIdx++; | ||
if (nextEntryIdx < exportedEntries.length) { | ||
nextEntryLine = exportedEntries[nextEntryIdx].loc.start.line; | ||
nextEntryColumn = exportedEntries[nextEntryIdx].loc.start.column; | ||
} else { | ||
nextEntryLine = -1; | ||
nextEntryColumn = -1; | ||
} | ||
} | ||
lastMappedLine = generatedLine; | ||
if (sourceIndex > -1) { | ||
lastSourceIndex = sourceIndex; | ||
} | ||
if (originalLine > -1) { | ||
lastOriginalLine = originalLine; | ||
} | ||
if (originalColumn > -1) { | ||
lastOriginalColumn = originalColumn; | ||
} | ||
if (nameIndex > -1) { | ||
lastNameIndex = nameIndex; | ||
} | ||
}); | ||
if (nextEntryIdx < exportedEntries.length) { | ||
if (lastMappedLine === nextEntryLine) { | ||
// Match | ||
exportedEntries[nextEntryIdx].originalLine = lastOriginalLine; | ||
exportedEntries[nextEntryIdx].originalColumn = lastOriginalColumn; | ||
exportedEntries[nextEntryIdx].originalSource = lastSourceIndex; | ||
exportedEntries[nextEntryIdx].nameIndex = lastNameIndex; | ||
} | ||
} | ||
for (let lastIdx = mappings.length - 1; lastIdx >= 0 && mappings[lastIdx] === ';'; lastIdx--) { | ||
// If the last mapped lines don't contain any segments, we don't get a callback from readMappings | ||
// so we need to pad the number of mapped lines, with one for each empty line. | ||
lastMappedLine++; | ||
} | ||
sourceLineCount = program.loc.end.line; | ||
if (sourceLineCount < lastMappedLine) { | ||
throw new Error('The source map has more mappings than there are lines.'); | ||
} // If the original source string had more lines than there are mappings in the source map. | ||
// Add some extra padding of unmapped lines so that any lines that we add line up. | ||
for (let extraLines = sourceLineCount - lastMappedLine; extraLines > 0; extraLines--) { | ||
mappings += ';'; | ||
} | ||
} else { | ||
// If a file doesn't have a source map then we generate a blank source map that just | ||
// contains the original content and segments pointing to the original lines. | ||
sourceLineCount = 1; | ||
let idx = -1; | ||
while ((idx = source.indexOf('\n', idx + 1)) !== -1) { | ||
sourceLineCount++; | ||
} | ||
mappings = 'AAAA' + ';AACA'.repeat(sourceLineCount - 1); | ||
sourceMap = { | ||
version: 3, | ||
sources: [url], | ||
sourcesContent: [source], | ||
mappings: mappings, | ||
sourceRoot: '' | ||
}; | ||
lastSourceIndex = 0; | ||
lastOriginalLine = sourceLineCount; | ||
lastOriginalColumn = 0; | ||
lastNameIndex = -1; | ||
lastMappedLine = sourceLineCount; | ||
for (let i = 0; i < exportedEntries.length; i++) { | ||
// Point each entry to original location. | ||
const entry = exportedEntries[i]; | ||
entry.originalSource = 0; | ||
entry.originalLine = entry.loc.start.line; // We use column zero since we do the short-hand line-only source maps above. | ||
entry.originalColumn = 0; // entry.loc.start.column; | ||
} | ||
} | ||
newSrc += 'registerServerReference(' + local + ','; | ||
newSrc += JSON.stringify(url) + ','; | ||
newSrc += JSON.stringify(exported) + ');\n'; | ||
}); | ||
newSrc += '\n\n;'; | ||
newSrc += 'import {registerServerReference} from "react-server-dom-webpack/server";\n'; | ||
if (mappings) { | ||
mappings += ';;'; | ||
} | ||
const createMapping = createMappingsSerializer(); // Create an empty mapping pointing to where we last left off to reset the counters. | ||
let generatedLine = 1; | ||
createMapping(generatedLine, 0, lastSourceIndex, lastOriginalLine, lastOriginalColumn, lastNameIndex); | ||
for (let i = 0; i < exportedEntries.length; i++) { | ||
const entry = exportedEntries[i]; | ||
generatedLine++; | ||
if (entry.type !== 'function') { | ||
// We first check if the export is a function and if so annotate it. | ||
newSrc += 'if (typeof ' + entry.localName + ' === "function") '; | ||
} | ||
newSrc += 'registerServerReference(' + entry.localName + ','; | ||
newSrc += JSON.stringify(url) + ','; | ||
newSrc += JSON.stringify(entry.exportedName) + ');\n'; | ||
mappings += createMapping(generatedLine, 0, entry.originalSource, entry.originalLine, entry.originalColumn, entry.nameIndex); | ||
} | ||
} | ||
if (sourceMap) { | ||
// Override with an new mappings and serialize an inline source map. | ||
sourceMap.mappings = mappings; | ||
newSrc += '//# sourceMappingURL=data:application/json;charset=utf-8;base64,' + Buffer.from(JSON.stringify(sourceMap)).toString('base64'); | ||
} | ||
return newSrc; | ||
@@ -289,3 +443,4 @@ } | ||
async function transformClientModule(body, url, loader) { | ||
async function transformClientModule(program, url, sourceMap, loader) { | ||
const body = program.body; | ||
const names = []; | ||
@@ -316,4 +471,6 @@ await parseExportNamesInto(body, names, url, loader); | ||
newSrc += JSON.stringify(name) + ');\n'; | ||
} | ||
} // TODO: Generate source maps for Client Reference functions so they can point to their | ||
// original locations. | ||
return newSrc; | ||
@@ -350,9 +507,24 @@ } | ||
let body; | ||
let sourceMappingURL = null; | ||
let sourceMappingStart = 0; | ||
let sourceMappingEnd = 0; | ||
let sourceMappingLines = 0; | ||
let program; | ||
try { | ||
body = acorn.parse(source, { | ||
program = acorn.parse(source, { | ||
ecmaVersion: '2024', | ||
sourceType: 'module' | ||
}).body; | ||
sourceType: 'module', | ||
locations: true, | ||
onComment(block, text, start, end, startLoc, endLoc) { | ||
if (text.startsWith('# sourceMappingURL=') || text.startsWith('@ sourceMappingURL=')) { | ||
sourceMappingURL = text.slice(19); | ||
sourceMappingStart = start; | ||
sourceMappingEnd = end; | ||
sourceMappingLines = endLoc.line - startLoc.line; | ||
} | ||
} | ||
}); | ||
} catch (x) { | ||
@@ -366,2 +538,3 @@ // eslint-disable-next-line react-internal/no-production-logging | ||
let useServer = false; | ||
const body = program.body; | ||
@@ -392,7 +565,28 @@ for (let i = 0; i < body.length; i++) { | ||
let sourceMap = null; | ||
if (sourceMappingURL) { | ||
const sourceMapResult = await loader(sourceMappingURL, // $FlowFixMe | ||
{ | ||
format: 'json', | ||
conditions: [], | ||
importAssertions: { | ||
type: 'json' | ||
}, | ||
importAttributes: { | ||
type: 'json' | ||
} | ||
}, loader); | ||
const sourceMapString = typeof sourceMapResult.source === 'string' ? sourceMapResult.source : // $FlowFixMe | ||
sourceMapResult.source.toString('utf8'); | ||
sourceMap = JSON.parse(sourceMapString); // Strip the source mapping comment. We'll re-add it below if needed. | ||
source = source.slice(0, sourceMappingStart) + '\n'.repeat(sourceMappingLines) + source.slice(sourceMappingEnd); | ||
} | ||
if (useClient) { | ||
return transformClientModule(body, url, loader); | ||
return transformClientModule(program, url, sourceMap, loader); | ||
} | ||
return transformServerModule(source, body, url); | ||
return transformServerModule(source, program, url, sourceMap); | ||
} | ||
@@ -399,0 +593,0 @@ |
{ | ||
"name": "react-server-dom-webpack", | ||
"description": "React Server Components bindings for DOM using Webpack. This is intended to be integrated into meta-frameworks. It is not intended to be imported directly.", | ||
"version": "19.0.0-rc-49496d49-20240814", | ||
"version": "19.0.0-rc-4beb1fd8-20241118", | ||
"keywords": [ | ||
@@ -26,2 +26,7 @@ "react" | ||
"server.node.unbundled.js", | ||
"static.js", | ||
"static.browser.js", | ||
"static.edge.js", | ||
"static.node.js", | ||
"static.node.unbundled.js", | ||
"node-register.js", | ||
@@ -67,2 +72,19 @@ "cjs/", | ||
"./server.node.unbundled": "./server.node.unbundled.js", | ||
"./static": { | ||
"react-server": { | ||
"workerd": "./static.edge.js", | ||
"deno": "./static.browser.js", | ||
"node": { | ||
"webpack": "./static.node.js", | ||
"default": "./static.node.unbundled.js" | ||
}, | ||
"edge-light": "./static.edge.js", | ||
"browser": "./static.browser.js" | ||
}, | ||
"default": "./static.js" | ||
}, | ||
"./static.browser": "./static.browser.js", | ||
"./static.edge": "./static.edge.js", | ||
"./static.node": "./static.node.js", | ||
"./static.node.unbundled": "./static.node.unbundled.js", | ||
"./node-loader": "./esm/react-server-dom-webpack-node-loader.production.js", | ||
@@ -82,4 +104,4 @@ "./node-register": "./node-register.js", | ||
"peerDependencies": { | ||
"react": "19.0.0-rc-49496d49-20240814", | ||
"react-dom": "19.0.0-rc-49496d49-20240814", | ||
"react": "19.0.0-rc-4beb1fd8-20241118", | ||
"react-dom": "19.0.0-rc-4beb1fd8-20241118", | ||
"webpack": "^5.59.0" | ||
@@ -89,4 +111,5 @@ }, | ||
"acorn-loose": "^8.3.0", | ||
"neo-async": "^2.6.1" | ||
"neo-async": "^2.6.1", | ||
"webpack-sources": "^3.2.0" | ||
} | ||
} |
'use strict'; | ||
var s; | ||
if (process.env.NODE_ENV === 'production') { | ||
module.exports = require('./cjs/react-server-dom-webpack-server.browser.production.js'); | ||
s = require('./cjs/react-server-dom-webpack-server.browser.production.js'); | ||
} else { | ||
module.exports = require('./cjs/react-server-dom-webpack-server.browser.development.js'); | ||
s = require('./cjs/react-server-dom-webpack-server.browser.development.js'); | ||
} | ||
exports.renderToReadableStream = s.renderToReadableStream; | ||
exports.decodeReply = s.decodeReply; | ||
exports.decodeAction = s.decodeAction; | ||
exports.decodeFormState = s.decodeFormState; | ||
exports.registerServerReference = s.registerServerReference; | ||
exports.registerClientReference = s.registerClientReference; | ||
exports.createClientModuleProxy = s.createClientModuleProxy; | ||
exports.createTemporaryReferenceSet = s.createTemporaryReferenceSet; |
'use strict'; | ||
var s; | ||
if (process.env.NODE_ENV === 'production') { | ||
module.exports = require('./cjs/react-server-dom-webpack-server.edge.production.js'); | ||
s = require('./cjs/react-server-dom-webpack-server.edge.production.js'); | ||
} else { | ||
module.exports = require('./cjs/react-server-dom-webpack-server.edge.development.js'); | ||
s = require('./cjs/react-server-dom-webpack-server.edge.development.js'); | ||
} | ||
exports.renderToReadableStream = s.renderToReadableStream; | ||
exports.decodeReply = s.decodeReply; | ||
exports.decodeAction = s.decodeAction; | ||
exports.decodeFormState = s.decodeFormState; | ||
exports.registerServerReference = s.registerServerReference; | ||
exports.registerClientReference = s.registerClientReference; | ||
exports.createClientModuleProxy = s.createClientModuleProxy; | ||
exports.createTemporaryReferenceSet = s.createTemporaryReferenceSet; |
'use strict'; | ||
var s; | ||
if (process.env.NODE_ENV === 'production') { | ||
module.exports = require('./cjs/react-server-dom-webpack-server.node.production.js'); | ||
s = require('./cjs/react-server-dom-webpack-server.node.production.js'); | ||
} else { | ||
module.exports = require('./cjs/react-server-dom-webpack-server.node.development.js'); | ||
s = require('./cjs/react-server-dom-webpack-server.node.development.js'); | ||
} | ||
exports.renderToPipeableStream = s.renderToPipeableStream; | ||
exports.decodeReplyFromBusboy = s.decodeReplyFromBusboy; | ||
exports.decodeReply = s.decodeReply; | ||
exports.decodeAction = s.decodeAction; | ||
exports.decodeFormState = s.decodeFormState; | ||
exports.registerServerReference = s.registerServerReference; | ||
exports.registerClientReference = s.registerClientReference; | ||
exports.createClientModuleProxy = s.createClientModuleProxy; | ||
exports.createTemporaryReferenceSet = s.createTemporaryReferenceSet; |
'use strict'; | ||
var s; | ||
if (process.env.NODE_ENV === 'production') { | ||
module.exports = require('./cjs/react-server-dom-webpack-server.node.unbundled.production.js'); | ||
s = require('./cjs/react-server-dom-webpack-server.node.unbundled.production.js'); | ||
} else { | ||
module.exports = require('./cjs/react-server-dom-webpack-server.node.unbundled.development.js'); | ||
s = require('./cjs/react-server-dom-webpack-server.node.unbundled.development.js'); | ||
} | ||
exports.renderToPipeableStream = s.renderToPipeableStream; | ||
exports.decodeReplyFromBusboy = s.decodeReplyFromBusboy; | ||
exports.decodeReply = s.decodeReply; | ||
exports.decodeAction = s.decodeAction; | ||
exports.decodeFormState = s.decodeFormState; | ||
exports.registerServerReference = s.registerServerReference; | ||
exports.registerClientReference = s.registerClientReference; | ||
exports.createClientModuleProxy = s.createClientModuleProxy; | ||
exports.createTemporaryReferenceSet = s.createTemporaryReferenceSet; |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1598589
41
45463
6
25
12
+ Addedwebpack-sources@^3.2.0
+ Added@types/node@22.10.3(transitive)
+ Addedreact@19.0.0-rc-4beb1fd8-20241118(transitive)
+ Addedreact-dom@19.0.0-rc-4beb1fd8-20241118(transitive)
+ Addedscheduler@0.25.0-rc-4beb1fd8-20241118(transitive)
- Removed@types/node@22.10.2(transitive)
- Removedreact@19.0.0-rc-49496d49-20240814(transitive)
- Removedreact-dom@19.0.0-rc-49496d49-20240814(transitive)
- Removedscheduler@0.25.0-rc-49496d49-20240814(transitive)