@webtypen/webframez-react 0.0.6 → 0.0.7
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 +34 -0
- package/dist/http.js +34 -0
- package/dist/index.cjs +34 -0
- package/dist/index.js +34 -0
- package/dist/webframez-core.cjs +34 -0
- package/dist/webframez-core.js +34 -0
- package/package.json +1 -1
package/dist/client.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var P=Object.create;var f=Object.defineProperty;var O=Object.getOwnPropertyDescriptor;var T=Object.getOwnPropertyNames;var N=Object.getPrototypeOf,U=Object.prototype.hasOwnProperty;var $=(e,t)=>{for(var n in t)f(e,n,{get:t[n],enumerable:!0})},_=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of T(t))!U.call(e,i)&&i!==n&&f(e,i,{get:()=>t[i],enumerable:!(o=O(t,i))||o.enumerable});return e};var M=(e,t,n)=>(n=e!=null?P(N(e)):{},_(t||!e||!e.__esModule?f(n,"default",{value:e,enumerable:!0}):n,e)),H=e=>_(f({},"__esModule",{value:!0}),e);var X={};$(X,{mountWebframezClient:()=>j,useCookie:()=>z,useRouter:()=>G});module.exports=H(X);var r=M(require("react"),1),S=require("react-dom/client"),u=require("react-server-dom-webpack/client"),a=require("react/jsx-runtime"),W={push:()=>{},replace:()=>{},refresh:()=>{}},p=typeof r.default.createContext=="function"?r.default.createContext(null):null,k="__WEBFRAMEZ_ROUTER__",D="[data-webframez-head='true']";function F(){return typeof window>"u"?null:window[k]??null}function B(e){typeof window>"u"||(window[k]=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("="),d=i>=0?o.slice(0,i).trim():o,c=i>=0?o.slice(i+1):"";d&&(e[d]=decodeURIComponent(c))}return e}function A(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 z(){return r.default.useMemo(()=>({all:()=>v(),get:e=>v()[e],set:(e,t,n)=>{typeof document>"u"||(document.cookie=A(e,t,n))},remove:(e,t)=>{typeof document>"u"||(document.cookie=A(e,"",{...t??{},maxAge:0}))}}),[])}function G(){let e=p?r.default.useContext(p):null;if(!e){let t=F();if(t)return t;if(typeof window>"u")return W;throw new Error("useRouter must be used inside mountWebframezClient()")}return e}function x({active:e}){return(0,a.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 E(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 b(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 I(e){if(!(typeof document>"u")){document.title=e.title||"Webframez React";for(let t of document.head.querySelectorAll(D))t.remove();e.description&&E({name:"description",content:e.description}),e.favicon&&b({rel:"icon",href:e.favicon});for(let t of e.meta??[])E(t);for(let t of e.links??[])b(t)}}function Y(e){let t=new TextEncoder;return new ReadableStream({start(n){n.enqueue(t.encode(e)),n.close()}})}function q(){if(typeof window>"u")return null;let e=window.__RSC_INITIAL_PAYLOAD;return typeof e!="string"||e===""?null:(delete window.__RSC_INITIAL_PAYLOAD,(0,u.createFromReadableStream)(Y(e)))}function Z(e){return function(){let[n]=(0,r.useState)(()=>q()??(0,u.createFromFetch)(fetch(`${e}?path=${encodeURIComponent(window.location.pathname)}&search=${encodeURIComponent(window.location.search)}`,{headers:{Accept:"text/x-component"}}))),o=r.default.use(n),[i,d]=(0,r.useState)(o.model),[c,L]=(0,r.useState)(o.head),[g,w]=(0,r.useState)(!1);async function l(s,h="push"){w(!0);try{let m=await(0,u.createFromFetch)(fetch(`${e}?path=${encodeURIComponent(s.pathname)}&search=${encodeURIComponent(s.search)}`,{headers:{Accept:"text/x-component"}}));I(m.head),L(m.head),d(m.model);let y=`${s.pathname}${s.search}`;h==="replace"?history.replaceState(null,"",y):h==="push"&&history.pushState(null,"",y)}catch(C){console.error("[webframez-react] Failed to render route",C),d((0,a.jsx)("p",{children:"Failed to load route."}))}finally{w(!1)}}(0,r.useEffect)(()=>{I(c)},[c]),(0,r.useEffect)(()=>{let s=()=>{l(new URL(window.location.href),"none")};return window.addEventListener("popstate",s),()=>{window.removeEventListener("popstate",s)}},[]);let R=r.default.useMemo(()=>({push:s=>{l(new URL(s,window.location.origin),"push")},replace:s=>{l(new URL(s,window.location.origin),"replace")},refresh:()=>{l(new URL(window.location.href),"none")}}),[]);return B(R),p?(0,a.jsxs)(p.Provider,{value:R,children:[(0,a.jsx)(x,{active:g}),i??(0,a.jsx)("p",{style:{padding:24},children:"Loading..."})]}):(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(x,{active:g}),i??(0,a.jsx)("p",{style:{padding:24},children:"Loading..."})]})}}function j(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",d=Z(i);return(0,S.hydrateRoot)(n,(0,a.jsx)(d,{}))}
|
package/dist/client.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import
|
|
1
|
+
import d,{useEffect as y,useState as l}from"react";import{hydrateRoot as P}from"react-dom/client";import{createFromFetch as _,createFromReadableStream as O}from"react-server-dom-webpack/client";import{Fragment as D,jsx as s,jsxs as S}from"react/jsx-runtime";var T={push:()=>{},replace:()=>{},refresh:()=>{}},f=typeof d.createContext=="function"?d.createContext(null):null,k="__WEBFRAMEZ_ROUTER__",N="[data-webframez-head='true']";function U(){return typeof window>"u"?null:window[k]??null}function $(e){typeof window>"u"||(window[k]=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("="),a=i>=0?o.slice(0,i).trim():o,c=i>=0?o.slice(i+1):"";a&&(e[a]=decodeURIComponent(c))}return e}function A(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 G(){return d.useMemo(()=>({all:()=>v(),get:e=>v()[e],set:(e,t,n)=>{typeof document>"u"||(document.cookie=A(e,t,n))},remove:(e,t)=>{typeof document>"u"||(document.cookie=A(e,"",{...t??{},maxAge:0}))}}),[])}function Y(){let e=f?d.useContext(f):null;if(!e){let t=U();if(t)return t;if(typeof window>"u")return T;throw new Error("useRouter must be used inside mountWebframezClient()")}return e}function x({active:e}){return s("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 E(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 b(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 I(e){if(!(typeof document>"u")){document.title=e.title||"Webframez React";for(let t of document.head.querySelectorAll(N))t.remove();e.description&&E({name:"description",content:e.description}),e.favicon&&b({rel:"icon",href:e.favicon});for(let t of e.meta??[])E(t);for(let t of e.links??[])b(t)}}function M(e){let t=new TextEncoder;return new ReadableStream({start(n){n.enqueue(t.encode(e)),n.close()}})}function H(){if(typeof window>"u")return null;let e=window.__RSC_INITIAL_PAYLOAD;return typeof e!="string"||e===""?null:(delete window.__RSC_INITIAL_PAYLOAD,O(M(e)))}function W(e){return function(){let[n]=l(()=>H()??_(fetch(`${e}?path=${encodeURIComponent(window.location.pathname)}&search=${encodeURIComponent(window.location.search)}`,{headers:{Accept:"text/x-component"}}))),o=d.use(n),[i,a]=l(o.model),[c,L]=l(o.head),[m,g]=l(!1);async function u(r,R="push"){g(!0);try{let p=await _(fetch(`${e}?path=${encodeURIComponent(r.pathname)}&search=${encodeURIComponent(r.search)}`,{headers:{Accept:"text/x-component"}}));I(p.head),L(p.head),a(p.model);let C=`${r.pathname}${r.search}`;R==="replace"?history.replaceState(null,"",C):R==="push"&&history.pushState(null,"",C)}catch(h){console.error("[webframez-react] Failed to render route",h),a(s("p",{children:"Failed to load route."}))}finally{g(!1)}}y(()=>{I(c)},[c]),y(()=>{let r=()=>{u(new URL(window.location.href),"none")};return window.addEventListener("popstate",r),()=>{window.removeEventListener("popstate",r)}},[]);let w=d.useMemo(()=>({push:r=>{u(new URL(r,window.location.origin),"push")},replace:r=>{u(new URL(r,window.location.origin),"replace")},refresh:()=>{u(new URL(window.location.href),"none")}}),[]);return $(w),f?S(f.Provider,{value:w,children:[s(x,{active:m}),i??s("p",{style:{padding:24},children:"Loading..."})]}):S(D,{children:[s(x,{active:m}),i??s("p",{style:{padding:24},children:"Loading..."})]})}}function q(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",a=W(i);return P(n,s(a,{}))}export{q as mountWebframezClient,G as useCookie,Y as useRouter};
|
package/dist/http.cjs
CHANGED
|
@@ -37,6 +37,7 @@ var import_node_path2 = __toESM(require("node:path"), 1);
|
|
|
37
37
|
var import_node_child_process = require("node:child_process");
|
|
38
38
|
|
|
39
39
|
// src/server.ts
|
|
40
|
+
var import_node_stream = require("node:stream");
|
|
40
41
|
var import_server = require("react-server-dom-webpack/server");
|
|
41
42
|
function defaultOnError(err) {
|
|
42
43
|
console.error("[webframez-react] RSC render error", err);
|
|
@@ -48,10 +49,12 @@ function createHTMLShell(options = {}) {
|
|
|
48
49
|
clientScriptUrl = "/client.js",
|
|
49
50
|
headTags = "",
|
|
50
51
|
rootHtml = "",
|
|
52
|
+
initialFlightData = "",
|
|
51
53
|
basename = "",
|
|
52
54
|
liveReloadPath,
|
|
53
55
|
liveReloadServerId
|
|
54
56
|
} = options;
|
|
57
|
+
const escapedInitialFlightData = initialFlightData ? JSON.stringify(initialFlightData).replace(/</g, "\\u003c").replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029") : '""';
|
|
55
58
|
const liveReloadScript = liveReloadPath && liveReloadServerId ? `<script>
|
|
56
59
|
(() => {
|
|
57
60
|
const endpoint = ${JSON.stringify(liveReloadPath)};
|
|
@@ -96,11 +99,34 @@ function createHTMLShell(options = {}) {
|
|
|
96
99
|
<div id="root">${rootHtml}</div>
|
|
97
100
|
<script>window.__RSC_ENDPOINT = "${rscEndpoint}";</script>
|
|
98
101
|
<script>window.__RSC_BASENAME = "${basename}";</script>
|
|
102
|
+
<script>window.__RSC_INITIAL_PAYLOAD = ${escapedInitialFlightData};</script>
|
|
99
103
|
<script type="module" src="${clientScriptUrl}"></script>
|
|
100
104
|
${liveReloadScript}
|
|
101
105
|
</body>
|
|
102
106
|
</html>`;
|
|
103
107
|
}
|
|
108
|
+
function renderRSCToString(payload, options = {}) {
|
|
109
|
+
const {
|
|
110
|
+
moduleMap = {},
|
|
111
|
+
onError = defaultOnError
|
|
112
|
+
} = options;
|
|
113
|
+
return new Promise((resolve, reject) => {
|
|
114
|
+
const chunks = [];
|
|
115
|
+
const writable = new import_node_stream.Writable({
|
|
116
|
+
write(chunk, _encoding, callback) {
|
|
117
|
+
const normalized = typeof chunk === "string" ? Buffer.from(chunk) : Buffer.from(chunk);
|
|
118
|
+
chunks.push(normalized);
|
|
119
|
+
callback();
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
writable.on("finish", () => {
|
|
123
|
+
resolve(Buffer.concat(chunks).toString("utf8"));
|
|
124
|
+
});
|
|
125
|
+
writable.on("error", reject);
|
|
126
|
+
const stream = (0, import_server.renderToPipeableStream)(payload, moduleMap, { onError });
|
|
127
|
+
stream.pipe(writable);
|
|
128
|
+
});
|
|
129
|
+
}
|
|
104
130
|
function sendRSC(res, model, options = {}) {
|
|
105
131
|
const {
|
|
106
132
|
moduleMap = {},
|
|
@@ -836,6 +862,10 @@ function createNodeRequestHandler(options) {
|
|
|
836
862
|
cookies: requestCookies
|
|
837
863
|
})
|
|
838
864
|
);
|
|
865
|
+
const initialPayload = {
|
|
866
|
+
model: resolved.model,
|
|
867
|
+
head: resolved.head
|
|
868
|
+
};
|
|
839
869
|
let rootHtml = "";
|
|
840
870
|
try {
|
|
841
871
|
rootHtml = await initialHtmlWorker.render({
|
|
@@ -873,6 +903,9 @@ function createNodeRequestHandler(options) {
|
|
|
873
903
|
return;
|
|
874
904
|
}
|
|
875
905
|
}
|
|
906
|
+
const initialFlightData = await renderRSCToString(initialPayload, {
|
|
907
|
+
moduleMap
|
|
908
|
+
});
|
|
876
909
|
res.statusCode = resolved.statusCode;
|
|
877
910
|
res.setHeader("Content-Type", "text/html");
|
|
878
911
|
res.end(
|
|
@@ -882,6 +915,7 @@ function createNodeRequestHandler(options) {
|
|
|
882
915
|
clientScriptUrl,
|
|
883
916
|
rscEndpoint: rscPath,
|
|
884
917
|
rootHtml,
|
|
918
|
+
initialFlightData,
|
|
885
919
|
basename: basePath,
|
|
886
920
|
liveReloadPath: liveReloadPath || void 0,
|
|
887
921
|
liveReloadServerId: liveReloadPath ? devServerId : void 0
|
package/dist/http.js
CHANGED
|
@@ -12,6 +12,7 @@ import path2 from "node:path";
|
|
|
12
12
|
import { spawn } from "node:child_process";
|
|
13
13
|
|
|
14
14
|
// src/server.ts
|
|
15
|
+
import { Writable } from "node:stream";
|
|
15
16
|
import { renderToPipeableStream } from "react-server-dom-webpack/server";
|
|
16
17
|
function defaultOnError(err) {
|
|
17
18
|
console.error("[webframez-react] RSC render error", err);
|
|
@@ -23,10 +24,12 @@ function createHTMLShell(options = {}) {
|
|
|
23
24
|
clientScriptUrl = "/client.js",
|
|
24
25
|
headTags = "",
|
|
25
26
|
rootHtml = "",
|
|
27
|
+
initialFlightData = "",
|
|
26
28
|
basename = "",
|
|
27
29
|
liveReloadPath,
|
|
28
30
|
liveReloadServerId
|
|
29
31
|
} = options;
|
|
32
|
+
const escapedInitialFlightData = initialFlightData ? JSON.stringify(initialFlightData).replace(/</g, "\\u003c").replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029") : '""';
|
|
30
33
|
const liveReloadScript = liveReloadPath && liveReloadServerId ? `<script>
|
|
31
34
|
(() => {
|
|
32
35
|
const endpoint = ${JSON.stringify(liveReloadPath)};
|
|
@@ -71,11 +74,34 @@ function createHTMLShell(options = {}) {
|
|
|
71
74
|
<div id="root">${rootHtml}</div>
|
|
72
75
|
<script>window.__RSC_ENDPOINT = "${rscEndpoint}";</script>
|
|
73
76
|
<script>window.__RSC_BASENAME = "${basename}";</script>
|
|
77
|
+
<script>window.__RSC_INITIAL_PAYLOAD = ${escapedInitialFlightData};</script>
|
|
74
78
|
<script type="module" src="${clientScriptUrl}"></script>
|
|
75
79
|
${liveReloadScript}
|
|
76
80
|
</body>
|
|
77
81
|
</html>`;
|
|
78
82
|
}
|
|
83
|
+
function renderRSCToString(payload, options = {}) {
|
|
84
|
+
const {
|
|
85
|
+
moduleMap = {},
|
|
86
|
+
onError = defaultOnError
|
|
87
|
+
} = options;
|
|
88
|
+
return new Promise((resolve, reject) => {
|
|
89
|
+
const chunks = [];
|
|
90
|
+
const writable = new Writable({
|
|
91
|
+
write(chunk, _encoding, callback) {
|
|
92
|
+
const normalized = typeof chunk === "string" ? Buffer.from(chunk) : Buffer.from(chunk);
|
|
93
|
+
chunks.push(normalized);
|
|
94
|
+
callback();
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
writable.on("finish", () => {
|
|
98
|
+
resolve(Buffer.concat(chunks).toString("utf8"));
|
|
99
|
+
});
|
|
100
|
+
writable.on("error", reject);
|
|
101
|
+
const stream = renderToPipeableStream(payload, moduleMap, { onError });
|
|
102
|
+
stream.pipe(writable);
|
|
103
|
+
});
|
|
104
|
+
}
|
|
79
105
|
function sendRSC(res, model, options = {}) {
|
|
80
106
|
const {
|
|
81
107
|
moduleMap = {},
|
|
@@ -811,6 +837,10 @@ function createNodeRequestHandler(options) {
|
|
|
811
837
|
cookies: requestCookies
|
|
812
838
|
})
|
|
813
839
|
);
|
|
840
|
+
const initialPayload = {
|
|
841
|
+
model: resolved.model,
|
|
842
|
+
head: resolved.head
|
|
843
|
+
};
|
|
814
844
|
let rootHtml = "";
|
|
815
845
|
try {
|
|
816
846
|
rootHtml = await initialHtmlWorker.render({
|
|
@@ -848,6 +878,9 @@ function createNodeRequestHandler(options) {
|
|
|
848
878
|
return;
|
|
849
879
|
}
|
|
850
880
|
}
|
|
881
|
+
const initialFlightData = await renderRSCToString(initialPayload, {
|
|
882
|
+
moduleMap
|
|
883
|
+
});
|
|
851
884
|
res.statusCode = resolved.statusCode;
|
|
852
885
|
res.setHeader("Content-Type", "text/html");
|
|
853
886
|
res.end(
|
|
@@ -857,6 +890,7 @@ function createNodeRequestHandler(options) {
|
|
|
857
890
|
clientScriptUrl,
|
|
858
891
|
rscEndpoint: rscPath,
|
|
859
892
|
rootHtml,
|
|
893
|
+
initialFlightData,
|
|
860
894
|
basename: basePath,
|
|
861
895
|
liveReloadPath: liveReloadPath || void 0,
|
|
862
896
|
liveReloadServerId: liveReloadPath ? devServerId : void 0
|
package/dist/index.cjs
CHANGED
|
@@ -43,6 +43,7 @@ __export(src_exports, {
|
|
|
43
43
|
module.exports = __toCommonJS(src_exports);
|
|
44
44
|
|
|
45
45
|
// src/server.ts
|
|
46
|
+
var import_node_stream = require("node:stream");
|
|
46
47
|
var import_server = require("react-server-dom-webpack/server");
|
|
47
48
|
function defaultOnError(err) {
|
|
48
49
|
console.error("[webframez-react] RSC render error", err);
|
|
@@ -54,10 +55,12 @@ function createHTMLShell(options = {}) {
|
|
|
54
55
|
clientScriptUrl = "/client.js",
|
|
55
56
|
headTags = "",
|
|
56
57
|
rootHtml = "",
|
|
58
|
+
initialFlightData = "",
|
|
57
59
|
basename = "",
|
|
58
60
|
liveReloadPath,
|
|
59
61
|
liveReloadServerId
|
|
60
62
|
} = options;
|
|
63
|
+
const escapedInitialFlightData = initialFlightData ? JSON.stringify(initialFlightData).replace(/</g, "\\u003c").replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029") : '""';
|
|
61
64
|
const liveReloadScript = liveReloadPath && liveReloadServerId ? `<script>
|
|
62
65
|
(() => {
|
|
63
66
|
const endpoint = ${JSON.stringify(liveReloadPath)};
|
|
@@ -102,11 +105,34 @@ function createHTMLShell(options = {}) {
|
|
|
102
105
|
<div id="root">${rootHtml}</div>
|
|
103
106
|
<script>window.__RSC_ENDPOINT = "${rscEndpoint}";</script>
|
|
104
107
|
<script>window.__RSC_BASENAME = "${basename}";</script>
|
|
108
|
+
<script>window.__RSC_INITIAL_PAYLOAD = ${escapedInitialFlightData};</script>
|
|
105
109
|
<script type="module" src="${clientScriptUrl}"></script>
|
|
106
110
|
${liveReloadScript}
|
|
107
111
|
</body>
|
|
108
112
|
</html>`;
|
|
109
113
|
}
|
|
114
|
+
function renderRSCToString(payload, options = {}) {
|
|
115
|
+
const {
|
|
116
|
+
moduleMap = {},
|
|
117
|
+
onError = defaultOnError
|
|
118
|
+
} = options;
|
|
119
|
+
return new Promise((resolve, reject) => {
|
|
120
|
+
const chunks = [];
|
|
121
|
+
const writable = new import_node_stream.Writable({
|
|
122
|
+
write(chunk, _encoding, callback) {
|
|
123
|
+
const normalized = typeof chunk === "string" ? Buffer.from(chunk) : Buffer.from(chunk);
|
|
124
|
+
chunks.push(normalized);
|
|
125
|
+
callback();
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
writable.on("finish", () => {
|
|
129
|
+
resolve(Buffer.concat(chunks).toString("utf8"));
|
|
130
|
+
});
|
|
131
|
+
writable.on("error", reject);
|
|
132
|
+
const stream = (0, import_server.renderToPipeableStream)(payload, moduleMap, { onError });
|
|
133
|
+
stream.pipe(writable);
|
|
134
|
+
});
|
|
135
|
+
}
|
|
110
136
|
function sendRSC(res, model, options = {}) {
|
|
111
137
|
const {
|
|
112
138
|
moduleMap = {},
|
|
@@ -873,6 +899,10 @@ function createNodeRequestHandler(options) {
|
|
|
873
899
|
cookies: requestCookies
|
|
874
900
|
})
|
|
875
901
|
);
|
|
902
|
+
const initialPayload = {
|
|
903
|
+
model: resolved.model,
|
|
904
|
+
head: resolved.head
|
|
905
|
+
};
|
|
876
906
|
let rootHtml = "";
|
|
877
907
|
try {
|
|
878
908
|
rootHtml = await initialHtmlWorker.render({
|
|
@@ -910,6 +940,9 @@ function createNodeRequestHandler(options) {
|
|
|
910
940
|
return;
|
|
911
941
|
}
|
|
912
942
|
}
|
|
943
|
+
const initialFlightData = await renderRSCToString(initialPayload, {
|
|
944
|
+
moduleMap
|
|
945
|
+
});
|
|
913
946
|
res.statusCode = resolved.statusCode;
|
|
914
947
|
res.setHeader("Content-Type", "text/html");
|
|
915
948
|
res.end(
|
|
@@ -919,6 +952,7 @@ function createNodeRequestHandler(options) {
|
|
|
919
952
|
clientScriptUrl,
|
|
920
953
|
rscEndpoint: rscPath,
|
|
921
954
|
rootHtml,
|
|
955
|
+
initialFlightData,
|
|
922
956
|
basename: basePath,
|
|
923
957
|
liveReloadPath: liveReloadPath || void 0,
|
|
924
958
|
liveReloadServerId: liveReloadPath ? devServerId : void 0
|
package/dist/index.js
CHANGED
|
@@ -7,6 +7,7 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
7
7
|
});
|
|
8
8
|
|
|
9
9
|
// src/server.ts
|
|
10
|
+
import { Writable } from "node:stream";
|
|
10
11
|
import { renderToPipeableStream } from "react-server-dom-webpack/server";
|
|
11
12
|
function defaultOnError(err) {
|
|
12
13
|
console.error("[webframez-react] RSC render error", err);
|
|
@@ -18,10 +19,12 @@ function createHTMLShell(options = {}) {
|
|
|
18
19
|
clientScriptUrl = "/client.js",
|
|
19
20
|
headTags = "",
|
|
20
21
|
rootHtml = "",
|
|
22
|
+
initialFlightData = "",
|
|
21
23
|
basename = "",
|
|
22
24
|
liveReloadPath,
|
|
23
25
|
liveReloadServerId
|
|
24
26
|
} = options;
|
|
27
|
+
const escapedInitialFlightData = initialFlightData ? JSON.stringify(initialFlightData).replace(/</g, "\\u003c").replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029") : '""';
|
|
25
28
|
const liveReloadScript = liveReloadPath && liveReloadServerId ? `<script>
|
|
26
29
|
(() => {
|
|
27
30
|
const endpoint = ${JSON.stringify(liveReloadPath)};
|
|
@@ -66,11 +69,34 @@ function createHTMLShell(options = {}) {
|
|
|
66
69
|
<div id="root">${rootHtml}</div>
|
|
67
70
|
<script>window.__RSC_ENDPOINT = "${rscEndpoint}";</script>
|
|
68
71
|
<script>window.__RSC_BASENAME = "${basename}";</script>
|
|
72
|
+
<script>window.__RSC_INITIAL_PAYLOAD = ${escapedInitialFlightData};</script>
|
|
69
73
|
<script type="module" src="${clientScriptUrl}"></script>
|
|
70
74
|
${liveReloadScript}
|
|
71
75
|
</body>
|
|
72
76
|
</html>`;
|
|
73
77
|
}
|
|
78
|
+
function renderRSCToString(payload, options = {}) {
|
|
79
|
+
const {
|
|
80
|
+
moduleMap = {},
|
|
81
|
+
onError = defaultOnError
|
|
82
|
+
} = options;
|
|
83
|
+
return new Promise((resolve, reject) => {
|
|
84
|
+
const chunks = [];
|
|
85
|
+
const writable = new Writable({
|
|
86
|
+
write(chunk, _encoding, callback) {
|
|
87
|
+
const normalized = typeof chunk === "string" ? Buffer.from(chunk) : Buffer.from(chunk);
|
|
88
|
+
chunks.push(normalized);
|
|
89
|
+
callback();
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
writable.on("finish", () => {
|
|
93
|
+
resolve(Buffer.concat(chunks).toString("utf8"));
|
|
94
|
+
});
|
|
95
|
+
writable.on("error", reject);
|
|
96
|
+
const stream = renderToPipeableStream(payload, moduleMap, { onError });
|
|
97
|
+
stream.pipe(writable);
|
|
98
|
+
});
|
|
99
|
+
}
|
|
74
100
|
function sendRSC(res, model, options = {}) {
|
|
75
101
|
const {
|
|
76
102
|
moduleMap = {},
|
|
@@ -837,6 +863,10 @@ function createNodeRequestHandler(options) {
|
|
|
837
863
|
cookies: requestCookies
|
|
838
864
|
})
|
|
839
865
|
);
|
|
866
|
+
const initialPayload = {
|
|
867
|
+
model: resolved.model,
|
|
868
|
+
head: resolved.head
|
|
869
|
+
};
|
|
840
870
|
let rootHtml = "";
|
|
841
871
|
try {
|
|
842
872
|
rootHtml = await initialHtmlWorker.render({
|
|
@@ -874,6 +904,9 @@ function createNodeRequestHandler(options) {
|
|
|
874
904
|
return;
|
|
875
905
|
}
|
|
876
906
|
}
|
|
907
|
+
const initialFlightData = await renderRSCToString(initialPayload, {
|
|
908
|
+
moduleMap
|
|
909
|
+
});
|
|
877
910
|
res.statusCode = resolved.statusCode;
|
|
878
911
|
res.setHeader("Content-Type", "text/html");
|
|
879
912
|
res.end(
|
|
@@ -883,6 +916,7 @@ function createNodeRequestHandler(options) {
|
|
|
883
916
|
clientScriptUrl,
|
|
884
917
|
rscEndpoint: rscPath,
|
|
885
918
|
rootHtml,
|
|
919
|
+
initialFlightData,
|
|
886
920
|
basename: basePath,
|
|
887
921
|
liveReloadPath: liveReloadPath || void 0,
|
|
888
922
|
liveReloadServerId: liveReloadPath ? devServerId : void 0
|
package/dist/webframez-core.cjs
CHANGED
|
@@ -40,6 +40,7 @@ var import_node_path2 = __toESM(require("node:path"), 1);
|
|
|
40
40
|
var import_node_child_process = require("node:child_process");
|
|
41
41
|
|
|
42
42
|
// src/server.ts
|
|
43
|
+
var import_node_stream = require("node:stream");
|
|
43
44
|
var import_server = require("react-server-dom-webpack/server");
|
|
44
45
|
function defaultOnError(err) {
|
|
45
46
|
console.error("[webframez-react] RSC render error", err);
|
|
@@ -51,10 +52,12 @@ function createHTMLShell(options = {}) {
|
|
|
51
52
|
clientScriptUrl = "/client.js",
|
|
52
53
|
headTags = "",
|
|
53
54
|
rootHtml = "",
|
|
55
|
+
initialFlightData = "",
|
|
54
56
|
basename = "",
|
|
55
57
|
liveReloadPath,
|
|
56
58
|
liveReloadServerId
|
|
57
59
|
} = options;
|
|
60
|
+
const escapedInitialFlightData = initialFlightData ? JSON.stringify(initialFlightData).replace(/</g, "\\u003c").replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029") : '""';
|
|
58
61
|
const liveReloadScript = liveReloadPath && liveReloadServerId ? `<script>
|
|
59
62
|
(() => {
|
|
60
63
|
const endpoint = ${JSON.stringify(liveReloadPath)};
|
|
@@ -99,11 +102,34 @@ function createHTMLShell(options = {}) {
|
|
|
99
102
|
<div id="root">${rootHtml}</div>
|
|
100
103
|
<script>window.__RSC_ENDPOINT = "${rscEndpoint}";</script>
|
|
101
104
|
<script>window.__RSC_BASENAME = "${basename}";</script>
|
|
105
|
+
<script>window.__RSC_INITIAL_PAYLOAD = ${escapedInitialFlightData};</script>
|
|
102
106
|
<script type="module" src="${clientScriptUrl}"></script>
|
|
103
107
|
${liveReloadScript}
|
|
104
108
|
</body>
|
|
105
109
|
</html>`;
|
|
106
110
|
}
|
|
111
|
+
function renderRSCToString(payload, options = {}) {
|
|
112
|
+
const {
|
|
113
|
+
moduleMap = {},
|
|
114
|
+
onError = defaultOnError
|
|
115
|
+
} = options;
|
|
116
|
+
return new Promise((resolve, reject) => {
|
|
117
|
+
const chunks = [];
|
|
118
|
+
const writable = new import_node_stream.Writable({
|
|
119
|
+
write(chunk, _encoding, callback) {
|
|
120
|
+
const normalized = typeof chunk === "string" ? Buffer.from(chunk) : Buffer.from(chunk);
|
|
121
|
+
chunks.push(normalized);
|
|
122
|
+
callback();
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
writable.on("finish", () => {
|
|
126
|
+
resolve(Buffer.concat(chunks).toString("utf8"));
|
|
127
|
+
});
|
|
128
|
+
writable.on("error", reject);
|
|
129
|
+
const stream = (0, import_server.renderToPipeableStream)(payload, moduleMap, { onError });
|
|
130
|
+
stream.pipe(writable);
|
|
131
|
+
});
|
|
132
|
+
}
|
|
107
133
|
function sendRSC(res, model, options = {}) {
|
|
108
134
|
const {
|
|
109
135
|
moduleMap = {},
|
|
@@ -839,6 +865,10 @@ function createNodeRequestHandler(options) {
|
|
|
839
865
|
cookies: requestCookies
|
|
840
866
|
})
|
|
841
867
|
);
|
|
868
|
+
const initialPayload = {
|
|
869
|
+
model: resolved.model,
|
|
870
|
+
head: resolved.head
|
|
871
|
+
};
|
|
842
872
|
let rootHtml = "";
|
|
843
873
|
try {
|
|
844
874
|
rootHtml = await initialHtmlWorker.render({
|
|
@@ -876,6 +906,9 @@ function createNodeRequestHandler(options) {
|
|
|
876
906
|
return;
|
|
877
907
|
}
|
|
878
908
|
}
|
|
909
|
+
const initialFlightData = await renderRSCToString(initialPayload, {
|
|
910
|
+
moduleMap
|
|
911
|
+
});
|
|
879
912
|
res.statusCode = resolved.statusCode;
|
|
880
913
|
res.setHeader("Content-Type", "text/html");
|
|
881
914
|
res.end(
|
|
@@ -885,6 +918,7 @@ function createNodeRequestHandler(options) {
|
|
|
885
918
|
clientScriptUrl,
|
|
886
919
|
rscEndpoint: rscPath,
|
|
887
920
|
rootHtml,
|
|
921
|
+
initialFlightData,
|
|
888
922
|
basename: basePath,
|
|
889
923
|
liveReloadPath: liveReloadPath || void 0,
|
|
890
924
|
liveReloadServerId: liveReloadPath ? devServerId : void 0
|
package/dist/webframez-core.js
CHANGED
|
@@ -12,6 +12,7 @@ import path2 from "node:path";
|
|
|
12
12
|
import { spawn } from "node:child_process";
|
|
13
13
|
|
|
14
14
|
// src/server.ts
|
|
15
|
+
import { Writable } from "node:stream";
|
|
15
16
|
import { renderToPipeableStream } from "react-server-dom-webpack/server";
|
|
16
17
|
function defaultOnError(err) {
|
|
17
18
|
console.error("[webframez-react] RSC render error", err);
|
|
@@ -23,10 +24,12 @@ function createHTMLShell(options = {}) {
|
|
|
23
24
|
clientScriptUrl = "/client.js",
|
|
24
25
|
headTags = "",
|
|
25
26
|
rootHtml = "",
|
|
27
|
+
initialFlightData = "",
|
|
26
28
|
basename = "",
|
|
27
29
|
liveReloadPath,
|
|
28
30
|
liveReloadServerId
|
|
29
31
|
} = options;
|
|
32
|
+
const escapedInitialFlightData = initialFlightData ? JSON.stringify(initialFlightData).replace(/</g, "\\u003c").replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029") : '""';
|
|
30
33
|
const liveReloadScript = liveReloadPath && liveReloadServerId ? `<script>
|
|
31
34
|
(() => {
|
|
32
35
|
const endpoint = ${JSON.stringify(liveReloadPath)};
|
|
@@ -71,11 +74,34 @@ function createHTMLShell(options = {}) {
|
|
|
71
74
|
<div id="root">${rootHtml}</div>
|
|
72
75
|
<script>window.__RSC_ENDPOINT = "${rscEndpoint}";</script>
|
|
73
76
|
<script>window.__RSC_BASENAME = "${basename}";</script>
|
|
77
|
+
<script>window.__RSC_INITIAL_PAYLOAD = ${escapedInitialFlightData};</script>
|
|
74
78
|
<script type="module" src="${clientScriptUrl}"></script>
|
|
75
79
|
${liveReloadScript}
|
|
76
80
|
</body>
|
|
77
81
|
</html>`;
|
|
78
82
|
}
|
|
83
|
+
function renderRSCToString(payload, options = {}) {
|
|
84
|
+
const {
|
|
85
|
+
moduleMap = {},
|
|
86
|
+
onError = defaultOnError
|
|
87
|
+
} = options;
|
|
88
|
+
return new Promise((resolve, reject) => {
|
|
89
|
+
const chunks = [];
|
|
90
|
+
const writable = new Writable({
|
|
91
|
+
write(chunk, _encoding, callback) {
|
|
92
|
+
const normalized = typeof chunk === "string" ? Buffer.from(chunk) : Buffer.from(chunk);
|
|
93
|
+
chunks.push(normalized);
|
|
94
|
+
callback();
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
writable.on("finish", () => {
|
|
98
|
+
resolve(Buffer.concat(chunks).toString("utf8"));
|
|
99
|
+
});
|
|
100
|
+
writable.on("error", reject);
|
|
101
|
+
const stream = renderToPipeableStream(payload, moduleMap, { onError });
|
|
102
|
+
stream.pipe(writable);
|
|
103
|
+
});
|
|
104
|
+
}
|
|
79
105
|
function sendRSC(res, model, options = {}) {
|
|
80
106
|
const {
|
|
81
107
|
moduleMap = {},
|
|
@@ -811,6 +837,10 @@ function createNodeRequestHandler(options) {
|
|
|
811
837
|
cookies: requestCookies
|
|
812
838
|
})
|
|
813
839
|
);
|
|
840
|
+
const initialPayload = {
|
|
841
|
+
model: resolved.model,
|
|
842
|
+
head: resolved.head
|
|
843
|
+
};
|
|
814
844
|
let rootHtml = "";
|
|
815
845
|
try {
|
|
816
846
|
rootHtml = await initialHtmlWorker.render({
|
|
@@ -848,6 +878,9 @@ function createNodeRequestHandler(options) {
|
|
|
848
878
|
return;
|
|
849
879
|
}
|
|
850
880
|
}
|
|
881
|
+
const initialFlightData = await renderRSCToString(initialPayload, {
|
|
882
|
+
moduleMap
|
|
883
|
+
});
|
|
851
884
|
res.statusCode = resolved.statusCode;
|
|
852
885
|
res.setHeader("Content-Type", "text/html");
|
|
853
886
|
res.end(
|
|
@@ -857,6 +890,7 @@ function createNodeRequestHandler(options) {
|
|
|
857
890
|
clientScriptUrl,
|
|
858
891
|
rscEndpoint: rscPath,
|
|
859
892
|
rootHtml,
|
|
893
|
+
initialFlightData,
|
|
860
894
|
basename: basePath,
|
|
861
895
|
liveReloadPath: liveReloadPath || void 0,
|
|
862
896
|
liveReloadServerId: liveReloadPath ? devServerId : void 0
|