react-server-dom-webpack
Version:
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.
1,426 lines (1,425 loc) • 151 kB
JavaScript
/**
* @license React
* react-server-dom-webpack-server.node.unbundled.development.js
*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
"use strict";
"production" !== process.env.NODE_ENV &&
(function () {
function voidHandler() {}
function _defineProperty(obj, key, value) {
a: if ("object" == typeof key && key) {
var e = key[Symbol.toPrimitive];
if (void 0 !== e) {
key = e.call(key, "string");
if ("object" != typeof key) break a;
throw new TypeError("@@toPrimitive must return a primitive value.");
}
key = String(key);
}
key = "symbol" == typeof key ? key : key + "";
key in obj
? Object.defineProperty(obj, key, {
value: value,
enumerable: !0,
configurable: !0,
writable: !0
})
: (obj[key] = value);
return obj;
}
function writeToDestination(destination, view) {
destination = destination.write(view);
destinationHasCapacity = destinationHasCapacity && destination;
}
function writeChunkAndReturn(destination, chunk) {
if ("string" === typeof chunk) {
if (0 !== chunk.length)
if (2048 < 3 * chunk.length)
0 < writtenBytes &&
(writeToDestination(
destination,
currentView.subarray(0, writtenBytes)
),
(currentView = new Uint8Array(2048)),
(writtenBytes = 0)),
writeToDestination(destination, chunk);
else {
var target = currentView;
0 < writtenBytes && (target = currentView.subarray(writtenBytes));
target = textEncoder.encodeInto(chunk, target);
var read = target.read;
writtenBytes += target.written;
read < chunk.length &&
(writeToDestination(
destination,
currentView.subarray(0, writtenBytes)
),
(currentView = new Uint8Array(2048)),
(writtenBytes = textEncoder.encodeInto(
chunk.slice(read),
currentView
).written));
2048 === writtenBytes &&
(writeToDestination(destination, currentView),
(currentView = new Uint8Array(2048)),
(writtenBytes = 0));
}
} else
0 !== chunk.byteLength &&
(2048 < chunk.byteLength
? (0 < writtenBytes &&
(writeToDestination(
destination,
currentView.subarray(0, writtenBytes)
),
(currentView = new Uint8Array(2048)),
(writtenBytes = 0)),
writeToDestination(destination, chunk))
: ((target = currentView.length - writtenBytes),
target < chunk.byteLength &&
(0 === target
? writeToDestination(destination, currentView)
: (currentView.set(chunk.subarray(0, target), writtenBytes),
(writtenBytes += target),
writeToDestination(destination, currentView),
(chunk = chunk.subarray(target))),
(currentView = new Uint8Array(2048)),
(writtenBytes = 0)),
currentView.set(chunk, writtenBytes),
(writtenBytes += chunk.byteLength),
2048 === writtenBytes &&
(writeToDestination(destination, currentView),
(currentView = new Uint8Array(2048)),
(writtenBytes = 0))));
return destinationHasCapacity;
}
function byteLengthOfChunk(chunk) {
return "string" === typeof chunk
? Buffer.byteLength(chunk, "utf8")
: chunk.byteLength;
}
function isClientReference(reference) {
return reference.$$typeof === CLIENT_REFERENCE_TAG$1;
}
function registerClientReferenceImpl(proxyImplementation, id, async) {
return Object.defineProperties(proxyImplementation, {
$$typeof: { value: CLIENT_REFERENCE_TAG$1 },
$$id: { value: id },
$$async: { value: async }
});
}
function bind() {
var newFn = FunctionBind.apply(this, arguments);
if (this.$$typeof === SERVER_REFERENCE_TAG) {
null != arguments[0] &&
console.error(
'Cannot bind "this" of a Server Action. Pass null or undefined as the first argument to .bind().'
);
var args = ArraySlice.call(arguments, 1),
$$typeof = { value: SERVER_REFERENCE_TAG },
$$id = { value: this.$$id };
args = { value: this.$$bound ? this.$$bound.concat(args) : args };
return Object.defineProperties(newFn, {
$$typeof: $$typeof,
$$id: $$id,
$$bound: args,
$$location: { value: this.$$location, configurable: !0 },
bind: { value: bind, configurable: !0 }
});
}
return newFn;
}
function getReference(target, name) {
switch (name) {
case "$$typeof":
return target.$$typeof;
case "$$id":
return target.$$id;
case "$$async":
return target.$$async;
case "name":
return target.name;
case "defaultProps":
return;
case "toJSON":
return;
case Symbol.toPrimitive:
return Object.prototype[Symbol.toPrimitive];
case Symbol.toStringTag:
return Object.prototype[Symbol.toStringTag];
case "__esModule":
var moduleId = target.$$id;
target.default = registerClientReferenceImpl(
function () {
throw Error(
"Attempted to call the default export of " +
moduleId +
" from the server but it's on the client. It's not possible to invoke a client function from the server, it can only be rendered as a Component or passed to props of a Client Component."
);
},
target.$$id + "#",
target.$$async
);
return !0;
case "then":
if (target.then) return target.then;
if (target.$$async) return;
var clientReference = registerClientReferenceImpl(
{},
target.$$id,
!0
),
proxy = new Proxy(clientReference, proxyHandlers$1);
target.status = "fulfilled";
target.value = proxy;
return (target.then = registerClientReferenceImpl(
function (resolve) {
return Promise.resolve(resolve(proxy));
},
target.$$id + "#then",
!1
));
}
if ("symbol" === typeof name)
throw Error(
"Cannot read Symbol exports. Only named exports are supported on a client module imported on the server."
);
clientReference = target[name];
clientReference ||
((clientReference = registerClientReferenceImpl(
function () {
throw Error(
"Attempted to call " +
String(name) +
"() from the server but " +
String(name) +
" is on the client. It's not possible to invoke a client function from the server, it can only be rendered as a Component or passed to props of a Client Component."
);
},
target.$$id + "#" + name,
target.$$async
)),
Object.defineProperty(clientReference, "name", { value: name }),
(clientReference = target[name] =
new Proxy(clientReference, deepProxyHandlers)));
return clientReference;
}
function trimOptions(options) {
if (null == options) return null;
var hasProperties = !1,
trimmed = {},
key;
for (key in options)
null != options[key] &&
((hasProperties = !0), (trimmed[key] = options[key]));
return hasProperties ? trimmed : null;
}
function prepareStackTrace(error, structuredStackTrace) {
error = (error.name || "Error") + ": " + (error.message || "");
for (var i = 0; i < structuredStackTrace.length; i++)
error += "\n at " + structuredStackTrace[i].toString();
return error;
}
function parseStackTrace(error, skipFrames) {
a: {
var previousPrepare = Error.prepareStackTrace;
Error.prepareStackTrace = prepareStackTrace;
try {
var stack = String(error.stack);
break a;
} finally {
Error.prepareStackTrace = previousPrepare;
}
stack = void 0;
}
stack.startsWith("Error: react-stack-top-frame\n") &&
(stack = stack.slice(29));
error = stack.indexOf("react-stack-bottom-frame");
-1 !== error && (error = stack.lastIndexOf("\n", error));
-1 !== error && (stack = stack.slice(0, error));
stack = stack.split("\n");
for (error = []; skipFrames < stack.length; skipFrames++)
if ((previousPrepare = frameRegExp.exec(stack[skipFrames]))) {
var name = previousPrepare[1] || "";
"<anonymous>" === name && (name = "");
var filename = previousPrepare[2] || previousPrepare[5] || "";
"<anonymous>" === filename && (filename = "");
error.push([
name,
filename,
+(previousPrepare[3] || previousPrepare[6]),
+(previousPrepare[4] || previousPrepare[7])
]);
}
return error;
}
function createTemporaryReference(temporaryReferences, id) {
var reference = Object.defineProperties(
function () {
throw Error(
"Attempted to call a temporary Client Reference from the server but it is on the client. It's not possible to invoke a client function from the server, it can only be rendered as a Component or passed to props of a Client Component."
);
},
{ $$typeof: { value: TEMPORARY_REFERENCE_TAG } }
);
reference = new Proxy(reference, proxyHandlers);
temporaryReferences.set(reference, id);
return reference;
}
function getIteratorFn(maybeIterable) {
if (null === maybeIterable || "object" !== typeof maybeIterable)
return null;
maybeIterable =
(MAYBE_ITERATOR_SYMBOL && maybeIterable[MAYBE_ITERATOR_SYMBOL]) ||
maybeIterable["@@iterator"];
return "function" === typeof maybeIterable ? maybeIterable : null;
}
function noop$1() {}
function trackUsedThenable(thenableState, thenable, index) {
index = thenableState[index];
void 0 === index
? thenableState.push(thenable)
: index !== thenable &&
(thenable.then(noop$1, noop$1), (thenable = index));
switch (thenable.status) {
case "fulfilled":
return thenable.value;
case "rejected":
throw thenable.reason;
default:
"string" === typeof thenable.status
? thenable.then(noop$1, noop$1)
: ((thenableState = thenable),
(thenableState.status = "pending"),
thenableState.then(
function (fulfilledValue) {
if ("pending" === thenable.status) {
var fulfilledThenable = thenable;
fulfilledThenable.status = "fulfilled";
fulfilledThenable.value = fulfilledValue;
}
},
function (error) {
if ("pending" === thenable.status) {
var rejectedThenable = thenable;
rejectedThenable.status = "rejected";
rejectedThenable.reason = error;
}
}
));
switch (thenable.status) {
case "fulfilled":
return thenable.value;
case "rejected":
throw thenable.reason;
}
suspendedThenable = thenable;
throw SuspenseException;
}
}
function getSuspendedThenable() {
if (null === suspendedThenable)
throw Error(
"Expected a suspended thenable. This is a bug in React. Please file an issue."
);
var thenable = suspendedThenable;
suspendedThenable = null;
return thenable;
}
function getThenableStateAfterSuspending() {
var state = thenableState || [];
state._componentDebugInfo = currentComponentDebugInfo;
thenableState = currentComponentDebugInfo = null;
return state;
}
function unsupportedHook() {
throw Error("This Hook is not supported in Server Components.");
}
function unsupportedRefresh() {
throw Error(
"Refreshing the cache is not supported in Server Components."
);
}
function unsupportedContext() {
throw Error("Cannot read a Client Context from a Server Component.");
}
function resolveOwner() {
if (currentOwner) return currentOwner;
var owner = componentStorage.getStore();
return owner ? owner : null;
}
function resetOwnerStackLimit() {
var now = getCurrentTime();
1e3 < now - lastResetTime &&
((ReactSharedInternalsServer.recentlyCreatedOwnerStacks = 0),
(lastResetTime = now));
}
function isObjectPrototype(object) {
if (!object) return !1;
var ObjectPrototype = Object.prototype;
if (object === ObjectPrototype) return !0;
if (getPrototypeOf(object)) return !1;
object = Object.getOwnPropertyNames(object);
for (var i = 0; i < object.length; i++)
if (!(object[i] in ObjectPrototype)) return !1;
return !0;
}
function isSimpleObject(object) {
if (!isObjectPrototype(getPrototypeOf(object))) return !1;
for (
var names = Object.getOwnPropertyNames(object), i = 0;
i < names.length;
i++
) {
var descriptor = Object.getOwnPropertyDescriptor(object, names[i]);
if (
!descriptor ||
(!descriptor.enumerable &&
(("key" !== names[i] && "ref" !== names[i]) ||
"function" !== typeof descriptor.get))
)
return !1;
}
return !0;
}
function objectName(object) {
return Object.prototype.toString
.call(object)
.replace(/^\[object (.*)\]$/, function (m, p0) {
return p0;
});
}
function describeKeyForErrorMessage(key) {
var encodedKey = JSON.stringify(key);
return '"' + key + '"' === encodedKey ? key : encodedKey;
}
function describeValueForErrorMessage(value) {
switch (typeof value) {
case "string":
return JSON.stringify(
10 >= value.length ? value : value.slice(0, 10) + "..."
);
case "object":
if (isArrayImpl(value)) return "[...]";
if (null !== value && value.$$typeof === CLIENT_REFERENCE_TAG)
return "client";
value = objectName(value);
return "Object" === value ? "{...}" : value;
case "function":
return value.$$typeof === CLIENT_REFERENCE_TAG
? "client"
: (value = value.displayName || value.name)
? "function " + value
: "function";
default:
return String(value);
}
}
function describeElementType(type) {
if ("string" === typeof type) return type;
switch (type) {
case REACT_SUSPENSE_TYPE:
return "Suspense";
case REACT_SUSPENSE_LIST_TYPE:
return "SuspenseList";
}
if ("object" === typeof type)
switch (type.$$typeof) {
case REACT_FORWARD_REF_TYPE:
return describeElementType(type.render);
case REACT_MEMO_TYPE:
return describeElementType(type.type);
case REACT_LAZY_TYPE:
var payload = type._payload;
type = type._init;
try {
return describeElementType(type(payload));
} catch (x) {}
}
return "";
}
function describeObjectForErrorMessage(objectOrArray, expandedName) {
var objKind = objectName(objectOrArray);
if ("Object" !== objKind && "Array" !== objKind) return objKind;
var start = -1,
length = 0;
if (isArrayImpl(objectOrArray))
if (jsxChildrenParents.has(objectOrArray)) {
var type = jsxChildrenParents.get(objectOrArray);
objKind = "<" + describeElementType(type) + ">";
for (var i = 0; i < objectOrArray.length; i++) {
var value = objectOrArray[i];
value =
"string" === typeof value
? value
: "object" === typeof value && null !== value
? "{" + describeObjectForErrorMessage(value) + "}"
: "{" + describeValueForErrorMessage(value) + "}";
"" + i === expandedName
? ((start = objKind.length),
(length = value.length),
(objKind += value))
: (objKind =
15 > value.length && 40 > objKind.length + value.length
? objKind + value
: objKind + "{...}");
}
objKind += "</" + describeElementType(type) + ">";
} else {
objKind = "[";
for (type = 0; type < objectOrArray.length; type++)
0 < type && (objKind += ", "),
(i = objectOrArray[type]),
(i =
"object" === typeof i && null !== i
? describeObjectForErrorMessage(i)
: describeValueForErrorMessage(i)),
"" + type === expandedName
? ((start = objKind.length),
(length = i.length),
(objKind += i))
: (objKind =
10 > i.length && 40 > objKind.length + i.length
? objKind + i
: objKind + "...");
objKind += "]";
}
else if (objectOrArray.$$typeof === REACT_ELEMENT_TYPE)
objKind = "<" + describeElementType(objectOrArray.type) + "/>";
else {
if (objectOrArray.$$typeof === CLIENT_REFERENCE_TAG) return "client";
if (jsxPropsParents.has(objectOrArray)) {
objKind = jsxPropsParents.get(objectOrArray);
objKind = "<" + (describeElementType(objKind) || "...");
type = Object.keys(objectOrArray);
for (i = 0; i < type.length; i++) {
objKind += " ";
value = type[i];
objKind += describeKeyForErrorMessage(value) + "=";
var _value2 = objectOrArray[value];
var _substr2 =
value === expandedName &&
"object" === typeof _value2 &&
null !== _value2
? describeObjectForErrorMessage(_value2)
: describeValueForErrorMessage(_value2);
"string" !== typeof _value2 && (_substr2 = "{" + _substr2 + "}");
value === expandedName
? ((start = objKind.length),
(length = _substr2.length),
(objKind += _substr2))
: (objKind =
10 > _substr2.length && 40 > objKind.length + _substr2.length
? objKind + _substr2
: objKind + "...");
}
objKind += ">";
} else {
objKind = "{";
type = Object.keys(objectOrArray);
for (i = 0; i < type.length; i++)
0 < i && (objKind += ", "),
(value = type[i]),
(objKind += describeKeyForErrorMessage(value) + ": "),
(_value2 = objectOrArray[value]),
(_value2 =
"object" === typeof _value2 && null !== _value2
? describeObjectForErrorMessage(_value2)
: describeValueForErrorMessage(_value2)),
value === expandedName
? ((start = objKind.length),
(length = _value2.length),
(objKind += _value2))
: (objKind =
10 > _value2.length && 40 > objKind.length + _value2.length
? objKind + _value2
: objKind + "...");
objKind += "}";
}
}
return void 0 === expandedName
? objKind
: -1 < start && 0 < length
? ((objectOrArray = " ".repeat(start) + "^".repeat(length)),
"\n " + objKind + "\n " + objectOrArray)
: "\n " + objKind;
}
function defaultFilterStackFrame(filename) {
return (
"" !== filename &&
!filename.startsWith("node:") &&
!filename.includes("node_modules")
);
}
function filterStackTrace(request, error, skipFrames) {
request = request.filterStackFrame;
error = parseStackTrace(error, skipFrames);
for (skipFrames = 0; skipFrames < error.length; skipFrames++) {
var callsite = error[skipFrames],
functionName = callsite[0],
url = callsite[1];
if (url.startsWith("rsc://React/")) {
var envIdx = url.indexOf("/", 12),
suffixIdx = url.lastIndexOf("?");
-1 < envIdx &&
-1 < suffixIdx &&
(url = callsite[1] = url.slice(envIdx + 1, suffixIdx));
}
request(url, functionName) ||
(error.splice(skipFrames, 1), skipFrames--);
}
return error;
}
function patchConsole(consoleInst, methodName) {
var descriptor = Object.getOwnPropertyDescriptor(consoleInst, methodName);
if (
descriptor &&
(descriptor.configurable || descriptor.writable) &&
"function" === typeof descriptor.value
) {
var originalMethod = descriptor.value;
descriptor = Object.getOwnPropertyDescriptor(originalMethod, "name");
var wrapperMethod = function () {
var request = resolveRequest();
if (("assert" !== methodName || !arguments[0]) && null !== request) {
var stack = filterStackTrace(
request,
Error("react-stack-top-frame"),
1
);
request.pendingChunks++;
var owner = resolveOwner();
emitConsoleChunk(request, methodName, owner, stack, arguments);
}
return originalMethod.apply(this, arguments);
};
descriptor && Object.defineProperty(wrapperMethod, "name", descriptor);
Object.defineProperty(consoleInst, methodName, {
value: wrapperMethod
});
}
}
function getCurrentStackInDEV() {
var owner = resolveOwner();
if (null === owner) return "";
try {
var info = "";
if (owner.owner || "string" !== typeof owner.name) {
for (; owner; ) {
var ownerStack = owner.debugStack;
if (null != ownerStack) {
if ((owner = owner.owner)) {
var JSCompiler_temp_const = info;
var error = ownerStack,
prevPrepareStackTrace = Error.prepareStackTrace;
Error.prepareStackTrace = prepareStackTrace;
var stack = error.stack;
Error.prepareStackTrace = prevPrepareStackTrace;
stack.startsWith("Error: react-stack-top-frame\n") &&
(stack = stack.slice(29));
var idx = stack.indexOf("\n");
-1 !== idx && (stack = stack.slice(idx + 1));
idx = stack.indexOf("react-stack-bottom-frame");
-1 !== idx && (idx = stack.lastIndexOf("\n", idx));
var JSCompiler_inline_result =
-1 !== idx ? (stack = stack.slice(0, idx)) : "";
info =
JSCompiler_temp_const + ("\n" + JSCompiler_inline_result);
}
} else break;
}
var JSCompiler_inline_result$jscomp$0 = info;
} else {
JSCompiler_temp_const = owner.name;
if (void 0 === prefix)
try {
throw Error();
} catch (x) {
(prefix =
((error = x.stack.trim().match(/\n( *(at )?)/)) && error[1]) ||
""),
(suffix =
-1 < x.stack.indexOf("\n at")
? " (<anonymous>)"
: -1 < x.stack.indexOf("@")
? "@unknown:0:0"
: "");
}
JSCompiler_inline_result$jscomp$0 =
"\n" + prefix + JSCompiler_temp_const + suffix;
}
} catch (x) {
JSCompiler_inline_result$jscomp$0 =
"\nError generating stack: " + x.message + "\n" + x.stack;
}
return JSCompiler_inline_result$jscomp$0;
}
function defaultErrorHandler(error) {
console.error(error);
}
function defaultPostponeHandler() {}
function RequestInstance(
type,
model,
bundlerConfig,
onError,
identifierPrefix,
onPostpone,
temporaryReferences,
environmentName,
filterStackFrame,
onAllReady,
onFatalError
) {
if (
null !== ReactSharedInternalsServer.A &&
ReactSharedInternalsServer.A !== DefaultAsyncDispatcher
)
throw Error(
"Currently React only supports one RSC renderer at a time."
);
ReactSharedInternalsServer.A = DefaultAsyncDispatcher;
ReactSharedInternalsServer.getCurrentStack = getCurrentStackInDEV;
var abortSet = new Set(),
pingedTasks = [],
hints = new Set();
this.type = type;
this.status = OPENING;
this.flushScheduled = !1;
this.destination = this.fatalError = null;
this.bundlerConfig = bundlerConfig;
this.cache = new Map();
this.pendingChunks = this.nextChunkId = 0;
this.hints = hints;
this.abortListeners = new Set();
this.abortableTasks = abortSet;
this.pingedTasks = pingedTasks;
this.completedImportChunks = [];
this.completedHintChunks = [];
this.completedRegularChunks = [];
this.completedErrorChunks = [];
this.writtenSymbols = new Map();
this.writtenClientReferences = new Map();
this.writtenServerReferences = new Map();
this.writtenObjects = new WeakMap();
this.temporaryReferences = temporaryReferences;
this.identifierPrefix = identifierPrefix || "";
this.identifierCount = 1;
this.taintCleanupQueue = [];
this.onError = void 0 === onError ? defaultErrorHandler : onError;
this.onPostpone =
void 0 === onPostpone ? defaultPostponeHandler : onPostpone;
this.onAllReady = onAllReady;
this.onFatalError = onFatalError;
this.environmentName =
void 0 === environmentName
? function () {
return "Server";
}
: "function" !== typeof environmentName
? function () {
return environmentName;
}
: environmentName;
this.filterStackFrame =
void 0 === filterStackFrame
? defaultFilterStackFrame
: filterStackFrame;
this.didWarnForKey = null;
type = createTask(this, model, null, !1, abortSet, null, null, null);
pingedTasks.push(type);
}
function noop() {}
function createRequest(
model,
bundlerConfig,
onError,
identifierPrefix,
onPostpone,
temporaryReferences,
environmentName,
filterStackFrame
) {
resetOwnerStackLimit();
return new RequestInstance(
20,
model,
bundlerConfig,
onError,
identifierPrefix,
onPostpone,
temporaryReferences,
environmentName,
filterStackFrame,
noop,
noop
);
}
function createPrerenderRequest(
model,
bundlerConfig,
onAllReady,
onFatalError,
onError,
identifierPrefix,
onPostpone,
temporaryReferences,
environmentName,
filterStackFrame
) {
resetOwnerStackLimit();
return new RequestInstance(
PRERENDER,
model,
bundlerConfig,
onError,
identifierPrefix,
onPostpone,
temporaryReferences,
environmentName,
filterStackFrame,
onAllReady,
onFatalError
);
}
function resolveRequest() {
if (currentRequest) return currentRequest;
var store = requestStorage.getStore();
return store ? store : null;
}
function serializeThenable(request, task, thenable) {
var newTask = createTask(
request,
null,
task.keyPath,
task.implicitSlot,
request.abortableTasks,
task.debugOwner,
task.debugStack,
task.debugTask
);
(task = thenable._debugInfo) &&
forwardDebugInfo(request, newTask.id, task);
switch (thenable.status) {
case "fulfilled":
return (
(newTask.model = thenable.value),
pingTask(request, newTask),
newTask.id
);
case "rejected":
return erroredTask(request, newTask, thenable.reason), newTask.id;
default:
if (request.status === ABORTING)
return (
request.abortableTasks.delete(newTask),
(newTask.status = ABORTED),
(task = stringify(serializeByValueID(request.fatalError))),
emitModelChunk(request, newTask.id, task),
newTask.id
);
"string" !== typeof thenable.status &&
((thenable.status = "pending"),
thenable.then(
function (fulfilledValue) {
"pending" === thenable.status &&
((thenable.status = "fulfilled"),
(thenable.value = fulfilledValue));
},
function (error) {
"pending" === thenable.status &&
((thenable.status = "rejected"), (thenable.reason = error));
}
));
}
thenable.then(
function (value) {
newTask.model = value;
pingTask(request, newTask);
},
function (reason) {
newTask.status === PENDING$1 &&
(erroredTask(request, newTask, reason), enqueueFlush(request));
}
);
return newTask.id;
}
function serializeReadableStream(request, task, stream) {
function progress(entry) {
if (!aborted)
if (entry.done)
request.abortListeners.delete(abortStream),
(entry = streamTask.id.toString(16) + ":C\n"),
request.completedRegularChunks.push(entry),
enqueueFlush(request),
(aborted = !0);
else
try {
(streamTask.model = entry.value),
request.pendingChunks++,
tryStreamTask(request, streamTask),
enqueueFlush(request),
reader.read().then(progress, error);
} catch (x$0) {
error(x$0);
}
}
function error(reason) {
aborted ||
((aborted = !0),
request.abortListeners.delete(abortStream),
erroredTask(request, streamTask, reason),
enqueueFlush(request),
reader.cancel(reason).then(error, error));
}
function abortStream(reason) {
aborted ||
((aborted = !0),
request.abortListeners.delete(abortStream),
erroredTask(request, streamTask, reason),
enqueueFlush(request),
reader.cancel(reason).then(error, error));
}
var supportsBYOB = stream.supportsBYOB;
if (void 0 === supportsBYOB)
try {
stream.getReader({ mode: "byob" }).releaseLock(), (supportsBYOB = !0);
} catch (x) {
supportsBYOB = !1;
}
var reader = stream.getReader(),
streamTask = createTask(
request,
task.model,
task.keyPath,
task.implicitSlot,
request.abortableTasks,
task.debugOwner,
task.debugStack,
task.debugTask
);
request.abortableTasks.delete(streamTask);
request.pendingChunks++;
task =
streamTask.id.toString(16) + ":" + (supportsBYOB ? "r" : "R") + "\n";
request.completedRegularChunks.push(task);
var aborted = !1;
request.abortListeners.add(abortStream);
reader.read().then(progress, error);
return serializeByValueID(streamTask.id);
}
function serializeAsyncIterable(request, task, iterable, iterator) {
function progress(entry) {
if (!aborted)
if (entry.done) {
request.abortListeners.delete(abortIterable);
if (void 0 === entry.value)
var endStreamRow = streamTask.id.toString(16) + ":C\n";
else
try {
var chunkId = outlineModel(request, entry.value);
endStreamRow =
streamTask.id.toString(16) +
":C" +
stringify(serializeByValueID(chunkId)) +
"\n";
} catch (x) {
error(x);
return;
}
request.completedRegularChunks.push(endStreamRow);
enqueueFlush(request);
aborted = !0;
} else
try {
(streamTask.model = entry.value),
request.pendingChunks++,
tryStreamTask(request, streamTask),
enqueueFlush(request),
callIteratorInDEV(iterator, progress, error);
} catch (x$1) {
error(x$1);
}
}
function error(reason) {
aborted ||
((aborted = !0),
request.abortListeners.delete(abortIterable),
erroredTask(request, streamTask, reason),
enqueueFlush(request),
"function" === typeof iterator.throw &&
iterator.throw(reason).then(error, error));
}
function abortIterable(reason) {
aborted ||
((aborted = !0),
request.abortListeners.delete(abortIterable),
erroredTask(request, streamTask, reason),
enqueueFlush(request),
"function" === typeof iterator.throw &&
iterator.throw(reason).then(error, error));
}
var isIterator = iterable === iterator,
streamTask = createTask(
request,
task.model,
task.keyPath,
task.implicitSlot,
request.abortableTasks,
task.debugOwner,
task.debugStack,
task.debugTask
);
request.abortableTasks.delete(streamTask);
request.pendingChunks++;
task = streamTask.id.toString(16) + ":" + (isIterator ? "x" : "X") + "\n";
request.completedRegularChunks.push(task);
(iterable = iterable._debugInfo) &&
forwardDebugInfo(request, streamTask.id, iterable);
var aborted = !1;
request.abortListeners.add(abortIterable);
callIteratorInDEV(iterator, progress, error);
return serializeByValueID(streamTask.id);
}
function emitHint(request, code, model) {
model = stringify(model);
request.completedHintChunks.push(":H" + code + model + "\n");
enqueueFlush(request);
}
function readThenable(thenable) {
if ("fulfilled" === thenable.status) return thenable.value;
if ("rejected" === thenable.status) throw thenable.reason;
throw thenable;
}
function createLazyWrapperAroundWakeable(wakeable) {
switch (wakeable.status) {
case "fulfilled":
case "rejected":
break;
default:
"string" !== typeof wakeable.status &&
((wakeable.status = "pending"),
wakeable.then(
function (fulfilledValue) {
"pending" === wakeable.status &&
((wakeable.status = "fulfilled"),
(wakeable.value = fulfilledValue));
},
function (error) {
"pending" === wakeable.status &&
((wakeable.status = "rejected"), (wakeable.reason = error));
}
));
}
var lazyType = {
$$typeof: REACT_LAZY_TYPE,
_payload: wakeable,
_init: readThenable
};
lazyType._debugInfo = wakeable._debugInfo || [];
return lazyType;
}
function callWithDebugContextInDEV(request, task, callback, arg) {
var componentDebugInfo = {
name: "",
env: task.environmentName,
key: null,
owner: task.debugOwner
};
componentDebugInfo.stack =
null === task.debugStack
? null
: filterStackTrace(request, task.debugStack, 1);
componentDebugInfo.debugStack = task.debugStack;
request = componentDebugInfo.debugTask = task.debugTask;
currentOwner = componentDebugInfo;
try {
return request ? request.run(callback.bind(null, arg)) : callback(arg);
} finally {
currentOwner = null;
}
}
function processServerComponentReturnValue(
request,
task,
Component,
result
) {
if (
"object" !== typeof result ||
null === result ||
isClientReference(result)
)
return result;
if ("function" === typeof result.then)
return (
result.then(function (resolvedValue) {
"object" === typeof resolvedValue &&
null !== resolvedValue &&
resolvedValue.$$typeof === REACT_ELEMENT_TYPE &&
(resolvedValue._store.validated = 1);
}, voidHandler),
"fulfilled" === result.status
? result.value
: createLazyWrapperAroundWakeable(result)
);
result.$$typeof === REACT_ELEMENT_TYPE && (result._store.validated = 1);
var iteratorFn = getIteratorFn(result);
if (iteratorFn) {
var multiShot = _defineProperty({}, Symbol.iterator, function () {
var iterator = iteratorFn.call(result);
iterator !== result ||
("[object GeneratorFunction]" ===
Object.prototype.toString.call(Component) &&
"[object Generator]" ===
Object.prototype.toString.call(result)) ||
callWithDebugContextInDEV(request, task, function () {
console.error(
"Returning an Iterator from a Server Component is not supported since it cannot be looped over more than once. "
);
});
return iterator;
});
multiShot._debugInfo = result._debugInfo;
return multiShot;
}
return "function" !== typeof result[ASYNC_ITERATOR] ||
("function" === typeof ReadableStream &&
result instanceof ReadableStream)
? result
: ((multiShot = _defineProperty({}, ASYNC_ITERATOR, function () {
var iterator = result[ASYNC_ITERATOR]();
iterator !== result ||
("[object AsyncGeneratorFunction]" ===
Object.prototype.toString.call(Component) &&
"[object AsyncGenerator]" ===
Object.prototype.toString.call(result)) ||
callWithDebugContextInDEV(request, task, function () {
console.error(
"Returning an AsyncIterator from a Server Component is not supported since it cannot be looped over more than once. "
);
});
return iterator;
})),
(multiShot._debugInfo = result._debugInfo),
multiShot);
}
function renderFunctionComponent(
request,
task,
key,
Component,
props,
validated
) {
var prevThenableState = task.thenableState;
task.thenableState = null;
if (null === debugID) return outlineTask(request, task);
if (null !== prevThenableState)
var componentDebugInfo = prevThenableState._componentDebugInfo;
else {
var componentDebugID = debugID;
componentDebugInfo = Component.displayName || Component.name || "";
var componentEnv = (0, request.environmentName)();
request.pendingChunks++;
componentDebugInfo = {
name: componentDebugInfo,
env: componentEnv,
key: key,
owner: task.debugOwner
};
componentDebugInfo.stack =
null === task.debugStack
? null
: filterStackTrace(request, task.debugStack, 1);
componentDebugInfo.props = props;
componentDebugInfo.debugStack = task.debugStack;
componentDebugInfo.debugTask = task.debugTask;
outlineComponentInfo(request, componentDebugInfo);
emitDebugChunk(request, componentDebugID, componentDebugInfo);
task.environmentName = componentEnv;
2 === validated &&
warnForMissingKey(request, key, componentDebugInfo, task.debugTask);
}
thenableIndexCounter = 0;
thenableState = prevThenableState;
currentComponentDebugInfo = componentDebugInfo;
props = task.debugTask
? task.debugTask.run(
componentStorage.run.bind(
componentStorage,
componentDebugInfo,
callComponentInDEV,
Component,
props,
componentDebugInfo
)
)
: componentStorage.run(
componentDebugInfo,
callComponentInDEV,
Component,
props,
componentDebugInfo
);
if (request.status === ABORTING)
throw (
("object" !== typeof props ||
null === props ||
"function" !== typeof props.then ||
isClientReference(props) ||
props.then(voidHandler, voidHandler),
null)
);
props = processServerComponentReturnValue(
request,
task,
Component,
props
);
Component = task.keyPath;
validated = task.implicitSlot;
null !== key
? (task.keyPath = null === Component ? key : Component + "," + key)
: null === Component && (task.implicitSlot = !0);
request = renderModelDestructive(request, task, emptyRoot, "", props);
task.keyPath = Component;
task.implicitSlot = validated;
return request;
}
function warnForMissingKey(request, key, componentDebugInfo, debugTask) {
function logKeyError() {
console.error(
'Each child in a list should have a unique "key" prop.%s%s See https://react.dev/link/warning-keys for more information.',
"",
""
);
}
key = request.didWarnForKey;
null == key && (key = request.didWarnForKey = new WeakSet());
request = componentDebugInfo.owner;
if (null != request) {
if (key.has(request)) return;
key.add(request);
}
debugTask
? debugTask.run(
componentStorage.run.bind(
componentStorage,
componentDebugInfo,
callComponentInDEV,
logKeyError,
null,
componentDebugInfo
)
)
: componentStorage.run(
componentDebugInfo,
callComponentInDEV,
logKeyError,
null,
componentDebugInfo
);
}
function renderFragment(request, task, children) {
for (var i = 0; i < children.length; i++) {
var child = children[i];
null === child ||
"object" !== typeof child ||
child.$$typeof !== REACT_ELEMENT_TYPE ||
null !== child.key ||
child._store.validated ||
(child._store.validated = 2);
}
if (null !== task.keyPath)
return (
(request = [
REACT_ELEMENT_TYPE,
REACT_FRAGMENT_TYPE,
task.keyPath,
{ children: children },
null,
null,
0
]),
task.implicitSlot ? [request] : request
);
if ((i = children._debugInfo)) {
if (null === debugID) return outlineTask(request, task);
forwardDebugInfo(request, debugID, i);
children = Array.from(children);
}
return children;
}
function renderAsyncFragment(request, task, children, getAsyncIterator) {
if (null !== task.keyPath)
return (
(request = [
REACT_ELEMENT_TYPE,
REACT_FRAGMENT_TYPE,
task.keyPath,
{ children: children },
null,
null,
0
]),
task.implicitSlot ? [request] : request
);
getAsyncIterator = getAsyncIterator.call(children);
return serializeAsyncIterable(request, task, children, getAsyncIterator);
}
function outlineTask(request, task) {
task = createTask(
request,
task.model,
task.keyPath,
task.implicitSlot,
request.abortableTasks,
task.debugOwner,
task.debugStack,
task.debugTask
);
retryTask(request, task);
return task.status === COMPLETED
? serializeByValueID(task.id)
: "$L" + task.id.toString(16);
}
function renderElement(request, task, type, key, ref, props, validated) {
if (null !== ref && void 0 !== ref)
throw Error(
"Refs cannot be used in Server Components, nor passed to Client Components."
);
jsxPropsParents.set(props, type);
"object" === typeof props.children &&
null !== props.children &&
jsxChildrenParents.set(props.children, type);
if (
"function" !== typeof type ||
isClientReference(type) ||
type.$$typeof === TEMPORARY_REFERENCE_TAG
) {
if (type === REACT_FRAGMENT_TYPE && null === key)
return (
2 === validated &&
((validated = {
name: "Fragment",
env: (0, request.environmentName)(),
key: key,
owner: task.debugOwner,
stack:
null === task.debugStack
? null
: filterStackTrace(request, task.debugStack, 1),
props: props,
debugStack: task.debugStack,
debugTask: task.debugTask
}),
warnForMissingKey(request, key, validated, task.debugTask)),
(validated = task.implicitSlot),
null === task.keyPath && (task.implicitSlot = !0),
(request = renderModelDestructive(
request,
task,
emptyRoot,
"",
props.children
)),
(task.implicitSlot = validated),
request
);
if (
null != type &&
"object" === typeof type &&
!isClientReference(type)
)
switch (type.$$typeof) {
case REACT_LAZY_TYPE:
type = callLazyInitInDEV(type);
if (request.status === ABORTING) throw null;
return renderElement(
request,
task,
type,
key,
ref,
props,
validated
);
case REACT_FORWARD_REF_TYPE:
return renderFunctionComponent(
request,
task,
key,
type.render,
props,
validated
);
case REACT_MEMO_TYPE:
return renderElement(
request,
task,
type.type,
key,
ref,
props,
validated
);
case REACT_ELEMENT_TYPE:
type._store.validated = 1;
}
} else
return renderFunctionComponent(
request,
task,
key,
type,
props,
validated
);
ref = task.keyPath;
null === key ? (key = ref) : null !== ref && (key = ref + "," + key);
null !== task.debugOwner &&
outlineComponentInfo(request, task.debugOwner);
request = [
REACT_ELEMENT_TYPE,
type,
key,
props,
task.debugOwner,
null === task.debugStack
? null
: filterStackTrace(request, task.debugStack, 1),
validated
];
task = task.implicitSlot && null !== key ? [request] : request;
return task;
}
function pingTask(request, task) {
var pingedTasks = request.pingedTasks;
pingedTasks.push(task);
1 === pingedTasks.length &&
((request.flushScheduled = null !== request.destination),
request.type === PRERENDER || request.status === OPENING
? scheduleMicrotask(function () {
return performWork(request);
})
: setImmediate(function () {
return performWork(request);
}));
}
function createTask(
request,
model,
keyPath,
implicitSlot,
abortSet,
debugOwner,
debugStack,
debugTask
) {
reques