| Server IP : 159.203.156.69 / Your IP : 216.73.217.172 Web Server : nginx/1.24.0 System : Linux main-ubuntu 6.8.0-71-generic #71-Ubuntu SMP PREEMPT_DYNAMIC Tue Jul 22 16:52:38 UTC 2025 x86_64 User : root ( 0) PHP Version : 8.3.6 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/tanviranik.com/node_modules/vinext/dist/server/ |
Upload File : |
import { createArtifactCompatibilityEnvelope, parseArtifactCompatibilityEnvelope } from "./artifact-compatibility.js";
import { isValidElement } from "react";
//#region src/server/app-elements-wire.ts
const APP_INTERCEPTION_SEPARATOR = "\0";
const APP_ARTIFACT_COMPATIBILITY_KEY = "__artifactCompatibility";
const APP_INTERCEPTION_CONTEXT_KEY = "__interceptionContext";
const APP_LAYOUT_IDS_KEY = "__layoutIds";
const APP_LAYOUT_FLAGS_KEY = "__layoutFlags";
const APP_ROUTE_KEY = "__route";
const APP_ROOT_LAYOUT_KEY = "__rootLayout";
const APP_UNMATCHED_SLOT_WIRE_VALUE = "__VINEXT_UNMATCHED_SLOT__";
const UNMATCHED_SLOT = Symbol.for("vinext.unmatchedSlot");
function appendInterceptionContext(identity, interceptionContext) {
return interceptionContext === null ? identity : `${identity}${APP_INTERCEPTION_SEPARATOR}${interceptionContext}`;
}
function createAppPayloadRouteId(routePath, interceptionContext) {
return appendInterceptionContext(`route:${routePath}`, interceptionContext);
}
function createAppPayloadPageId(routePath, interceptionContext) {
return appendInterceptionContext(`page:${routePath}`, interceptionContext);
}
function createAppPayloadLayoutId(treePath) {
return `layout:${treePath}`;
}
function createAppPayloadTemplateId(treePath) {
return `template:${treePath}`;
}
function createAppPayloadSlotId(slotName, treePath) {
return `slot:${slotName}:${treePath}`;
}
function createAppPayloadCacheKey(rscUrl, interceptionContext) {
return appendInterceptionContext(rscUrl, interceptionContext);
}
function parsePathWithInterception(input) {
const separatorIndex = input.indexOf(APP_INTERCEPTION_SEPARATOR);
const path = separatorIndex === -1 ? input : input.slice(0, separatorIndex);
if (!path.startsWith("/")) return null;
return {
interceptionContext: separatorIndex === -1 ? null : input.slice(separatorIndex + 1),
path
};
}
/**
* AppElements tree paths are absolute route-tree paths on the wire.
* Bare segment names are not valid layout/template/slot tree identities.
*/
function parseTreePath(input) {
return input.startsWith("/") ? input : null;
}
function parseAppElementsWireElementKey(key) {
if (key.startsWith("route:")) {
const parsed = parsePathWithInterception(key.slice(6));
if (!parsed) return null;
return {
interceptionContext: parsed.interceptionContext,
kind: "route",
path: parsed.path
};
}
if (key.startsWith("page:")) {
const parsed = parsePathWithInterception(key.slice(5));
if (!parsed) return null;
return {
interceptionContext: parsed.interceptionContext,
kind: "page",
path: parsed.path
};
}
if (key.startsWith("layout:")) {
const treePath = parseTreePath(key.slice(7));
return treePath ? {
kind: "layout",
treePath
} : null;
}
if (key.startsWith("template:")) {
const treePath = parseTreePath(key.slice(9));
return treePath ? {
kind: "template",
treePath
} : null;
}
if (key.startsWith("slot:")) {
const body = key.slice(5);
const separatorIndex = body.indexOf(":");
if (separatorIndex <= 0) return null;
const name = body.slice(0, separatorIndex);
const treePath = parseTreePath(body.slice(separatorIndex + 1));
return treePath ? {
kind: "slot",
name,
treePath
} : null;
}
return null;
}
function isAppElementsWireSlotId(key) {
if (!key.startsWith("slot:")) return false;
const body = key.slice(5);
const separatorIndex = body.indexOf(":");
return separatorIndex > 0 && body.charCodeAt(separatorIndex + 1) === 47;
}
function createAppElementsWireMetadataEntries(input) {
return {
[APP_ROUTE_KEY]: input.routeId,
[APP_INTERCEPTION_CONTEXT_KEY]: input.interceptionContext,
[APP_LAYOUT_IDS_KEY]: [...input.layoutIds ?? []],
[APP_ROOT_LAYOUT_KEY]: input.rootLayoutTreePath
};
}
function normalizeAppElements(elements) {
let needsNormalization = false;
for (const [key, value] of Object.entries(elements)) if (isAppElementsWireSlotId(key) && value === "__VINEXT_UNMATCHED_SLOT__") {
needsNormalization = true;
break;
}
if (!needsNormalization) return elements;
const normalized = {};
for (const [key, value] of Object.entries(elements)) normalized[key] = isAppElementsWireSlotId(key) && value === "__VINEXT_UNMATCHED_SLOT__" ? UNMATCHED_SLOT : value;
return normalized;
}
function isLayoutFlagsRecord(value) {
if (typeof value !== "object" || value === null || Array.isArray(value)) return false;
for (const v of Object.values(value)) if (v !== "s" && v !== "d") return false;
return true;
}
function parseLayoutFlags(value) {
if (isLayoutFlagsRecord(value)) return value;
return {};
}
function parseLayoutIds(value) {
if (value === void 0) return [];
if (!Array.isArray(value)) throw new Error("[vinext] Invalid __layoutIds in App Router payload: expected layout id string[]");
const layoutIds = [];
for (const entry of value) {
if (typeof entry !== "string") throw new Error("[vinext] Invalid __layoutIds in App Router payload: expected layout id string[]");
if (parseAppElementsWireElementKey(entry)?.kind !== "layout") throw new Error("[vinext] Invalid __layoutIds in App Router payload: expected layout ids");
layoutIds.push(entry);
}
return layoutIds;
}
/**
* Type predicate for a plain (non-null, non-array) record of app payload values.
* Used to distinguish the App Router payload object from bare React elements at
* the render boundary. Narrows to `Readonly<Record<string, unknown>>` because
* the outgoing payload carries heterogeneous values (ReactNodes for the rendered
* tree, plus metadata like `__layoutFlags` which is a plain object). Delegates
* to React's canonical `isValidElement` so we don't depend on React's internal
* `$$typeof` marker scheme.
*/
function isAppElementsRecord(value) {
if (typeof value !== "object" || value === null) return false;
if (Array.isArray(value)) return false;
if (isValidElement(value)) return false;
return true;
}
function withLayoutFlags(elements, layoutFlags) {
return {
...elements,
[APP_LAYOUT_FLAGS_KEY]: layoutFlags
};
}
function buildOutgoingAppPayload(input) {
if (!isAppElementsRecord(input.element)) return input.element;
return {
...input.element,
[APP_LAYOUT_FLAGS_KEY]: input.layoutFlags,
[APP_ARTIFACT_COMPATIBILITY_KEY]: input.artifactCompatibility ?? createArtifactCompatibilityEnvelope()
};
}
function readArtifactCompatibilityMetadata(value) {
if (value === void 0) return createArtifactCompatibilityEnvelope();
return parseArtifactCompatibilityEnvelope(value) ?? createArtifactCompatibilityEnvelope();
}
function readAppElementsMetadata(elements) {
const routeId = elements[APP_ROUTE_KEY];
if (typeof routeId !== "string") throw new Error("[vinext] Missing __route string in App Router payload");
const interceptionContext = elements[APP_INTERCEPTION_CONTEXT_KEY];
if (interceptionContext !== void 0 && interceptionContext !== null && typeof interceptionContext !== "string") throw new Error("[vinext] Invalid __interceptionContext in App Router payload");
const rootLayoutTreePath = elements[APP_ROOT_LAYOUT_KEY];
if (rootLayoutTreePath === void 0) throw new Error("[vinext] Missing __rootLayout key in App Router payload");
if (rootLayoutTreePath !== null && typeof rootLayoutTreePath !== "string") throw new Error("[vinext] Invalid __rootLayout in App Router payload: expected string or null");
const layoutFlags = parseLayoutFlags(elements[APP_LAYOUT_FLAGS_KEY]);
const layoutIds = parseLayoutIds(elements[APP_LAYOUT_IDS_KEY]);
return {
artifactCompatibility: readArtifactCompatibilityMetadata(elements[APP_ARTIFACT_COMPATIBILITY_KEY]),
interceptionContext: interceptionContext ?? null,
layoutIds,
layoutFlags,
routeId,
rootLayoutTreePath
};
}
const AppElementsWire = {
keys: {
artifactCompatibility: APP_ARTIFACT_COMPATIBILITY_KEY,
interceptionContext: APP_INTERCEPTION_CONTEXT_KEY,
layoutIds: APP_LAYOUT_IDS_KEY,
layoutFlags: APP_LAYOUT_FLAGS_KEY,
rootLayout: APP_ROOT_LAYOUT_KEY,
route: APP_ROUTE_KEY
},
unmatchedSlotValue: APP_UNMATCHED_SLOT_WIRE_VALUE,
createMetadataEntries: createAppElementsWireMetadataEntries,
decode: normalizeAppElements,
encodeCacheKey: createAppPayloadCacheKey,
encodeLayoutId: createAppPayloadLayoutId,
encodeOutgoingPayload: buildOutgoingAppPayload,
encodePageId: createAppPayloadPageId,
encodeRouteId: createAppPayloadRouteId,
encodeSlotId: createAppPayloadSlotId,
encodeTemplateId: createAppPayloadTemplateId,
isSlotId: isAppElementsWireSlotId,
parseElementKey: parseAppElementsWireElementKey,
readMetadata: readAppElementsMetadata,
withLayoutFlags
};
//#endregion
export { APP_ARTIFACT_COMPATIBILITY_KEY, APP_INTERCEPTION_CONTEXT_KEY, APP_LAYOUT_FLAGS_KEY, APP_LAYOUT_IDS_KEY, APP_ROOT_LAYOUT_KEY, APP_ROUTE_KEY, APP_UNMATCHED_SLOT_WIRE_VALUE, AppElementsWire, UNMATCHED_SLOT, buildOutgoingAppPayload, isAppElementsRecord, normalizeAppElements, readAppElementsMetadata, withLayoutFlags };
//# sourceMappingURL=app-elements-wire.js.map