@webtypen/webframez-react 0.0.29 → 0.0.31
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.js +1 -1
- package/dist/http.cjs +79 -21
- package/dist/http.js +80 -22
- package/dist/index.cjs +79 -21
- package/dist/index.js +80 -22
- package/dist/router.cjs +14 -5
- package/dist/router.js +14 -5
- package/dist/webframez-core.cjs +79 -21
- package/dist/webframez-core.js +80 -22
- package/package.json +1 -1
package/dist/client.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var M=Object.create;var m=Object.defineProperty;var D=Object.getOwnPropertyDescriptor;var F=Object.getOwnPropertyNames;var q=Object.getPrototypeOf,G=Object.prototype.hasOwnProperty;var Y=(e,t)=>{for(var n in t)m(e,n,{get:t[n],enumerable:!0})},S=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of F(t))!G.call(e,r)&&r!==n&&m(e,r,{get:()=>t[r],enumerable:!(o=D(t,r))||o.enumerable});return e};var Z=(e,t,n)=>(n=e!=null?M(q(e)):{},S(t||!e||!e.__esModule?m(n,"default",{value:e,enumerable:!0}):n,e)),j=e=>S(m({},"__esModule",{value:!0}),e);var ce={};Y(ce,{mountWebframezClient:()=>ue,useCookie:()=>ne,useRouter:()=>oe});module.exports=j(ce);var a=Z(require("react"),1),b=require("react-dom/client"),l=require("react-server-dom-webpack/client");var X=/^(?:[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 y(e,t){let n=e.trim(),o=u(t);return!n||!o||X.test(n)||n.startsWith("/")||o!=="/"&&(n===o||n.startsWith(`${o}/`))?n:o==="/"?n.startsWith("/")?n:`/${n}`:n.startsWith("/")?`${o}${n}`:`${o}/${n}`}function v(e,t){if(!e)return;let n=u(e.basename)??u(t),o=u(e.routeBasePath),r=u(e.transportBasePath),i={...e,...n!==void 0?{basename:n}:{},...o!==void 0?{routeBasePath:o}:{},...r!==void 0?{transportBasePath:r}:{}};return i.favicon&&(i.favicon=y(i.favicon,n)),i.links&&(i.links=i.links.map(c=>({...c,href:y(c.href,n)}))),i}var d=require("react/jsx-runtime"),K={push:()=>{},replace:()=>{},refresh:()=>{}},p=typeof a.default.createContext=="function"?a.default.createContext(null):null,N="__WEBFRAMEZ_ROUTER__",V="[data-webframez-head='true']";function w(e){return u(e)??""}function J(e,t){return t?e===t?"/":e.startsWith(`${t}/`)?e.slice(t.length)||"/":e||"/":e||"/"}function k(e,t){let n=!t||t==="/"?"/":t.startsWith("/")?t:`/${t}`;return e?n==="/"?e:`${e}${n}`:n}function Q(){return w(typeof window>"u"?globalThis.__RSC_ROUTE_BASE_PATH:window.__RSC_ROUTE_BASE_PATH)}function H(e){if(typeof window>"u")return e||"/";let t=w(window.__RSC_BASENAME),n=Q(),o=J(e||"/",t);return k(n,o)}function U(e){if(typeof window>"u")return e;let t=window.__RSC_ENDPOINT;return typeof t=="string"&&t.trim()!==""?t:e}function ee(){return typeof window>"u"?null:window[N]??null}function te(e){typeof window>"u"||(window[N]=e)}function T(){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("="),i=r>=0?o.slice(0,r).trim():o,c=r>=0?o.slice(r+1):"";i&&(e[i]=decodeURIComponent(c))}return e}function B(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 ne(){return a.default.useMemo(()=>({all:()=>T(),get:e=>T()[e],set:(e,t,n)=>{typeof document>"u"||(document.cookie=B(e,t,n))},remove:(e,t)=>{typeof document>"u"||(document.cookie=B(e,"",{...t??{},maxAge:0}))}}),[])}function oe(){let e=p?a.default.useContext(p):null;if(!e){let t=ee();if(t)return t;if(typeof window>"u")return K;throw new Error("useRouter must be used inside mountWebframezClient()")}return e}function re({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 x(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 O(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 I(e){if(typeof document>"u")return;let t=v(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=k(r,"/rsc")),document.title=t.title||"Webframez React";for(let i of document.head.querySelectorAll(V))i.remove();t.description&&x({name:"description",content:t.description}),t.favicon&&O({rel:"icon",href:t.favicon});for(let i of t.meta??[])x(i);for(let i of t.links??[])O(i)}function ie(e){let t=new TextEncoder;return new ReadableStream({start(n){n.enqueue(t.encode(e)),n.close()}})}function ae(){if(typeof window>"u")return null;let e=window.__RSC_INITIAL_PAYLOAD;return typeof e!="string"||e===""?null:(delete window.__RSC_INITIAL_PAYLOAD,(0,l.createFromReadableStream)(ie(e)))}function se(e){let t=U(e),n=H(window.location.pathname);return ae()??(0,l.createFromFetch)(fetch(`${t}?path=${encodeURIComponent(n)}&search=${encodeURIComponent(window.location.search)}`,{headers:{Accept:"text/x-component"}}))}function de(e,t){return function(){let o=a.default.use(e),[r,i]=(0,a.useState)(o.model),[c,R]=(0,a.useState)(o.head),[$,h]=(0,a.useState)(!1),[L,z]=(0,a.useState)(!1);async function f(s,E="push"){h(!0);try{let g=U(t),W=H(s.pathname),_=await(0,l.createFromFetch)(fetch(`${g}?path=${encodeURIComponent(W)}&search=${encodeURIComponent(s.search)}`,{headers:{Accept:"text/x-component"}}));I(_.head),R(_.head),i(_.model);let P=`${s.pathname}${s.search}`;E==="replace"?history.replaceState(null,"",P):E==="push"&&history.pushState(null,"",P)}catch(g){console.error("[webframez-react] Failed to render route",g),i((0,d.jsx)("p",{children:"Failed to load route."}))}finally{h(!1)}}(0,a.useEffect)(()=>{I(c)},[c]),(0,a.useEffect)(()=>{z(!0);let s=()=>{f(new URL(window.location.href),"none")};return window.addEventListener("popstate",s),()=>{window.removeEventListener("popstate",s)}},[]);let C=a.default.useMemo(()=>({push:s=>{f(new URL(s,window.location.origin),"push")},replace:s=>{f(new URL(s,window.location.origin),"replace")},refresh:()=>{f(new URL(window.location.href),"none")}}),[]);te(C);let A=(0,d.jsxs)(d.Fragment,{children:[L?(0,d.jsx)(re,{active:$}):null,r??(0,d.jsx)("p",{style:{padding:24},children:"Loading..."})]});return p?(0,d.jsx)(p.Provider,{value:C,children:A}):A}}function ue(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",i=se(r),c=de(i,r);return(0,b.hydrateRoot)(n,(0,d.jsx)(c,{}))}
|
package/dist/client.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import c,{useEffect as
|
|
1
|
+
import c,{useEffect as y,useState as f}from"react";import{hydrateRoot as M}from"react-dom/client";import{createFromFetch as I,createFromReadableStream as D}from"react-server-dom-webpack/client";var W=/^(?:[a-zA-Z][a-zA-Z\d+\-.]*:|\/\/|#)/;function s(e){if(typeof e!="string")return;let t=e.trim();return!t||t==="/"?"":t.replace(/\/+$/,"")}function P(e,t){let n=e.trim(),o=s(t);return!n||!o||W.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=s(e.basename)??s(t),o=s(e.routeBasePath),i=s(e.transportBasePath),r={...e,...n!==void 0?{basename:n}:{},...o!==void 0?{routeBasePath:o}:{},...i!==void 0?{transportBasePath:i}:{}};return r.favicon&&(r.favicon=P(r.favicon,n)),r.links&&(r.links=r.links.map(d=>({...d,href:P(d.href,n)}))),r}import{Fragment as ee,jsx as u,jsxs as te}from"react/jsx-runtime";var F={push:()=>{},replace:()=>{},refresh:()=>{}},m=typeof c.createContext=="function"?c.createContext(null):null,b="__WEBFRAMEZ_ROUTER__",q="[data-webframez-head='true']";function _(e){return s(e)??""}function G(e,t){return t?e===t?"/":e.startsWith(`${t}/`)?e.slice(t.length)||"/":e||"/":e||"/"}function N(e,t){let n=!t||t==="/"?"/":t.startsWith("/")?t:`/${t}`;return e?n==="/"?e:`${e}${n}`:n}function Y(){return _(typeof window>"u"?globalThis.__RSC_ROUTE_BASE_PATH:window.__RSC_ROUTE_BASE_PATH)}function k(e){if(typeof window>"u")return e||"/";let t=_(window.__RSC_BASENAME),n=Y(),o=G(e||"/",t);return N(n,o)}function H(e){if(typeof window>"u")return e;let t=window.__RSC_ENDPOINT;return typeof t=="string"&&t.trim()!==""?t:e}function Z(){return typeof window>"u"?null:window[b]??null}function j(e){typeof window>"u"||(window[b]=e)}function v(){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 i=o.indexOf("="),r=i>=0?o.slice(0,i).trim():o,d=i>=0?o.slice(i+1):"";r&&(e[r]=decodeURIComponent(d))}return e}function T(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 de(){return c.useMemo(()=>({all:()=>v(),get:e=>v()[e],set:(e,t,n)=>{typeof document>"u"||(document.cookie=T(e,t,n))},remove:(e,t)=>{typeof document>"u"||(document.cookie=T(e,"",{...t??{},maxAge:0}))}}),[])}function ue(){let e=m?c.useContext(m):null;if(!e){let t=Z();if(t)return t;if(typeof window>"u")return F;throw new Error("useRouter must be used inside mountWebframezClient()")}return e}function X({active:e}){return u("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 B(e){let t=document.createElement("meta");t.setAttribute("data-webframez-head","true");let n=Object.entries(e).filter(([,o])=>!!o);for(let[o,i]of n)t.setAttribute(o,String(i));document.head.appendChild(t)}function x(e){let t=document.createElement("link");t.setAttribute("data-webframez-head","true");let n=Object.entries(e).filter(([,o])=>!!o);for(let[o,i]of n)t.setAttribute(o,String(i));document.head.appendChild(t)}function O(e){if(typeof document>"u")return;let t=S(e)??e,n=s(t.basename),o=s(t.routeBasePath),i=s(t.transportBasePath);window.__RSC_BASENAME=n??"",window.__RSC_ROUTE_BASE_PATH=o??"",i!==void 0&&(window.__RSC_ENDPOINT=N(i,"/rsc")),document.title=t.title||"Webframez React";for(let r of document.head.querySelectorAll(q))r.remove();t.description&&B({name:"description",content:t.description}),t.favicon&&x({rel:"icon",href:t.favicon});for(let r of t.meta??[])B(r);for(let r of t.links??[])x(r)}function K(e){let t=new TextEncoder;return new ReadableStream({start(n){n.enqueue(t.encode(e)),n.close()}})}function V(){if(typeof window>"u")return null;let e=window.__RSC_INITIAL_PAYLOAD;return typeof e!="string"||e===""?null:(delete window.__RSC_INITIAL_PAYLOAD,D(K(e)))}function J(e){let t=H(e),n=k(window.location.pathname);return V()??I(fetch(`${t}?path=${encodeURIComponent(n)}&search=${encodeURIComponent(window.location.search)}`,{headers:{Accept:"text/x-component"}}))}function Q(e,t){return function(){let o=c.use(e),[i,r]=f(o.model),[d,w]=f(o.head),[U,R]=f(!1),[$,L]=f(!1);async function l(a,A="push"){R(!0);try{let p=H(t),z=k(a.pathname),g=await I(fetch(`${p}?path=${encodeURIComponent(z)}&search=${encodeURIComponent(a.search)}`,{headers:{Accept:"text/x-component"}}));O(g.head),w(g.head),r(g.model);let E=`${a.pathname}${a.search}`;A==="replace"?history.replaceState(null,"",E):A==="push"&&history.pushState(null,"",E)}catch(p){console.error("[webframez-react] Failed to render route",p),r(u("p",{children:"Failed to load route."}))}finally{R(!1)}}y(()=>{O(d)},[d]),y(()=>{L(!0);let a=()=>{l(new URL(window.location.href),"none")};return window.addEventListener("popstate",a),()=>{window.removeEventListener("popstate",a)}},[]);let h=c.useMemo(()=>({push:a=>{l(new URL(a,window.location.origin),"push")},replace:a=>{l(new URL(a,window.location.origin),"replace")},refresh:()=>{l(new URL(window.location.href),"none")}}),[]);j(h);let C=te(ee,{children:[$?u(X,{active:U}):null,i??u("p",{style:{padding:24},children:"Loading..."})]});return m?u(m.Provider,{value:h,children:C}):C}}function ce(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,i=e.rscEndpoint??o??"/rsc",r=J(i),d=Q(r,i);return M(n,u(d,{}))}export{ce as mountWebframezClient,de as useCookie,ue as useRouter};
|
package/dist/http.cjs
CHANGED
|
@@ -42,7 +42,7 @@ var import_node_path = __toESM(require("node:path"), 1);
|
|
|
42
42
|
var import_node_stream = require("node:stream");
|
|
43
43
|
var import_node_module = require("node:module");
|
|
44
44
|
var import_server = require("react-server-dom-webpack/server");
|
|
45
|
-
var
|
|
45
|
+
var reactServerDomClientNode = __toESM(require("react-server-dom-webpack/client.node"), 1);
|
|
46
46
|
function defaultOnError(err) {
|
|
47
47
|
console.error("[webframez-react] RSC render error", err);
|
|
48
48
|
}
|
|
@@ -55,6 +55,7 @@ function createHTMLShell(options = {}) {
|
|
|
55
55
|
rootHtml = "",
|
|
56
56
|
initialFlightData = "",
|
|
57
57
|
basename = "",
|
|
58
|
+
routeBasePath = "",
|
|
58
59
|
liveReloadPath,
|
|
59
60
|
liveReloadServerId
|
|
60
61
|
} = options;
|
|
@@ -103,6 +104,7 @@ function createHTMLShell(options = {}) {
|
|
|
103
104
|
<div id="root">${rootHtml}</div>
|
|
104
105
|
<script>window.__RSC_ENDPOINT = "${rscEndpoint}";</script>
|
|
105
106
|
<script>window.__RSC_BASENAME = "${basename}";</script>
|
|
107
|
+
<script>window.__RSC_ROUTE_BASE_PATH = "${routeBasePath}";</script>
|
|
106
108
|
<script>window.__RSC_INITIAL_PAYLOAD = ${escapedInitialFlightData};</script>
|
|
107
109
|
<script type="module" src="${clientScriptUrl}"></script>
|
|
108
110
|
${liveReloadScript}
|
|
@@ -153,12 +155,12 @@ var import_node_path2 = __toESM(require("node:path"), 1);
|
|
|
153
155
|
// src/head.ts
|
|
154
156
|
var ABSOLUTE_ASSET_URL_PATTERN = /^(?:[a-zA-Z][a-zA-Z\d+\-.]*:|\/\/|#)/;
|
|
155
157
|
function normalizeHeadBasename(value) {
|
|
156
|
-
|
|
157
|
-
if (!trimmed) {
|
|
158
|
+
if (typeof value !== "string") {
|
|
158
159
|
return void 0;
|
|
159
160
|
}
|
|
160
|
-
|
|
161
|
-
|
|
161
|
+
const trimmed = value.trim();
|
|
162
|
+
if (!trimmed || trimmed === "/") {
|
|
163
|
+
return "";
|
|
162
164
|
}
|
|
163
165
|
return trimmed.replace(/\/+$/, "");
|
|
164
166
|
}
|
|
@@ -171,6 +173,9 @@ function resolveHeadAssetUrl(assetUrl, basename) {
|
|
|
171
173
|
if (ABSOLUTE_ASSET_URL_PATTERN.test(normalizedAssetUrl)) {
|
|
172
174
|
return normalizedAssetUrl;
|
|
173
175
|
}
|
|
176
|
+
if (normalizedAssetUrl.startsWith("/")) {
|
|
177
|
+
return normalizedAssetUrl;
|
|
178
|
+
}
|
|
174
179
|
if (normalizedBasename !== "/" && (normalizedAssetUrl === normalizedBasename || normalizedAssetUrl.startsWith(`${normalizedBasename}/`))) {
|
|
175
180
|
return normalizedAssetUrl;
|
|
176
181
|
}
|
|
@@ -187,9 +192,15 @@ function normalizeHeadConfig(head, inheritedBasename) {
|
|
|
187
192
|
return void 0;
|
|
188
193
|
}
|
|
189
194
|
const effectiveBasename = normalizeHeadBasename(head.basename) ?? normalizeHeadBasename(inheritedBasename);
|
|
195
|
+
const normalizedRouteBasePath = normalizeHeadBasename(head.routeBasePath);
|
|
196
|
+
const normalizedTransportBasePath = normalizeHeadBasename(
|
|
197
|
+
head.transportBasePath
|
|
198
|
+
);
|
|
190
199
|
const normalizedHead = {
|
|
191
200
|
...head,
|
|
192
|
-
...effectiveBasename ? { basename: effectiveBasename } : {}
|
|
201
|
+
...effectiveBasename !== void 0 ? { basename: effectiveBasename } : {},
|
|
202
|
+
...normalizedRouteBasePath !== void 0 ? { routeBasePath: normalizedRouteBasePath } : {},
|
|
203
|
+
...normalizedTransportBasePath !== void 0 ? { transportBasePath: normalizedTransportBasePath } : {}
|
|
193
204
|
};
|
|
194
205
|
if (normalizedHead.favicon) {
|
|
195
206
|
normalizedHead.favicon = resolveHeadAssetUrl(
|
|
@@ -746,8 +757,8 @@ function createInitialHtmlErrorMarkup(message) {
|
|
|
746
757
|
var INITIAL_HTML_WORKER_SCRIPT = `
|
|
747
758
|
const path = require("node:path");
|
|
748
759
|
const Module = require("node:module");
|
|
749
|
-
const { Writable } = require("node:stream");
|
|
750
|
-
const
|
|
760
|
+
const { Readable, Writable } = require("node:stream");
|
|
761
|
+
const reactServerDomClientNode = require("react-server-dom-webpack/client.node");
|
|
751
762
|
|
|
752
763
|
const originalResolveFilename = Module._resolveFilename;
|
|
753
764
|
const rootParent = {
|
|
@@ -865,14 +876,34 @@ function createReadableStreamFromString(value) {
|
|
|
865
876
|
});
|
|
866
877
|
}
|
|
867
878
|
|
|
879
|
+
async function decodeFlightPayloadFromString(flightData, moduleMap) {
|
|
880
|
+
const serverConsumerManifest = {
|
|
881
|
+
moduleMap: moduleMap || {},
|
|
882
|
+
serverModuleMap: null,
|
|
883
|
+
moduleLoading: null
|
|
884
|
+
};
|
|
885
|
+
|
|
886
|
+
if (typeof reactServerDomClientNode.createFromNodeStream === "function") {
|
|
887
|
+
return await reactServerDomClientNode.createFromNodeStream(
|
|
888
|
+
Readable.from([flightData]),
|
|
889
|
+
serverConsumerManifest
|
|
890
|
+
);
|
|
891
|
+
}
|
|
892
|
+
|
|
893
|
+
if (typeof reactServerDomClientNode.createFromReadableStream === "function") {
|
|
894
|
+
return await reactServerDomClientNode.createFromReadableStream(
|
|
895
|
+
createReadableStreamFromString(flightData),
|
|
896
|
+
{ serverConsumerManifest }
|
|
897
|
+
);
|
|
898
|
+
}
|
|
899
|
+
|
|
900
|
+
throw new Error(
|
|
901
|
+
"react-server-dom-webpack/client.node does not provide createFromNodeStream or createFromReadableStream."
|
|
902
|
+
);
|
|
903
|
+
}
|
|
904
|
+
|
|
868
905
|
async function renderHtmlFromFlightData(flightData, moduleMap) {
|
|
869
|
-
const payload = await
|
|
870
|
-
serverConsumerManifest: {
|
|
871
|
-
moduleMap: moduleMap || {},
|
|
872
|
-
serverModuleMap: null,
|
|
873
|
-
moduleLoading: null
|
|
874
|
-
}
|
|
875
|
-
});
|
|
906
|
+
const payload = await decodeFlightPayloadFromString(flightData, moduleMap);
|
|
876
907
|
|
|
877
908
|
const model =
|
|
878
909
|
payload && typeof payload === "object" && "model" in payload
|
|
@@ -979,6 +1010,23 @@ function stripBasePath(pathname, basePath) {
|
|
|
979
1010
|
}
|
|
980
1011
|
return pathname;
|
|
981
1012
|
}
|
|
1013
|
+
function normalizeRuntimeBasePath(value) {
|
|
1014
|
+
if (typeof value !== "string") {
|
|
1015
|
+
return void 0;
|
|
1016
|
+
}
|
|
1017
|
+
const trimmed = value.trim();
|
|
1018
|
+
if (!trimmed || trimmed === "/") {
|
|
1019
|
+
return "";
|
|
1020
|
+
}
|
|
1021
|
+
return trimmed.replace(/\/+$/, "");
|
|
1022
|
+
}
|
|
1023
|
+
function joinRuntimeBasePath(basePath, pathname) {
|
|
1024
|
+
const normalizedPath = !pathname || pathname === "/" ? "/" : pathname.startsWith("/") ? pathname : `/${pathname}`;
|
|
1025
|
+
if (!basePath) {
|
|
1026
|
+
return normalizedPath;
|
|
1027
|
+
}
|
|
1028
|
+
return normalizedPath === "/" ? basePath : `${basePath}${normalizedPath}`;
|
|
1029
|
+
}
|
|
982
1030
|
function sanitizeInitialHtmlWorkerNodeOptions(rawNodeOptions) {
|
|
983
1031
|
if (!rawNodeOptions || rawNodeOptions.trim() === "") {
|
|
984
1032
|
return "";
|
|
@@ -1379,6 +1427,14 @@ function createNodeRequestHandler(options) {
|
|
|
1379
1427
|
const initialFlightData = await renderRSCToString(initialPayload, {
|
|
1380
1428
|
moduleMap
|
|
1381
1429
|
});
|
|
1430
|
+
const transportBasePath = normalizeRuntimeBasePath(resolved.head.transportBasePath) ?? normalizeRuntimeBasePath(basePath) ?? "";
|
|
1431
|
+
const shellClientScriptUrl = joinRuntimeBasePath(
|
|
1432
|
+
transportBasePath,
|
|
1433
|
+
"/assets/client.js"
|
|
1434
|
+
);
|
|
1435
|
+
const shellRscEndpoint = joinRuntimeBasePath(transportBasePath, "/rsc");
|
|
1436
|
+
const shellBasename = normalizeRuntimeBasePath(resolved.head.basename) ?? normalizeRuntimeBasePath(basePath) ?? "";
|
|
1437
|
+
const shellRouteBasePath = normalizeRuntimeBasePath(resolved.head.routeBasePath) ?? "";
|
|
1382
1438
|
let rootHtml = "";
|
|
1383
1439
|
try {
|
|
1384
1440
|
rootHtml = await initialHtmlWorker.renderFromFlightData({
|
|
@@ -1409,11 +1465,12 @@ function createNodeRequestHandler(options) {
|
|
|
1409
1465
|
createHTMLShell({
|
|
1410
1466
|
title: "500 - Initial HTML render failed",
|
|
1411
1467
|
headTags: "",
|
|
1412
|
-
clientScriptUrl,
|
|
1413
|
-
rscEndpoint:
|
|
1468
|
+
clientScriptUrl: shellClientScriptUrl,
|
|
1469
|
+
rscEndpoint: shellRscEndpoint,
|
|
1414
1470
|
rootHtml: createInitialHtmlErrorMarkup("Initial HTML render failed."),
|
|
1415
1471
|
initialFlightData,
|
|
1416
|
-
basename:
|
|
1472
|
+
basename: shellBasename,
|
|
1473
|
+
routeBasePath: shellRouteBasePath,
|
|
1417
1474
|
liveReloadPath: liveReloadPath || void 0,
|
|
1418
1475
|
liveReloadServerId: liveReloadPath ? devServerId : void 0
|
|
1419
1476
|
})
|
|
@@ -1428,11 +1485,12 @@ function createNodeRequestHandler(options) {
|
|
|
1428
1485
|
createHTMLShell({
|
|
1429
1486
|
title: resolved.head.title || "Webframez React",
|
|
1430
1487
|
headTags: renderHeadToString(resolved.head),
|
|
1431
|
-
clientScriptUrl,
|
|
1432
|
-
rscEndpoint:
|
|
1488
|
+
clientScriptUrl: shellClientScriptUrl,
|
|
1489
|
+
rscEndpoint: shellRscEndpoint,
|
|
1433
1490
|
rootHtml,
|
|
1434
1491
|
initialFlightData,
|
|
1435
|
-
basename:
|
|
1492
|
+
basename: shellBasename,
|
|
1493
|
+
routeBasePath: shellRouteBasePath,
|
|
1436
1494
|
liveReloadPath: liveReloadPath || void 0,
|
|
1437
1495
|
liveReloadServerId: liveReloadPath ? devServerId : void 0
|
|
1438
1496
|
})
|
package/dist/http.js
CHANGED
|
@@ -14,10 +14,10 @@ import { spawn } from "node:child_process";
|
|
|
14
14
|
|
|
15
15
|
// src/server.ts
|
|
16
16
|
import path from "node:path";
|
|
17
|
-
import { Writable } from "node:stream";
|
|
17
|
+
import { Readable, Writable } from "node:stream";
|
|
18
18
|
import { createRequire } from "node:module";
|
|
19
19
|
import { renderToPipeableStream } from "react-server-dom-webpack/server";
|
|
20
|
-
import
|
|
20
|
+
import * as reactServerDomClientNode from "react-server-dom-webpack/client.node";
|
|
21
21
|
function defaultOnError(err) {
|
|
22
22
|
console.error("[webframez-react] RSC render error", err);
|
|
23
23
|
}
|
|
@@ -30,6 +30,7 @@ function createHTMLShell(options = {}) {
|
|
|
30
30
|
rootHtml = "",
|
|
31
31
|
initialFlightData = "",
|
|
32
32
|
basename = "",
|
|
33
|
+
routeBasePath = "",
|
|
33
34
|
liveReloadPath,
|
|
34
35
|
liveReloadServerId
|
|
35
36
|
} = options;
|
|
@@ -78,6 +79,7 @@ function createHTMLShell(options = {}) {
|
|
|
78
79
|
<div id="root">${rootHtml}</div>
|
|
79
80
|
<script>window.__RSC_ENDPOINT = "${rscEndpoint}";</script>
|
|
80
81
|
<script>window.__RSC_BASENAME = "${basename}";</script>
|
|
82
|
+
<script>window.__RSC_ROUTE_BASE_PATH = "${routeBasePath}";</script>
|
|
81
83
|
<script>window.__RSC_INITIAL_PAYLOAD = ${escapedInitialFlightData};</script>
|
|
82
84
|
<script type="module" src="${clientScriptUrl}"></script>
|
|
83
85
|
${liveReloadScript}
|
|
@@ -128,12 +130,12 @@ import path2 from "node:path";
|
|
|
128
130
|
// src/head.ts
|
|
129
131
|
var ABSOLUTE_ASSET_URL_PATTERN = /^(?:[a-zA-Z][a-zA-Z\d+\-.]*:|\/\/|#)/;
|
|
130
132
|
function normalizeHeadBasename(value) {
|
|
131
|
-
|
|
132
|
-
if (!trimmed) {
|
|
133
|
+
if (typeof value !== "string") {
|
|
133
134
|
return void 0;
|
|
134
135
|
}
|
|
135
|
-
|
|
136
|
-
|
|
136
|
+
const trimmed = value.trim();
|
|
137
|
+
if (!trimmed || trimmed === "/") {
|
|
138
|
+
return "";
|
|
137
139
|
}
|
|
138
140
|
return trimmed.replace(/\/+$/, "");
|
|
139
141
|
}
|
|
@@ -146,6 +148,9 @@ function resolveHeadAssetUrl(assetUrl, basename) {
|
|
|
146
148
|
if (ABSOLUTE_ASSET_URL_PATTERN.test(normalizedAssetUrl)) {
|
|
147
149
|
return normalizedAssetUrl;
|
|
148
150
|
}
|
|
151
|
+
if (normalizedAssetUrl.startsWith("/")) {
|
|
152
|
+
return normalizedAssetUrl;
|
|
153
|
+
}
|
|
149
154
|
if (normalizedBasename !== "/" && (normalizedAssetUrl === normalizedBasename || normalizedAssetUrl.startsWith(`${normalizedBasename}/`))) {
|
|
150
155
|
return normalizedAssetUrl;
|
|
151
156
|
}
|
|
@@ -162,9 +167,15 @@ function normalizeHeadConfig(head, inheritedBasename) {
|
|
|
162
167
|
return void 0;
|
|
163
168
|
}
|
|
164
169
|
const effectiveBasename = normalizeHeadBasename(head.basename) ?? normalizeHeadBasename(inheritedBasename);
|
|
170
|
+
const normalizedRouteBasePath = normalizeHeadBasename(head.routeBasePath);
|
|
171
|
+
const normalizedTransportBasePath = normalizeHeadBasename(
|
|
172
|
+
head.transportBasePath
|
|
173
|
+
);
|
|
165
174
|
const normalizedHead = {
|
|
166
175
|
...head,
|
|
167
|
-
...effectiveBasename ? { basename: effectiveBasename } : {}
|
|
176
|
+
...effectiveBasename !== void 0 ? { basename: effectiveBasename } : {},
|
|
177
|
+
...normalizedRouteBasePath !== void 0 ? { routeBasePath: normalizedRouteBasePath } : {},
|
|
178
|
+
...normalizedTransportBasePath !== void 0 ? { transportBasePath: normalizedTransportBasePath } : {}
|
|
168
179
|
};
|
|
169
180
|
if (normalizedHead.favicon) {
|
|
170
181
|
normalizedHead.favicon = resolveHeadAssetUrl(
|
|
@@ -721,8 +732,8 @@ function createInitialHtmlErrorMarkup(message) {
|
|
|
721
732
|
var INITIAL_HTML_WORKER_SCRIPT = `
|
|
722
733
|
const path = require("node:path");
|
|
723
734
|
const Module = require("node:module");
|
|
724
|
-
const { Writable } = require("node:stream");
|
|
725
|
-
const
|
|
735
|
+
const { Readable, Writable } = require("node:stream");
|
|
736
|
+
const reactServerDomClientNode = require("react-server-dom-webpack/client.node");
|
|
726
737
|
|
|
727
738
|
const originalResolveFilename = Module._resolveFilename;
|
|
728
739
|
const rootParent = {
|
|
@@ -840,14 +851,34 @@ function createReadableStreamFromString(value) {
|
|
|
840
851
|
});
|
|
841
852
|
}
|
|
842
853
|
|
|
854
|
+
async function decodeFlightPayloadFromString(flightData, moduleMap) {
|
|
855
|
+
const serverConsumerManifest = {
|
|
856
|
+
moduleMap: moduleMap || {},
|
|
857
|
+
serverModuleMap: null,
|
|
858
|
+
moduleLoading: null
|
|
859
|
+
};
|
|
860
|
+
|
|
861
|
+
if (typeof reactServerDomClientNode.createFromNodeStream === "function") {
|
|
862
|
+
return await reactServerDomClientNode.createFromNodeStream(
|
|
863
|
+
Readable.from([flightData]),
|
|
864
|
+
serverConsumerManifest
|
|
865
|
+
);
|
|
866
|
+
}
|
|
867
|
+
|
|
868
|
+
if (typeof reactServerDomClientNode.createFromReadableStream === "function") {
|
|
869
|
+
return await reactServerDomClientNode.createFromReadableStream(
|
|
870
|
+
createReadableStreamFromString(flightData),
|
|
871
|
+
{ serverConsumerManifest }
|
|
872
|
+
);
|
|
873
|
+
}
|
|
874
|
+
|
|
875
|
+
throw new Error(
|
|
876
|
+
"react-server-dom-webpack/client.node does not provide createFromNodeStream or createFromReadableStream."
|
|
877
|
+
);
|
|
878
|
+
}
|
|
879
|
+
|
|
843
880
|
async function renderHtmlFromFlightData(flightData, moduleMap) {
|
|
844
|
-
const payload = await
|
|
845
|
-
serverConsumerManifest: {
|
|
846
|
-
moduleMap: moduleMap || {},
|
|
847
|
-
serverModuleMap: null,
|
|
848
|
-
moduleLoading: null
|
|
849
|
-
}
|
|
850
|
-
});
|
|
881
|
+
const payload = await decodeFlightPayloadFromString(flightData, moduleMap);
|
|
851
882
|
|
|
852
883
|
const model =
|
|
853
884
|
payload && typeof payload === "object" && "model" in payload
|
|
@@ -954,6 +985,23 @@ function stripBasePath(pathname, basePath) {
|
|
|
954
985
|
}
|
|
955
986
|
return pathname;
|
|
956
987
|
}
|
|
988
|
+
function normalizeRuntimeBasePath(value) {
|
|
989
|
+
if (typeof value !== "string") {
|
|
990
|
+
return void 0;
|
|
991
|
+
}
|
|
992
|
+
const trimmed = value.trim();
|
|
993
|
+
if (!trimmed || trimmed === "/") {
|
|
994
|
+
return "";
|
|
995
|
+
}
|
|
996
|
+
return trimmed.replace(/\/+$/, "");
|
|
997
|
+
}
|
|
998
|
+
function joinRuntimeBasePath(basePath, pathname) {
|
|
999
|
+
const normalizedPath = !pathname || pathname === "/" ? "/" : pathname.startsWith("/") ? pathname : `/${pathname}`;
|
|
1000
|
+
if (!basePath) {
|
|
1001
|
+
return normalizedPath;
|
|
1002
|
+
}
|
|
1003
|
+
return normalizedPath === "/" ? basePath : `${basePath}${normalizedPath}`;
|
|
1004
|
+
}
|
|
957
1005
|
function sanitizeInitialHtmlWorkerNodeOptions(rawNodeOptions) {
|
|
958
1006
|
if (!rawNodeOptions || rawNodeOptions.trim() === "") {
|
|
959
1007
|
return "";
|
|
@@ -1354,6 +1402,14 @@ function createNodeRequestHandler(options) {
|
|
|
1354
1402
|
const initialFlightData = await renderRSCToString(initialPayload, {
|
|
1355
1403
|
moduleMap
|
|
1356
1404
|
});
|
|
1405
|
+
const transportBasePath = normalizeRuntimeBasePath(resolved.head.transportBasePath) ?? normalizeRuntimeBasePath(basePath) ?? "";
|
|
1406
|
+
const shellClientScriptUrl = joinRuntimeBasePath(
|
|
1407
|
+
transportBasePath,
|
|
1408
|
+
"/assets/client.js"
|
|
1409
|
+
);
|
|
1410
|
+
const shellRscEndpoint = joinRuntimeBasePath(transportBasePath, "/rsc");
|
|
1411
|
+
const shellBasename = normalizeRuntimeBasePath(resolved.head.basename) ?? normalizeRuntimeBasePath(basePath) ?? "";
|
|
1412
|
+
const shellRouteBasePath = normalizeRuntimeBasePath(resolved.head.routeBasePath) ?? "";
|
|
1357
1413
|
let rootHtml = "";
|
|
1358
1414
|
try {
|
|
1359
1415
|
rootHtml = await initialHtmlWorker.renderFromFlightData({
|
|
@@ -1384,11 +1440,12 @@ function createNodeRequestHandler(options) {
|
|
|
1384
1440
|
createHTMLShell({
|
|
1385
1441
|
title: "500 - Initial HTML render failed",
|
|
1386
1442
|
headTags: "",
|
|
1387
|
-
clientScriptUrl,
|
|
1388
|
-
rscEndpoint:
|
|
1443
|
+
clientScriptUrl: shellClientScriptUrl,
|
|
1444
|
+
rscEndpoint: shellRscEndpoint,
|
|
1389
1445
|
rootHtml: createInitialHtmlErrorMarkup("Initial HTML render failed."),
|
|
1390
1446
|
initialFlightData,
|
|
1391
|
-
basename:
|
|
1447
|
+
basename: shellBasename,
|
|
1448
|
+
routeBasePath: shellRouteBasePath,
|
|
1392
1449
|
liveReloadPath: liveReloadPath || void 0,
|
|
1393
1450
|
liveReloadServerId: liveReloadPath ? devServerId : void 0
|
|
1394
1451
|
})
|
|
@@ -1403,11 +1460,12 @@ function createNodeRequestHandler(options) {
|
|
|
1403
1460
|
createHTMLShell({
|
|
1404
1461
|
title: resolved.head.title || "Webframez React",
|
|
1405
1462
|
headTags: renderHeadToString(resolved.head),
|
|
1406
|
-
clientScriptUrl,
|
|
1407
|
-
rscEndpoint:
|
|
1463
|
+
clientScriptUrl: shellClientScriptUrl,
|
|
1464
|
+
rscEndpoint: shellRscEndpoint,
|
|
1408
1465
|
rootHtml,
|
|
1409
1466
|
initialFlightData,
|
|
1410
|
-
basename:
|
|
1467
|
+
basename: shellBasename,
|
|
1468
|
+
routeBasePath: shellRouteBasePath,
|
|
1411
1469
|
liveReloadPath: liveReloadPath || void 0,
|
|
1412
1470
|
liveReloadServerId: liveReloadPath ? devServerId : void 0
|
|
1413
1471
|
})
|
package/dist/index.cjs
CHANGED
|
@@ -47,7 +47,7 @@ var import_node_path = __toESM(require("node:path"), 1);
|
|
|
47
47
|
var import_node_stream = require("node:stream");
|
|
48
48
|
var import_node_module = require("node:module");
|
|
49
49
|
var import_server = require("react-server-dom-webpack/server");
|
|
50
|
-
var
|
|
50
|
+
var reactServerDomClientNode = __toESM(require("react-server-dom-webpack/client.node"), 1);
|
|
51
51
|
function defaultOnError(err) {
|
|
52
52
|
console.error("[webframez-react] RSC render error", err);
|
|
53
53
|
}
|
|
@@ -60,6 +60,7 @@ function createHTMLShell(options = {}) {
|
|
|
60
60
|
rootHtml = "",
|
|
61
61
|
initialFlightData = "",
|
|
62
62
|
basename = "",
|
|
63
|
+
routeBasePath = "",
|
|
63
64
|
liveReloadPath,
|
|
64
65
|
liveReloadServerId
|
|
65
66
|
} = options;
|
|
@@ -108,6 +109,7 @@ function createHTMLShell(options = {}) {
|
|
|
108
109
|
<div id="root">${rootHtml}</div>
|
|
109
110
|
<script>window.__RSC_ENDPOINT = "${rscEndpoint}";</script>
|
|
110
111
|
<script>window.__RSC_BASENAME = "${basename}";</script>
|
|
112
|
+
<script>window.__RSC_ROUTE_BASE_PATH = "${routeBasePath}";</script>
|
|
111
113
|
<script>window.__RSC_INITIAL_PAYLOAD = ${escapedInitialFlightData};</script>
|
|
112
114
|
<script type="module" src="${clientScriptUrl}"></script>
|
|
113
115
|
${liveReloadScript}
|
|
@@ -186,12 +188,12 @@ var import_node_path2 = __toESM(require("node:path"), 1);
|
|
|
186
188
|
// src/head.ts
|
|
187
189
|
var ABSOLUTE_ASSET_URL_PATTERN = /^(?:[a-zA-Z][a-zA-Z\d+\-.]*:|\/\/|#)/;
|
|
188
190
|
function normalizeHeadBasename(value) {
|
|
189
|
-
|
|
190
|
-
if (!trimmed) {
|
|
191
|
+
if (typeof value !== "string") {
|
|
191
192
|
return void 0;
|
|
192
193
|
}
|
|
193
|
-
|
|
194
|
-
|
|
194
|
+
const trimmed = value.trim();
|
|
195
|
+
if (!trimmed || trimmed === "/") {
|
|
196
|
+
return "";
|
|
195
197
|
}
|
|
196
198
|
return trimmed.replace(/\/+$/, "");
|
|
197
199
|
}
|
|
@@ -204,6 +206,9 @@ function resolveHeadAssetUrl(assetUrl, basename) {
|
|
|
204
206
|
if (ABSOLUTE_ASSET_URL_PATTERN.test(normalizedAssetUrl)) {
|
|
205
207
|
return normalizedAssetUrl;
|
|
206
208
|
}
|
|
209
|
+
if (normalizedAssetUrl.startsWith("/")) {
|
|
210
|
+
return normalizedAssetUrl;
|
|
211
|
+
}
|
|
207
212
|
if (normalizedBasename !== "/" && (normalizedAssetUrl === normalizedBasename || normalizedAssetUrl.startsWith(`${normalizedBasename}/`))) {
|
|
208
213
|
return normalizedAssetUrl;
|
|
209
214
|
}
|
|
@@ -220,9 +225,15 @@ function normalizeHeadConfig(head, inheritedBasename) {
|
|
|
220
225
|
return void 0;
|
|
221
226
|
}
|
|
222
227
|
const effectiveBasename = normalizeHeadBasename(head.basename) ?? normalizeHeadBasename(inheritedBasename);
|
|
228
|
+
const normalizedRouteBasePath = normalizeHeadBasename(head.routeBasePath);
|
|
229
|
+
const normalizedTransportBasePath = normalizeHeadBasename(
|
|
230
|
+
head.transportBasePath
|
|
231
|
+
);
|
|
223
232
|
const normalizedHead = {
|
|
224
233
|
...head,
|
|
225
|
-
...effectiveBasename ? { basename: effectiveBasename } : {}
|
|
234
|
+
...effectiveBasename !== void 0 ? { basename: effectiveBasename } : {},
|
|
235
|
+
...normalizedRouteBasePath !== void 0 ? { routeBasePath: normalizedRouteBasePath } : {},
|
|
236
|
+
...normalizedTransportBasePath !== void 0 ? { transportBasePath: normalizedTransportBasePath } : {}
|
|
226
237
|
};
|
|
227
238
|
if (normalizedHead.favicon) {
|
|
228
239
|
normalizedHead.favicon = resolveHeadAssetUrl(
|
|
@@ -783,8 +794,8 @@ function createInitialHtmlErrorMarkup(message) {
|
|
|
783
794
|
var INITIAL_HTML_WORKER_SCRIPT = `
|
|
784
795
|
const path = require("node:path");
|
|
785
796
|
const Module = require("node:module");
|
|
786
|
-
const { Writable } = require("node:stream");
|
|
787
|
-
const
|
|
797
|
+
const { Readable, Writable } = require("node:stream");
|
|
798
|
+
const reactServerDomClientNode = require("react-server-dom-webpack/client.node");
|
|
788
799
|
|
|
789
800
|
const originalResolveFilename = Module._resolveFilename;
|
|
790
801
|
const rootParent = {
|
|
@@ -902,14 +913,34 @@ function createReadableStreamFromString(value) {
|
|
|
902
913
|
});
|
|
903
914
|
}
|
|
904
915
|
|
|
916
|
+
async function decodeFlightPayloadFromString(flightData, moduleMap) {
|
|
917
|
+
const serverConsumerManifest = {
|
|
918
|
+
moduleMap: moduleMap || {},
|
|
919
|
+
serverModuleMap: null,
|
|
920
|
+
moduleLoading: null
|
|
921
|
+
};
|
|
922
|
+
|
|
923
|
+
if (typeof reactServerDomClientNode.createFromNodeStream === "function") {
|
|
924
|
+
return await reactServerDomClientNode.createFromNodeStream(
|
|
925
|
+
Readable.from([flightData]),
|
|
926
|
+
serverConsumerManifest
|
|
927
|
+
);
|
|
928
|
+
}
|
|
929
|
+
|
|
930
|
+
if (typeof reactServerDomClientNode.createFromReadableStream === "function") {
|
|
931
|
+
return await reactServerDomClientNode.createFromReadableStream(
|
|
932
|
+
createReadableStreamFromString(flightData),
|
|
933
|
+
{ serverConsumerManifest }
|
|
934
|
+
);
|
|
935
|
+
}
|
|
936
|
+
|
|
937
|
+
throw new Error(
|
|
938
|
+
"react-server-dom-webpack/client.node does not provide createFromNodeStream or createFromReadableStream."
|
|
939
|
+
);
|
|
940
|
+
}
|
|
941
|
+
|
|
905
942
|
async function renderHtmlFromFlightData(flightData, moduleMap) {
|
|
906
|
-
const payload = await
|
|
907
|
-
serverConsumerManifest: {
|
|
908
|
-
moduleMap: moduleMap || {},
|
|
909
|
-
serverModuleMap: null,
|
|
910
|
-
moduleLoading: null
|
|
911
|
-
}
|
|
912
|
-
});
|
|
943
|
+
const payload = await decodeFlightPayloadFromString(flightData, moduleMap);
|
|
913
944
|
|
|
914
945
|
const model =
|
|
915
946
|
payload && typeof payload === "object" && "model" in payload
|
|
@@ -1016,6 +1047,23 @@ function stripBasePath(pathname, basePath) {
|
|
|
1016
1047
|
}
|
|
1017
1048
|
return pathname;
|
|
1018
1049
|
}
|
|
1050
|
+
function normalizeRuntimeBasePath(value) {
|
|
1051
|
+
if (typeof value !== "string") {
|
|
1052
|
+
return void 0;
|
|
1053
|
+
}
|
|
1054
|
+
const trimmed = value.trim();
|
|
1055
|
+
if (!trimmed || trimmed === "/") {
|
|
1056
|
+
return "";
|
|
1057
|
+
}
|
|
1058
|
+
return trimmed.replace(/\/+$/, "");
|
|
1059
|
+
}
|
|
1060
|
+
function joinRuntimeBasePath(basePath, pathname) {
|
|
1061
|
+
const normalizedPath = !pathname || pathname === "/" ? "/" : pathname.startsWith("/") ? pathname : `/${pathname}`;
|
|
1062
|
+
if (!basePath) {
|
|
1063
|
+
return normalizedPath;
|
|
1064
|
+
}
|
|
1065
|
+
return normalizedPath === "/" ? basePath : `${basePath}${normalizedPath}`;
|
|
1066
|
+
}
|
|
1019
1067
|
function sanitizeInitialHtmlWorkerNodeOptions(rawNodeOptions) {
|
|
1020
1068
|
if (!rawNodeOptions || rawNodeOptions.trim() === "") {
|
|
1021
1069
|
return "";
|
|
@@ -1416,6 +1464,14 @@ function createNodeRequestHandler(options) {
|
|
|
1416
1464
|
const initialFlightData = await renderRSCToString(initialPayload, {
|
|
1417
1465
|
moduleMap
|
|
1418
1466
|
});
|
|
1467
|
+
const transportBasePath = normalizeRuntimeBasePath(resolved.head.transportBasePath) ?? normalizeRuntimeBasePath(basePath) ?? "";
|
|
1468
|
+
const shellClientScriptUrl = joinRuntimeBasePath(
|
|
1469
|
+
transportBasePath,
|
|
1470
|
+
"/assets/client.js"
|
|
1471
|
+
);
|
|
1472
|
+
const shellRscEndpoint = joinRuntimeBasePath(transportBasePath, "/rsc");
|
|
1473
|
+
const shellBasename = normalizeRuntimeBasePath(resolved.head.basename) ?? normalizeRuntimeBasePath(basePath) ?? "";
|
|
1474
|
+
const shellRouteBasePath = normalizeRuntimeBasePath(resolved.head.routeBasePath) ?? "";
|
|
1419
1475
|
let rootHtml = "";
|
|
1420
1476
|
try {
|
|
1421
1477
|
rootHtml = await initialHtmlWorker.renderFromFlightData({
|
|
@@ -1446,11 +1502,12 @@ function createNodeRequestHandler(options) {
|
|
|
1446
1502
|
createHTMLShell({
|
|
1447
1503
|
title: "500 - Initial HTML render failed",
|
|
1448
1504
|
headTags: "",
|
|
1449
|
-
clientScriptUrl,
|
|
1450
|
-
rscEndpoint:
|
|
1505
|
+
clientScriptUrl: shellClientScriptUrl,
|
|
1506
|
+
rscEndpoint: shellRscEndpoint,
|
|
1451
1507
|
rootHtml: createInitialHtmlErrorMarkup("Initial HTML render failed."),
|
|
1452
1508
|
initialFlightData,
|
|
1453
|
-
basename:
|
|
1509
|
+
basename: shellBasename,
|
|
1510
|
+
routeBasePath: shellRouteBasePath,
|
|
1454
1511
|
liveReloadPath: liveReloadPath || void 0,
|
|
1455
1512
|
liveReloadServerId: liveReloadPath ? devServerId : void 0
|
|
1456
1513
|
})
|
|
@@ -1465,11 +1522,12 @@ function createNodeRequestHandler(options) {
|
|
|
1465
1522
|
createHTMLShell({
|
|
1466
1523
|
title: resolved.head.title || "Webframez React",
|
|
1467
1524
|
headTags: renderHeadToString(resolved.head),
|
|
1468
|
-
clientScriptUrl,
|
|
1469
|
-
rscEndpoint:
|
|
1525
|
+
clientScriptUrl: shellClientScriptUrl,
|
|
1526
|
+
rscEndpoint: shellRscEndpoint,
|
|
1470
1527
|
rootHtml,
|
|
1471
1528
|
initialFlightData,
|
|
1472
|
-
basename:
|
|
1529
|
+
basename: shellBasename,
|
|
1530
|
+
routeBasePath: shellRouteBasePath,
|
|
1473
1531
|
liveReloadPath: liveReloadPath || void 0,
|
|
1474
1532
|
liveReloadServerId: liveReloadPath ? devServerId : void 0
|
|
1475
1533
|
})
|