@webtypen/webframez-react 0.0.31 → 0.0.33
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client.cjs +1 -1
- package/dist/client.d.ts +1 -0
- package/dist/client.js +1 -1
- package/dist/http.cjs +66 -9
- package/dist/http.js +66 -9
- package/dist/index.cjs +66 -9
- package/dist/index.js +66 -9
- package/dist/route-slot.cjs +53 -0
- package/dist/route-slot.d.ts +7 -0
- package/dist/route-slot.js +19 -0
- package/dist/router.cjs +44 -7
- package/dist/router.d.ts +2 -0
- package/dist/router.js +44 -7
- package/dist/types.d.ts +5 -0
- package/dist/webframez-core.cjs +66 -9
- package/dist/webframez-core.js +66 -9
- package/package.json +6 -1
package/dist/client.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var ae=Object.create;var y=Object.defineProperty;var se=Object.getOwnPropertyDescriptor;var ce=Object.getOwnPropertyNames;var de=Object.getPrototypeOf,ue=Object.prototype.hasOwnProperty;var le=(e,t)=>{for(var n in t)y(e,n,{get:t[n],enumerable:!0})},L=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of ce(t))!ue.call(e,r)&&r!==n&&y(e,r,{get:()=>t[r],enumerable:!(o=se(t,r))||o.enumerable});return e};var H=(e,t,n)=>(n=e!=null?ae(de(e)):{},L(t||!e||!e.__esModule?y(n,"default",{value:e,enumerable:!0}):n,e)),fe=e=>L(y({},"__esModule",{value:!0}),e);var ve={};le(ve,{mountWebframezClient:()=>xe,useCookie:()=>ye,useRouter:()=>Ee});module.exports=fe(ve);var s=H(require("react"),1),Y=require("react-dom/client"),g=require("react-server-dom-webpack/client"),Z=require("@webtypen/webframez-react/route-slot");var pe=/^(?:[a-zA-Z][a-zA-Z\d+\-.]*:|\/\/|#)/;function u(e){if(typeof e!="string")return;let t=e.trim();return!t||t==="/"?"":t.replace(/\/+$/,"")}function U(e,t){let n=e.trim(),o=u(t);return!n||!o||pe.test(n)||n.startsWith("/")||o!=="/"&&(n===o||n.startsWith(`${o}/`))?n:o==="/"?n.startsWith("/")?n:`/${n}`:n.startsWith("/")?`${o}${n}`:`${o}/${n}`}function S(e,t){if(!e)return;let n=u(e.basename)??u(t),o=u(e.routeBasePath),r=u(e.transportBasePath),a={...e,...n!==void 0?{basename:n}:{},...o!==void 0?{routeBasePath:o}:{},...r!==void 0?{transportBasePath:r}:{}};return a.favicon&&(a.favicon=U(a.favicon,n)),a.links&&(a.links=a.links.map(c=>({...c,href:U(c.href,n)}))),a}var R=H(require("react"),1),$="webframez-route-children",W="__webframezRouteChildren",D="WebframezRouteChildren",N=()=>R.default.createElement($);N.displayName=D;N[W]=!0;var me=N;function z(e){if(e===$||e===me)return!0;if(!e||typeof e!="function"&&typeof e!="object")return!1;try{let t=e;return t[W]===!0||t.displayName===D||t.name==="RouteChildren"}catch{return!1}}function M(e){if(!e||typeof e!="object")return!1;try{return"type"in e&&"props"in e}catch{return!1}}function E(e,t){if(e==null||typeof e=="boolean")return e;if(Array.isArray(e)){let m=!1,f=e.map(p=>{let h=E(p,t);return h!==p&&(m=!0),h});return m?f:e}if(M(e)&&z(e.type))return t;let n=R.default.isValidElement(e);if(!n&&!M(e))return e;if(n&&z(e.type))return t;let o=e.props??{};if(!("children"in o))return e;let r=E(o.children,t);if(r===o.children)return e;if(n)return Array.isArray(r)?R.default.cloneElement(e,void 0,...r):R.default.cloneElement(e,void 0,r);let a=e,c={...a.props??{},children:r,...a.key!==void 0&&a.key!==null?{key:a.key}:{}};return R.default.createElement(a.type,c)}var d=require("react/jsx-runtime"),Re={push:()=>{},replace:()=>{},refresh:()=>{},refreshContext:()=>{}},A=typeof s.default.createContext=="function"?s.default.createContext(null):null,K="__WEBFRAMEZ_ROUTER__",ge="[data-webframez-head='true']";function v(e){return u(e)??""}function he(e,t){return t?e===t?"/":e.startsWith(`${t}/`)?e.slice(t.length)||"/":e||"/":e||"/"}function V(e,t){let n=!t||t==="/"?"/":t.startsWith("/")?t:`/${t}`;return e?n==="/"?e:`${e}${n}`:n}function _e(){return v(typeof window>"u"?globalThis.__RSC_ROUTE_BASE_PATH:window.__RSC_ROUTE_BASE_PATH)}function X(e){if(typeof window>"u")return e||"/";let t=v(window.__RSC_BASENAME),n=_e(),o=he(e||"/",t);return V(n,o)}function J(e){if(typeof window>"u")return e;let t=window.__RSC_ENDPOINT;return typeof t=="string"&&t.trim()!==""?t:e}function we(){return typeof window>"u"?null:window[K]??null}function Ce(e){typeof window>"u"||(window[K]=e)}function F(){let e={},t=typeof document>"u"?"":document.cookie;if(!t||t.trim()==="")return e;for(let n of t.split(";")){let o=n.trim();if(!o)continue;let r=o.indexOf("="),a=r>=0?o.slice(0,r).trim():o,c=r>=0?o.slice(r+1):"";a&&(e[a]=decodeURIComponent(c))}return e}function j(e,t,n={}){let o=[`${e}=${encodeURIComponent(t)}`];return n.path&&o.push(`Path=${n.path}`),n.domain&&o.push(`Domain=${n.domain}`),typeof n.maxAge=="number"&&o.push(`Max-Age=${Math.floor(n.maxAge)}`),n.expires&&o.push(`Expires=${n.expires.toUTCString()}`),n.sameSite&&o.push(`SameSite=${n.sameSite}`),n.secure&&o.push("Secure"),o.join("; ")}function ye(){return s.default.useMemo(()=>({all:()=>F(),get:e=>F()[e],set:(e,t,n)=>{typeof document>"u"||(document.cookie=j(e,t,n))},remove:(e,t)=>{typeof document>"u"||(document.cookie=j(e,"",{...t??{},maxAge:0}))}}),[])}function Ee(){let e=A?s.default.useContext(A):null;if(!e){let t=we();if(t)return t;if(typeof window>"u")return Re;throw new Error("useRouter must be used inside mountWebframezClient()")}return e}function Ae({active:e}){return(0,d.jsx)("div",{style:{position:"fixed",top:0,left:0,width:"100%",height:3,zIndex:9999,transformOrigin:"left",transform:e?"scaleX(1)":"scaleX(0)",transition:"transform 180ms ease",background:"linear-gradient(90deg, #0ea5e9, #22c55e)"}})}function G(e){let t=document.createElement("meta");t.setAttribute("data-webframez-head","true");let n=Object.entries(e).filter(([,o])=>!!o);for(let[o,r]of n)t.setAttribute(o,String(r));document.head.appendChild(t)}function q(e){let t=document.createElement("link");t.setAttribute("data-webframez-head","true");let n=Object.entries(e).filter(([,o])=>!!o);for(let[o,r]of n)t.setAttribute(o,String(r));document.head.appendChild(t)}function x(e){if(typeof document>"u")return;let t=S(e)??e;Q(t),document.title=t.title||"Webframez React";for(let n of document.head.querySelectorAll(ge))n.remove();t.description&&G({name:"description",content:t.description}),t.favicon&&q({rel:"icon",href:t.favicon});for(let n of t.meta??[])G(n);for(let n of t.links??[])q(n)}function Q(e){if(typeof window>"u")return;let t=S(e)??e,n=u(t.basename),o=u(t.routeBasePath),r=u(t.transportBasePath);window.__RSC_BASENAME=n??"",window.__RSC_ROUTE_BASE_PATH=o??"",r!==void 0&&(window.__RSC_ENDPOINT=V(r,"/rsc"))}function Pe(e){let t=new TextEncoder;return new ReadableStream({start(n){n.enqueue(t.encode(e)),n.close()}})}function Te(){if(typeof window>"u")return null;let e=window.__RSC_INITIAL_PAYLOAD;return typeof e!="string"||e===""?null:(delete window.__RSC_INITIAL_PAYLOAD,(0,g.createFromReadableStream)(Pe(e)))}function Se(e){let t=J(e),n=X(window.location.pathname);return Te()??(0,g.createFromFetch)(fetch(`${t}?path=${encodeURIComponent(n)}&search=${encodeURIComponent(window.location.search)}`,{cache:"no-store",credentials:"same-origin",headers:{Accept:"text/x-component"}}))}function Ne(e,t){return function(){let o=s.default.use(e),r=typeof o.contextModel<"u"&&typeof o.pageModel<"u",[a,c]=(0,s.useState)(o.model),[m,f]=(0,s.useState)(o.contextModel),[p,h]=(0,s.useState)(o.pageModel),[I,b]=(0,s.useState)(o.head),[ee,_]=(0,s.useState)(!1),[te,ne]=(0,s.useState)(!1),[oe,P]=(0,s.useState)(r);async function O(i){let C=J(t),l=X(i.pathname);return await(0,g.createFromFetch)(fetch(`${C}?path=${encodeURIComponent(l)}&search=${encodeURIComponent(i.search)}`,{cache:"no-store",credentials:"same-origin",headers:{Accept:"text/x-component"}}))}async function w(i,C="push"){_(!0);try{let l=await O(i);x(l.head),b(l.head),c(l.model),f(l.contextModel),h(l.pageModel),P(!0);let T=`${i.pathname}${i.search}`;C==="replace"?history.replaceState(null,"",T):C==="push"&&history.pushState(null,"",T)}catch(l){console.error("[webframez-react] Failed to render route",l),c((0,d.jsx)("p",{children:"Failed to load route."}))}finally{_(!1)}}async function re(){_(!0);try{let i=await O(new URL(window.location.href));if(x(i.head),b(i.head),Object.prototype.hasOwnProperty.call(i,"contextModel")){f(i.contextModel),P(!0);return}c(i.model),P(!1)}catch(i){console.error("[webframez-react] Failed to refresh route context",i)}finally{_(!1)}}(0,s.useEffect)(()=>{x(I)},[I]),(0,s.useEffect)(()=>{ne(!0);let i=()=>{w(new URL(window.location.href),"none")};return window.addEventListener("popstate",i),()=>{window.removeEventListener("popstate",i)}},[]);let k=s.default.useMemo(()=>({push:i=>{w(new URL(i,window.location.origin),"push")},replace:i=>{w(new URL(i,window.location.origin),"replace")},refresh:()=>{w(new URL(window.location.href),"none")},refreshContext:()=>{re()}}),[]);Ce(k);let ie=oe&&typeof p<"u"?m?(0,d.jsx)(Z.RouteChildrenSlotProvider,{page:p,children:E(m,p)}):p:a,B=(0,d.jsxs)(d.Fragment,{children:[te?(0,d.jsx)(Ae,{active:ee}):null,ie??(0,d.jsx)("p",{style:{padding:24},children:"Loading..."})]});return A?(0,d.jsx)(A.Provider,{value:k,children:B}):B}}function xe(e={}){let t=e.rootId??"root",n=document.getElementById(t);if(!n)throw new Error(`Missing #${t} element`);let o=typeof window<"u"&&window.__RSC_ENDPOINT,r=e.rscEndpoint??o??"/rsc",a=Promise.resolve(Se(r)).then(f=>(f?.head&&Q(f.head),f)),c=Ne(a,r);return(0,Y.hydrateRoot)(n,(0,d.jsx)(c,{}))}
|
package/dist/client.d.ts
CHANGED
package/dist/client.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import
|
|
1
|
+
import R,{useEffect as $,useState as f}from"react";import{hydrateRoot as ie}from"react-dom/client";import{createFromFetch as G,createFromReadableStream as ae}from"react-server-dom-webpack/client";import{RouteChildrenSlotProvider as se}from"@webtypen/webframez-react/route-slot";var oe=/^(?:[a-zA-Z][a-zA-Z\d+\-.]*:|\/\/|#)/;function c(e){if(typeof e!="string")return;let t=e.trim();return!t||t==="/"?"":t.replace(/\/+$/,"")}function B(e,t){let n=e.trim(),o=c(t);return!n||!o||oe.test(n)||n.startsWith("/")||o!=="/"&&(n===o||n.startsWith(`${o}/`))?n:o==="/"?n.startsWith("/")?n:`/${n}`:n.startsWith("/")?`${o}${n}`:`${o}/${n}`}function T(e,t){if(!e)return;let n=c(e.basename)??c(t),o=c(e.routeBasePath),r=c(e.transportBasePath),a={...e,...n!==void 0?{basename:n}:{},...o!==void 0?{routeBasePath:o}:{},...r!==void 0?{transportBasePath:r}:{}};return a.favicon&&(a.favicon=B(a.favicon,n)),a.links&&(a.links=a.links.map(s=>({...s,href:B(s.href,n)}))),a}import g from"react";var U="webframez-route-children",z="__webframezRouteChildren",M="WebframezRouteChildren",S=()=>g.createElement(U);S.displayName=M;S[z]=!0;var re=S;function L(e){if(e===U||e===re)return!0;if(!e||typeof e!="function"&&typeof e!="object")return!1;try{let t=e;return t[z]===!0||t.displayName===M||t.name==="RouteChildren"}catch{return!1}}function H(e){if(!e||typeof e!="object")return!1;try{return"type"in e&&"props"in e}catch{return!1}}function y(e,t){if(e==null||typeof e=="boolean")return e;if(Array.isArray(e)){let m=!1,u=e.map(l=>{let h=y(l,t);return h!==l&&(m=!0),h});return m?u:e}if(H(e)&&L(e.type))return t;let n=g.isValidElement(e);if(!n&&!H(e))return e;if(n&&L(e.type))return t;let o=e.props??{};if(!("children"in o))return e;let r=y(o.children,t);if(r===o.children)return e;if(n)return Array.isArray(r)?g.cloneElement(e,void 0,...r):g.cloneElement(e,void 0,r);let a=e,s={...a.props??{},children:r,...a.key!==void 0&&a.key!==null?{key:a.key}:{}};return g.createElement(a.type,s)}import{Fragment as we,jsx as p,jsxs as Ce}from"react/jsx-runtime";var ce={push:()=>{},replace:()=>{},refresh:()=>{},refreshContext:()=>{}},E=typeof R.createContext=="function"?R.createContext(null):null,q="__WEBFRAMEZ_ROUTER__",de="[data-webframez-head='true']";function x(e){return c(e)??""}function ue(e,t){return t?e===t?"/":e.startsWith(`${t}/`)?e.slice(t.length)||"/":e||"/":e||"/"}function Y(e,t){let n=!t||t==="/"?"/":t.startsWith("/")?t:`/${t}`;return e?n==="/"?e:`${e}${n}`:n}function le(){return x(typeof window>"u"?globalThis.__RSC_ROUTE_BASE_PATH:window.__RSC_ROUTE_BASE_PATH)}function Z(e){if(typeof window>"u")return e||"/";let t=x(window.__RSC_BASENAME),n=le(),o=ue(e||"/",t);return Y(n,o)}function K(e){if(typeof window>"u")return e;let t=window.__RSC_ENDPOINT;return typeof t=="string"&&t.trim()!==""?t:e}function fe(){return typeof window>"u"?null:window[q]??null}function pe(e){typeof window>"u"||(window[q]=e)}function W(){let e={},t=typeof document>"u"?"":document.cookie;if(!t||t.trim()==="")return e;for(let n of t.split(";")){let o=n.trim();if(!o)continue;let r=o.indexOf("="),a=r>=0?o.slice(0,r).trim():o,s=r>=0?o.slice(r+1):"";a&&(e[a]=decodeURIComponent(s))}return e}function D(e,t,n={}){let o=[`${e}=${encodeURIComponent(t)}`];return n.path&&o.push(`Path=${n.path}`),n.domain&&o.push(`Domain=${n.domain}`),typeof n.maxAge=="number"&&o.push(`Max-Age=${Math.floor(n.maxAge)}`),n.expires&&o.push(`Expires=${n.expires.toUTCString()}`),n.sameSite&&o.push(`SameSite=${n.sameSite}`),n.secure&&o.push("Secure"),o.join("; ")}function Ie(){return R.useMemo(()=>({all:()=>W(),get:e=>W()[e],set:(e,t,n)=>{typeof document>"u"||(document.cookie=D(e,t,n))},remove:(e,t)=>{typeof document>"u"||(document.cookie=D(e,"",{...t??{},maxAge:0}))}}),[])}function be(){let e=E?R.useContext(E):null;if(!e){let t=fe();if(t)return t;if(typeof window>"u")return ce;throw new Error("useRouter must be used inside mountWebframezClient()")}return e}function me({active:e}){return p("div",{style:{position:"fixed",top:0,left:0,width:"100%",height:3,zIndex:9999,transformOrigin:"left",transform:e?"scaleX(1)":"scaleX(0)",transition:"transform 180ms ease",background:"linear-gradient(90deg, #0ea5e9, #22c55e)"}})}function F(e){let t=document.createElement("meta");t.setAttribute("data-webframez-head","true");let n=Object.entries(e).filter(([,o])=>!!o);for(let[o,r]of n)t.setAttribute(o,String(r));document.head.appendChild(t)}function j(e){let t=document.createElement("link");t.setAttribute("data-webframez-head","true");let n=Object.entries(e).filter(([,o])=>!!o);for(let[o,r]of n)t.setAttribute(o,String(r));document.head.appendChild(t)}function N(e){if(typeof document>"u")return;let t=T(e)??e;V(t),document.title=t.title||"Webframez React";for(let n of document.head.querySelectorAll(de))n.remove();t.description&&F({name:"description",content:t.description}),t.favicon&&j({rel:"icon",href:t.favicon});for(let n of t.meta??[])F(n);for(let n of t.links??[])j(n)}function V(e){if(typeof window>"u")return;let t=T(e)??e,n=c(t.basename),o=c(t.routeBasePath),r=c(t.transportBasePath);window.__RSC_BASENAME=n??"",window.__RSC_ROUTE_BASE_PATH=o??"",r!==void 0&&(window.__RSC_ENDPOINT=Y(r,"/rsc"))}function Re(e){let t=new TextEncoder;return new ReadableStream({start(n){n.enqueue(t.encode(e)),n.close()}})}function ge(){if(typeof window>"u")return null;let e=window.__RSC_INITIAL_PAYLOAD;return typeof e!="string"||e===""?null:(delete window.__RSC_INITIAL_PAYLOAD,ae(Re(e)))}function he(e){let t=K(e),n=Z(window.location.pathname);return ge()??G(fetch(`${t}?path=${encodeURIComponent(n)}&search=${encodeURIComponent(window.location.search)}`,{cache:"no-store",credentials:"same-origin",headers:{Accept:"text/x-component"}}))}function _e(e,t){return function(){let o=R.use(e),r=typeof o.contextModel<"u"&&typeof o.pageModel<"u",[a,s]=f(o.model),[m,u]=f(o.contextModel),[l,h]=f(o.pageModel),[v,I]=f(o.head),[X,_]=f(!1),[J,Q]=f(!1),[ee,A]=f(r);async function b(i){let C=K(t),d=Z(i.pathname);return await G(fetch(`${C}?path=${encodeURIComponent(d)}&search=${encodeURIComponent(i.search)}`,{cache:"no-store",credentials:"same-origin",headers:{Accept:"text/x-component"}}))}async function w(i,C="push"){_(!0);try{let d=await b(i);N(d.head),I(d.head),s(d.model),u(d.contextModel),h(d.pageModel),A(!0);let P=`${i.pathname}${i.search}`;C==="replace"?history.replaceState(null,"",P):C==="push"&&history.pushState(null,"",P)}catch(d){console.error("[webframez-react] Failed to render route",d),s(p("p",{children:"Failed to load route."}))}finally{_(!1)}}async function te(){_(!0);try{let i=await b(new URL(window.location.href));if(N(i.head),I(i.head),Object.prototype.hasOwnProperty.call(i,"contextModel")){u(i.contextModel),A(!0);return}s(i.model),A(!1)}catch(i){console.error("[webframez-react] Failed to refresh route context",i)}finally{_(!1)}}$(()=>{N(v)},[v]),$(()=>{Q(!0);let i=()=>{w(new URL(window.location.href),"none")};return window.addEventListener("popstate",i),()=>{window.removeEventListener("popstate",i)}},[]);let O=R.useMemo(()=>({push:i=>{w(new URL(i,window.location.origin),"push")},replace:i=>{w(new URL(i,window.location.origin),"replace")},refresh:()=>{w(new URL(window.location.href),"none")},refreshContext:()=>{te()}}),[]);pe(O);let ne=ee&&typeof l<"u"?m?p(se,{page:l,children:y(m,l)}):l:a,k=Ce(we,{children:[J?p(me,{active:X}):null,ne??p("p",{style:{padding:24},children:"Loading..."})]});return E?p(E.Provider,{value:O,children:k}):k}}function Oe(e={}){let t=e.rootId??"root",n=document.getElementById(t);if(!n)throw new Error(`Missing #${t} element`);let o=typeof window<"u"&&window.__RSC_ENDPOINT,r=e.rscEndpoint??o??"/rsc",a=Promise.resolve(he(r)).then(u=>(u?.head&&V(u.head),u)),s=_e(a,r);return ie(n,p(s,{}))}export{Oe as mountWebframezClient,Ie as useCookie,be as useRouter};
|
package/dist/http.cjs
CHANGED
|
@@ -142,6 +142,7 @@ function sendRSC(res, model, options = {}) {
|
|
|
142
142
|
} = options;
|
|
143
143
|
res.statusCode = statusCode;
|
|
144
144
|
res.setHeader("Content-Type", contentType);
|
|
145
|
+
res.setHeader("Cache-Control", "no-store, no-cache, must-revalidate, proxy-revalidate");
|
|
145
146
|
const stream = (0, import_server.renderToPipeableStream)(model, moduleMap, { onError });
|
|
146
147
|
stream.pipe(res);
|
|
147
148
|
return stream;
|
|
@@ -151,6 +152,7 @@ function sendRSC(res, model, options = {}) {
|
|
|
151
152
|
var import_node_fs = __toESM(require("node:fs"), 1);
|
|
152
153
|
var import_node_module2 = __toESM(require("node:module"), 1);
|
|
153
154
|
var import_node_path2 = __toESM(require("node:path"), 1);
|
|
155
|
+
var import_route_slot = require("@webtypen/webframez-react/route-slot");
|
|
154
156
|
|
|
155
157
|
// src/head.ts
|
|
156
158
|
var ABSOLUTE_ASSET_URL_PATTERN = /^(?:[a-zA-Z][a-zA-Z\d+\-.]*:|\/\/|#)/;
|
|
@@ -240,6 +242,16 @@ function isRouteChildrenType(type) {
|
|
|
240
242
|
return false;
|
|
241
243
|
}
|
|
242
244
|
}
|
|
245
|
+
function isReactElementLike(node) {
|
|
246
|
+
if (!node || typeof node !== "object") {
|
|
247
|
+
return false;
|
|
248
|
+
}
|
|
249
|
+
try {
|
|
250
|
+
return "type" in node && "props" in node;
|
|
251
|
+
} catch {
|
|
252
|
+
return false;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
243
255
|
function injectRouteChildren(node, routeChildren) {
|
|
244
256
|
if (node === null || node === void 0 || typeof node === "boolean") {
|
|
245
257
|
return node;
|
|
@@ -255,13 +267,17 @@ function injectRouteChildren(node, routeChildren) {
|
|
|
255
267
|
});
|
|
256
268
|
return changed ? next : node;
|
|
257
269
|
}
|
|
258
|
-
if (
|
|
270
|
+
if (isReactElementLike(node) && isRouteChildrenType(node.type)) {
|
|
271
|
+
return routeChildren;
|
|
272
|
+
}
|
|
273
|
+
const isValidElement = import_react.default.isValidElement(node);
|
|
274
|
+
if (!isValidElement && !isReactElementLike(node)) {
|
|
259
275
|
return node;
|
|
260
276
|
}
|
|
261
|
-
if (isRouteChildrenType(node.type)) {
|
|
277
|
+
if (isValidElement && isRouteChildrenType(node.type)) {
|
|
262
278
|
return routeChildren;
|
|
263
279
|
}
|
|
264
|
-
const props = node.props;
|
|
280
|
+
const props = node.props ?? {};
|
|
265
281
|
if (!("children" in props)) {
|
|
266
282
|
return node;
|
|
267
283
|
}
|
|
@@ -269,10 +285,19 @@ function injectRouteChildren(node, routeChildren) {
|
|
|
269
285
|
if (nextChildren === props.children) {
|
|
270
286
|
return node;
|
|
271
287
|
}
|
|
272
|
-
if (
|
|
273
|
-
|
|
288
|
+
if (isValidElement) {
|
|
289
|
+
if (Array.isArray(nextChildren)) {
|
|
290
|
+
return import_react.default.cloneElement(node, void 0, ...nextChildren);
|
|
291
|
+
}
|
|
292
|
+
return import_react.default.cloneElement(node, void 0, nextChildren);
|
|
274
293
|
}
|
|
275
|
-
|
|
294
|
+
const elementLike = node;
|
|
295
|
+
const nextProps = {
|
|
296
|
+
...elementLike.props ?? {},
|
|
297
|
+
children: nextChildren,
|
|
298
|
+
...elementLike.key !== void 0 && elementLike.key !== null ? { key: elementLike.key } : {}
|
|
299
|
+
};
|
|
300
|
+
return import_react.default.createElement(elementLike.type, nextProps);
|
|
276
301
|
}
|
|
277
302
|
|
|
278
303
|
// src/file-router.tsx
|
|
@@ -437,15 +462,22 @@ function mergeHead(...configs) {
|
|
|
437
462
|
if (!config) {
|
|
438
463
|
continue;
|
|
439
464
|
}
|
|
465
|
+
const hasOwn = (key) => Object.prototype.hasOwnProperty.call(config, key);
|
|
440
466
|
if (config.title) {
|
|
441
467
|
merged.title = config.title;
|
|
442
468
|
}
|
|
443
469
|
if (config.description) {
|
|
444
470
|
merged.description = config.description;
|
|
445
471
|
}
|
|
446
|
-
if (
|
|
472
|
+
if (hasOwn("basename")) {
|
|
447
473
|
merged.basename = config.basename;
|
|
448
474
|
}
|
|
475
|
+
if (hasOwn("routeBasePath")) {
|
|
476
|
+
merged.routeBasePath = config.routeBasePath;
|
|
477
|
+
}
|
|
478
|
+
if (hasOwn("transportBasePath")) {
|
|
479
|
+
merged.transportBasePath = config.transportBasePath;
|
|
480
|
+
}
|
|
449
481
|
if (config.favicon) {
|
|
450
482
|
merged.favicon = config.favicon;
|
|
451
483
|
}
|
|
@@ -606,9 +638,12 @@ function createFileRouter(options) {
|
|
|
606
638
|
const errorHead = await resolveHead(errorModule, errorProps);
|
|
607
639
|
const layoutNode = layoutModule ? await layoutModule.default(context) : null;
|
|
608
640
|
const model = layoutNode ? injectRouteChildren(layoutNode, errorNode) : errorNode;
|
|
641
|
+
const contextModel = layoutNode ? injectRouteChildren(layoutNode, /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_route_slot.RouteChildrenSlot, {})) : void 0;
|
|
609
642
|
return {
|
|
610
643
|
statusCode,
|
|
611
644
|
model,
|
|
645
|
+
contextModel,
|
|
646
|
+
pageModel: errorNode,
|
|
612
647
|
head: mergeHead(layoutHead, errorHead)
|
|
613
648
|
};
|
|
614
649
|
}
|
|
@@ -728,9 +763,12 @@ function createFileRouter(options) {
|
|
|
728
763
|
const pageHead = await resolveHead(pageModule, pageContext);
|
|
729
764
|
const layoutNode = layoutModule ? await layoutModule.default(pageContext) : null;
|
|
730
765
|
const model = layoutNode ? injectRouteChildren(layoutNode, pageNode) : pageNode;
|
|
766
|
+
const contextModel = layoutNode ? injectRouteChildren(layoutNode, /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_route_slot.RouteChildrenSlot, {})) : void 0;
|
|
731
767
|
return {
|
|
732
768
|
statusCode: 200,
|
|
733
769
|
model,
|
|
770
|
+
contextModel,
|
|
771
|
+
pageModel: pageNode,
|
|
734
772
|
head: mergeHead(layoutHead, pageHead)
|
|
735
773
|
};
|
|
736
774
|
} catch (error) {
|
|
@@ -885,7 +923,7 @@ async function decodeFlightPayloadFromString(flightData, moduleMap) {
|
|
|
885
923
|
|
|
886
924
|
if (typeof reactServerDomClientNode.createFromNodeStream === "function") {
|
|
887
925
|
return await reactServerDomClientNode.createFromNodeStream(
|
|
888
|
-
Readable.from([flightData]),
|
|
926
|
+
Readable.from([Buffer.from(flightData)]),
|
|
889
927
|
serverConsumerManifest
|
|
890
928
|
);
|
|
891
929
|
}
|
|
@@ -910,7 +948,21 @@ async function renderHtmlFromFlightData(flightData, moduleMap) {
|
|
|
910
948
|
? payload.model
|
|
911
949
|
: payload;
|
|
912
950
|
|
|
913
|
-
|
|
951
|
+
const basename =
|
|
952
|
+
payload &&
|
|
953
|
+
typeof payload === "object" &&
|
|
954
|
+
payload.head &&
|
|
955
|
+
typeof payload.head.basename === "string"
|
|
956
|
+
? payload.head.basename
|
|
957
|
+
: "";
|
|
958
|
+
|
|
959
|
+
const previousBasename = globalThis.__RSC_BASENAME;
|
|
960
|
+
globalThis.__RSC_BASENAME = basename;
|
|
961
|
+
try {
|
|
962
|
+
return await renderHtml(model);
|
|
963
|
+
} finally {
|
|
964
|
+
globalThis.__RSC_BASENAME = previousBasename;
|
|
965
|
+
}
|
|
914
966
|
}
|
|
915
967
|
|
|
916
968
|
process.on("message", async (message) => {
|
|
@@ -1377,6 +1429,8 @@ function createNodeRequestHandler(options) {
|
|
|
1377
1429
|
);
|
|
1378
1430
|
const payload = {
|
|
1379
1431
|
model: resolved2.model,
|
|
1432
|
+
contextModel: resolved2.contextModel,
|
|
1433
|
+
pageModel: resolved2.pageModel,
|
|
1380
1434
|
head: resolved2.head
|
|
1381
1435
|
};
|
|
1382
1436
|
sendRSC(res, payload, {
|
|
@@ -1399,6 +1453,7 @@ function createNodeRequestHandler(options) {
|
|
|
1399
1453
|
} else if (ext === ".json") {
|
|
1400
1454
|
res.setHeader("Content-Type", "application/json; charset=utf-8");
|
|
1401
1455
|
}
|
|
1456
|
+
res.setHeader("Cache-Control", "no-store, no-cache, must-revalidate, proxy-revalidate");
|
|
1402
1457
|
const stream = import_node_fs2.default.createReadStream(filePath);
|
|
1403
1458
|
stream.on("error", () => {
|
|
1404
1459
|
res.statusCode = 404;
|
|
@@ -1422,6 +1477,8 @@ function createNodeRequestHandler(options) {
|
|
|
1422
1477
|
);
|
|
1423
1478
|
const initialPayload = {
|
|
1424
1479
|
model: resolved.model,
|
|
1480
|
+
contextModel: resolved.contextModel,
|
|
1481
|
+
pageModel: resolved.pageModel,
|
|
1425
1482
|
head: resolved.head
|
|
1426
1483
|
};
|
|
1427
1484
|
const initialFlightData = await renderRSCToString(initialPayload, {
|
package/dist/http.js
CHANGED
|
@@ -117,6 +117,7 @@ function sendRSC(res, model, options = {}) {
|
|
|
117
117
|
} = options;
|
|
118
118
|
res.statusCode = statusCode;
|
|
119
119
|
res.setHeader("Content-Type", contentType);
|
|
120
|
+
res.setHeader("Cache-Control", "no-store, no-cache, must-revalidate, proxy-revalidate");
|
|
120
121
|
const stream = renderToPipeableStream(model, moduleMap, { onError });
|
|
121
122
|
stream.pipe(res);
|
|
122
123
|
return stream;
|
|
@@ -126,6 +127,7 @@ function sendRSC(res, model, options = {}) {
|
|
|
126
127
|
import fs from "node:fs";
|
|
127
128
|
import Module from "node:module";
|
|
128
129
|
import path2 from "node:path";
|
|
130
|
+
import { RouteChildrenSlot } from "@webtypen/webframez-react/route-slot";
|
|
129
131
|
|
|
130
132
|
// src/head.ts
|
|
131
133
|
var ABSOLUTE_ASSET_URL_PATTERN = /^(?:[a-zA-Z][a-zA-Z\d+\-.]*:|\/\/|#)/;
|
|
@@ -215,6 +217,16 @@ function isRouteChildrenType(type) {
|
|
|
215
217
|
return false;
|
|
216
218
|
}
|
|
217
219
|
}
|
|
220
|
+
function isReactElementLike(node) {
|
|
221
|
+
if (!node || typeof node !== "object") {
|
|
222
|
+
return false;
|
|
223
|
+
}
|
|
224
|
+
try {
|
|
225
|
+
return "type" in node && "props" in node;
|
|
226
|
+
} catch {
|
|
227
|
+
return false;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
218
230
|
function injectRouteChildren(node, routeChildren) {
|
|
219
231
|
if (node === null || node === void 0 || typeof node === "boolean") {
|
|
220
232
|
return node;
|
|
@@ -230,13 +242,17 @@ function injectRouteChildren(node, routeChildren) {
|
|
|
230
242
|
});
|
|
231
243
|
return changed ? next : node;
|
|
232
244
|
}
|
|
233
|
-
if (
|
|
245
|
+
if (isReactElementLike(node) && isRouteChildrenType(node.type)) {
|
|
246
|
+
return routeChildren;
|
|
247
|
+
}
|
|
248
|
+
const isValidElement = React.isValidElement(node);
|
|
249
|
+
if (!isValidElement && !isReactElementLike(node)) {
|
|
234
250
|
return node;
|
|
235
251
|
}
|
|
236
|
-
if (isRouteChildrenType(node.type)) {
|
|
252
|
+
if (isValidElement && isRouteChildrenType(node.type)) {
|
|
237
253
|
return routeChildren;
|
|
238
254
|
}
|
|
239
|
-
const props = node.props;
|
|
255
|
+
const props = node.props ?? {};
|
|
240
256
|
if (!("children" in props)) {
|
|
241
257
|
return node;
|
|
242
258
|
}
|
|
@@ -244,10 +260,19 @@ function injectRouteChildren(node, routeChildren) {
|
|
|
244
260
|
if (nextChildren === props.children) {
|
|
245
261
|
return node;
|
|
246
262
|
}
|
|
247
|
-
if (
|
|
248
|
-
|
|
263
|
+
if (isValidElement) {
|
|
264
|
+
if (Array.isArray(nextChildren)) {
|
|
265
|
+
return React.cloneElement(node, void 0, ...nextChildren);
|
|
266
|
+
}
|
|
267
|
+
return React.cloneElement(node, void 0, nextChildren);
|
|
249
268
|
}
|
|
250
|
-
|
|
269
|
+
const elementLike = node;
|
|
270
|
+
const nextProps = {
|
|
271
|
+
...elementLike.props ?? {},
|
|
272
|
+
children: nextChildren,
|
|
273
|
+
...elementLike.key !== void 0 && elementLike.key !== null ? { key: elementLike.key } : {}
|
|
274
|
+
};
|
|
275
|
+
return React.createElement(elementLike.type, nextProps);
|
|
251
276
|
}
|
|
252
277
|
|
|
253
278
|
// src/file-router.tsx
|
|
@@ -412,15 +437,22 @@ function mergeHead(...configs) {
|
|
|
412
437
|
if (!config) {
|
|
413
438
|
continue;
|
|
414
439
|
}
|
|
440
|
+
const hasOwn = (key) => Object.prototype.hasOwnProperty.call(config, key);
|
|
415
441
|
if (config.title) {
|
|
416
442
|
merged.title = config.title;
|
|
417
443
|
}
|
|
418
444
|
if (config.description) {
|
|
419
445
|
merged.description = config.description;
|
|
420
446
|
}
|
|
421
|
-
if (
|
|
447
|
+
if (hasOwn("basename")) {
|
|
422
448
|
merged.basename = config.basename;
|
|
423
449
|
}
|
|
450
|
+
if (hasOwn("routeBasePath")) {
|
|
451
|
+
merged.routeBasePath = config.routeBasePath;
|
|
452
|
+
}
|
|
453
|
+
if (hasOwn("transportBasePath")) {
|
|
454
|
+
merged.transportBasePath = config.transportBasePath;
|
|
455
|
+
}
|
|
424
456
|
if (config.favicon) {
|
|
425
457
|
merged.favicon = config.favicon;
|
|
426
458
|
}
|
|
@@ -581,9 +613,12 @@ function createFileRouter(options) {
|
|
|
581
613
|
const errorHead = await resolveHead(errorModule, errorProps);
|
|
582
614
|
const layoutNode = layoutModule ? await layoutModule.default(context) : null;
|
|
583
615
|
const model = layoutNode ? injectRouteChildren(layoutNode, errorNode) : errorNode;
|
|
616
|
+
const contextModel = layoutNode ? injectRouteChildren(layoutNode, /* @__PURE__ */ jsx(RouteChildrenSlot, {})) : void 0;
|
|
584
617
|
return {
|
|
585
618
|
statusCode,
|
|
586
619
|
model,
|
|
620
|
+
contextModel,
|
|
621
|
+
pageModel: errorNode,
|
|
587
622
|
head: mergeHead(layoutHead, errorHead)
|
|
588
623
|
};
|
|
589
624
|
}
|
|
@@ -703,9 +738,12 @@ function createFileRouter(options) {
|
|
|
703
738
|
const pageHead = await resolveHead(pageModule, pageContext);
|
|
704
739
|
const layoutNode = layoutModule ? await layoutModule.default(pageContext) : null;
|
|
705
740
|
const model = layoutNode ? injectRouteChildren(layoutNode, pageNode) : pageNode;
|
|
741
|
+
const contextModel = layoutNode ? injectRouteChildren(layoutNode, /* @__PURE__ */ jsx(RouteChildrenSlot, {})) : void 0;
|
|
706
742
|
return {
|
|
707
743
|
statusCode: 200,
|
|
708
744
|
model,
|
|
745
|
+
contextModel,
|
|
746
|
+
pageModel: pageNode,
|
|
709
747
|
head: mergeHead(layoutHead, pageHead)
|
|
710
748
|
};
|
|
711
749
|
} catch (error) {
|
|
@@ -860,7 +898,7 @@ async function decodeFlightPayloadFromString(flightData, moduleMap) {
|
|
|
860
898
|
|
|
861
899
|
if (typeof reactServerDomClientNode.createFromNodeStream === "function") {
|
|
862
900
|
return await reactServerDomClientNode.createFromNodeStream(
|
|
863
|
-
Readable.from([flightData]),
|
|
901
|
+
Readable.from([Buffer.from(flightData)]),
|
|
864
902
|
serverConsumerManifest
|
|
865
903
|
);
|
|
866
904
|
}
|
|
@@ -885,7 +923,21 @@ async function renderHtmlFromFlightData(flightData, moduleMap) {
|
|
|
885
923
|
? payload.model
|
|
886
924
|
: payload;
|
|
887
925
|
|
|
888
|
-
|
|
926
|
+
const basename =
|
|
927
|
+
payload &&
|
|
928
|
+
typeof payload === "object" &&
|
|
929
|
+
payload.head &&
|
|
930
|
+
typeof payload.head.basename === "string"
|
|
931
|
+
? payload.head.basename
|
|
932
|
+
: "";
|
|
933
|
+
|
|
934
|
+
const previousBasename = globalThis.__RSC_BASENAME;
|
|
935
|
+
globalThis.__RSC_BASENAME = basename;
|
|
936
|
+
try {
|
|
937
|
+
return await renderHtml(model);
|
|
938
|
+
} finally {
|
|
939
|
+
globalThis.__RSC_BASENAME = previousBasename;
|
|
940
|
+
}
|
|
889
941
|
}
|
|
890
942
|
|
|
891
943
|
process.on("message", async (message) => {
|
|
@@ -1352,6 +1404,8 @@ function createNodeRequestHandler(options) {
|
|
|
1352
1404
|
);
|
|
1353
1405
|
const payload = {
|
|
1354
1406
|
model: resolved2.model,
|
|
1407
|
+
contextModel: resolved2.contextModel,
|
|
1408
|
+
pageModel: resolved2.pageModel,
|
|
1355
1409
|
head: resolved2.head
|
|
1356
1410
|
};
|
|
1357
1411
|
sendRSC(res, payload, {
|
|
@@ -1374,6 +1428,7 @@ function createNodeRequestHandler(options) {
|
|
|
1374
1428
|
} else if (ext === ".json") {
|
|
1375
1429
|
res.setHeader("Content-Type", "application/json; charset=utf-8");
|
|
1376
1430
|
}
|
|
1431
|
+
res.setHeader("Cache-Control", "no-store, no-cache, must-revalidate, proxy-revalidate");
|
|
1377
1432
|
const stream = fs2.createReadStream(filePath);
|
|
1378
1433
|
stream.on("error", () => {
|
|
1379
1434
|
res.statusCode = 404;
|
|
@@ -1397,6 +1452,8 @@ function createNodeRequestHandler(options) {
|
|
|
1397
1452
|
);
|
|
1398
1453
|
const initialPayload = {
|
|
1399
1454
|
model: resolved.model,
|
|
1455
|
+
contextModel: resolved.contextModel,
|
|
1456
|
+
pageModel: resolved.pageModel,
|
|
1400
1457
|
head: resolved.head
|
|
1401
1458
|
};
|
|
1402
1459
|
const initialFlightData = await renderRSCToString(initialPayload, {
|
package/dist/index.cjs
CHANGED
|
@@ -147,6 +147,7 @@ function sendRSC(res, model, options = {}) {
|
|
|
147
147
|
} = options;
|
|
148
148
|
res.statusCode = statusCode;
|
|
149
149
|
res.setHeader("Content-Type", contentType);
|
|
150
|
+
res.setHeader("Cache-Control", "no-store, no-cache, must-revalidate, proxy-revalidate");
|
|
150
151
|
const stream = (0, import_server.renderToPipeableStream)(model, moduleMap, { onError });
|
|
151
152
|
stream.pipe(res);
|
|
152
153
|
return stream;
|
|
@@ -184,6 +185,7 @@ function createRSCHandler(options) {
|
|
|
184
185
|
var import_node_fs = __toESM(require("node:fs"), 1);
|
|
185
186
|
var import_node_module2 = __toESM(require("node:module"), 1);
|
|
186
187
|
var import_node_path2 = __toESM(require("node:path"), 1);
|
|
188
|
+
var import_route_slot = require("@webtypen/webframez-react/route-slot");
|
|
187
189
|
|
|
188
190
|
// src/head.ts
|
|
189
191
|
var ABSOLUTE_ASSET_URL_PATTERN = /^(?:[a-zA-Z][a-zA-Z\d+\-.]*:|\/\/|#)/;
|
|
@@ -273,6 +275,16 @@ function isRouteChildrenType(type) {
|
|
|
273
275
|
return false;
|
|
274
276
|
}
|
|
275
277
|
}
|
|
278
|
+
function isReactElementLike(node) {
|
|
279
|
+
if (!node || typeof node !== "object") {
|
|
280
|
+
return false;
|
|
281
|
+
}
|
|
282
|
+
try {
|
|
283
|
+
return "type" in node && "props" in node;
|
|
284
|
+
} catch {
|
|
285
|
+
return false;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
276
288
|
function injectRouteChildren(node, routeChildren) {
|
|
277
289
|
if (node === null || node === void 0 || typeof node === "boolean") {
|
|
278
290
|
return node;
|
|
@@ -288,13 +300,17 @@ function injectRouteChildren(node, routeChildren) {
|
|
|
288
300
|
});
|
|
289
301
|
return changed ? next : node;
|
|
290
302
|
}
|
|
291
|
-
if (
|
|
303
|
+
if (isReactElementLike(node) && isRouteChildrenType(node.type)) {
|
|
304
|
+
return routeChildren;
|
|
305
|
+
}
|
|
306
|
+
const isValidElement = import_react.default.isValidElement(node);
|
|
307
|
+
if (!isValidElement && !isReactElementLike(node)) {
|
|
292
308
|
return node;
|
|
293
309
|
}
|
|
294
|
-
if (isRouteChildrenType(node.type)) {
|
|
310
|
+
if (isValidElement && isRouteChildrenType(node.type)) {
|
|
295
311
|
return routeChildren;
|
|
296
312
|
}
|
|
297
|
-
const props = node.props;
|
|
313
|
+
const props = node.props ?? {};
|
|
298
314
|
if (!("children" in props)) {
|
|
299
315
|
return node;
|
|
300
316
|
}
|
|
@@ -302,10 +318,19 @@ function injectRouteChildren(node, routeChildren) {
|
|
|
302
318
|
if (nextChildren === props.children) {
|
|
303
319
|
return node;
|
|
304
320
|
}
|
|
305
|
-
if (
|
|
306
|
-
|
|
321
|
+
if (isValidElement) {
|
|
322
|
+
if (Array.isArray(nextChildren)) {
|
|
323
|
+
return import_react.default.cloneElement(node, void 0, ...nextChildren);
|
|
324
|
+
}
|
|
325
|
+
return import_react.default.cloneElement(node, void 0, nextChildren);
|
|
307
326
|
}
|
|
308
|
-
|
|
327
|
+
const elementLike = node;
|
|
328
|
+
const nextProps = {
|
|
329
|
+
...elementLike.props ?? {},
|
|
330
|
+
children: nextChildren,
|
|
331
|
+
...elementLike.key !== void 0 && elementLike.key !== null ? { key: elementLike.key } : {}
|
|
332
|
+
};
|
|
333
|
+
return import_react.default.createElement(elementLike.type, nextProps);
|
|
309
334
|
}
|
|
310
335
|
|
|
311
336
|
// src/file-router.tsx
|
|
@@ -470,15 +495,22 @@ function mergeHead(...configs) {
|
|
|
470
495
|
if (!config) {
|
|
471
496
|
continue;
|
|
472
497
|
}
|
|
498
|
+
const hasOwn = (key) => Object.prototype.hasOwnProperty.call(config, key);
|
|
473
499
|
if (config.title) {
|
|
474
500
|
merged.title = config.title;
|
|
475
501
|
}
|
|
476
502
|
if (config.description) {
|
|
477
503
|
merged.description = config.description;
|
|
478
504
|
}
|
|
479
|
-
if (
|
|
505
|
+
if (hasOwn("basename")) {
|
|
480
506
|
merged.basename = config.basename;
|
|
481
507
|
}
|
|
508
|
+
if (hasOwn("routeBasePath")) {
|
|
509
|
+
merged.routeBasePath = config.routeBasePath;
|
|
510
|
+
}
|
|
511
|
+
if (hasOwn("transportBasePath")) {
|
|
512
|
+
merged.transportBasePath = config.transportBasePath;
|
|
513
|
+
}
|
|
482
514
|
if (config.favicon) {
|
|
483
515
|
merged.favicon = config.favicon;
|
|
484
516
|
}
|
|
@@ -639,9 +671,12 @@ function createFileRouter(options) {
|
|
|
639
671
|
const errorHead = await resolveHead(errorModule, errorProps);
|
|
640
672
|
const layoutNode = layoutModule ? await layoutModule.default(context) : null;
|
|
641
673
|
const model = layoutNode ? injectRouteChildren(layoutNode, errorNode) : errorNode;
|
|
674
|
+
const contextModel = layoutNode ? injectRouteChildren(layoutNode, /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_route_slot.RouteChildrenSlot, {})) : void 0;
|
|
642
675
|
return {
|
|
643
676
|
statusCode,
|
|
644
677
|
model,
|
|
678
|
+
contextModel,
|
|
679
|
+
pageModel: errorNode,
|
|
645
680
|
head: mergeHead(layoutHead, errorHead)
|
|
646
681
|
};
|
|
647
682
|
}
|
|
@@ -761,9 +796,12 @@ function createFileRouter(options) {
|
|
|
761
796
|
const pageHead = await resolveHead(pageModule, pageContext);
|
|
762
797
|
const layoutNode = layoutModule ? await layoutModule.default(pageContext) : null;
|
|
763
798
|
const model = layoutNode ? injectRouteChildren(layoutNode, pageNode) : pageNode;
|
|
799
|
+
const contextModel = layoutNode ? injectRouteChildren(layoutNode, /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_route_slot.RouteChildrenSlot, {})) : void 0;
|
|
764
800
|
return {
|
|
765
801
|
statusCode: 200,
|
|
766
802
|
model,
|
|
803
|
+
contextModel,
|
|
804
|
+
pageModel: pageNode,
|
|
767
805
|
head: mergeHead(layoutHead, pageHead)
|
|
768
806
|
};
|
|
769
807
|
} catch (error) {
|
|
@@ -922,7 +960,7 @@ async function decodeFlightPayloadFromString(flightData, moduleMap) {
|
|
|
922
960
|
|
|
923
961
|
if (typeof reactServerDomClientNode.createFromNodeStream === "function") {
|
|
924
962
|
return await reactServerDomClientNode.createFromNodeStream(
|
|
925
|
-
Readable.from([flightData]),
|
|
963
|
+
Readable.from([Buffer.from(flightData)]),
|
|
926
964
|
serverConsumerManifest
|
|
927
965
|
);
|
|
928
966
|
}
|
|
@@ -947,7 +985,21 @@ async function renderHtmlFromFlightData(flightData, moduleMap) {
|
|
|
947
985
|
? payload.model
|
|
948
986
|
: payload;
|
|
949
987
|
|
|
950
|
-
|
|
988
|
+
const basename =
|
|
989
|
+
payload &&
|
|
990
|
+
typeof payload === "object" &&
|
|
991
|
+
payload.head &&
|
|
992
|
+
typeof payload.head.basename === "string"
|
|
993
|
+
? payload.head.basename
|
|
994
|
+
: "";
|
|
995
|
+
|
|
996
|
+
const previousBasename = globalThis.__RSC_BASENAME;
|
|
997
|
+
globalThis.__RSC_BASENAME = basename;
|
|
998
|
+
try {
|
|
999
|
+
return await renderHtml(model);
|
|
1000
|
+
} finally {
|
|
1001
|
+
globalThis.__RSC_BASENAME = previousBasename;
|
|
1002
|
+
}
|
|
951
1003
|
}
|
|
952
1004
|
|
|
953
1005
|
process.on("message", async (message) => {
|
|
@@ -1414,6 +1466,8 @@ function createNodeRequestHandler(options) {
|
|
|
1414
1466
|
);
|
|
1415
1467
|
const payload = {
|
|
1416
1468
|
model: resolved2.model,
|
|
1469
|
+
contextModel: resolved2.contextModel,
|
|
1470
|
+
pageModel: resolved2.pageModel,
|
|
1417
1471
|
head: resolved2.head
|
|
1418
1472
|
};
|
|
1419
1473
|
sendRSC(res, payload, {
|
|
@@ -1436,6 +1490,7 @@ function createNodeRequestHandler(options) {
|
|
|
1436
1490
|
} else if (ext === ".json") {
|
|
1437
1491
|
res.setHeader("Content-Type", "application/json; charset=utf-8");
|
|
1438
1492
|
}
|
|
1493
|
+
res.setHeader("Cache-Control", "no-store, no-cache, must-revalidate, proxy-revalidate");
|
|
1439
1494
|
const stream = import_node_fs2.default.createReadStream(filePath);
|
|
1440
1495
|
stream.on("error", () => {
|
|
1441
1496
|
res.statusCode = 404;
|
|
@@ -1459,6 +1514,8 @@ function createNodeRequestHandler(options) {
|
|
|
1459
1514
|
);
|
|
1460
1515
|
const initialPayload = {
|
|
1461
1516
|
model: resolved.model,
|
|
1517
|
+
contextModel: resolved.contextModel,
|
|
1518
|
+
pageModel: resolved.pageModel,
|
|
1462
1519
|
head: resolved.head
|
|
1463
1520
|
};
|
|
1464
1521
|
const initialFlightData = await renderRSCToString(initialPayload, {
|