@webtypen/webframez-react 0.0.17 → 0.0.18

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/http.cjs CHANGED
@@ -636,11 +636,6 @@ const Module = require("node:module");
636
636
  const { Writable } = require("node:stream");
637
637
  const { createFromReadableStream } = require("react-server-dom-webpack/client.node");
638
638
 
639
- const pagesDir = process.env.WEBFRAMEZ_REACT_PAGES_DIR || "";
640
- if (!pagesDir) {
641
- throw new Error("Missing WEBFRAMEZ_REACT_PAGES_DIR");
642
- }
643
-
644
639
  const originalResolveFilename = Module._resolveFilename;
645
640
  const rootParent = {
646
641
  id: "__webframez_react_worker__",
@@ -678,12 +673,10 @@ Module._resolveFilename = function(request, parent, isMain, options) {
678
673
  return originalResolveFilename.call(this, request, parent, isMain, options);
679
674
  };
680
675
 
681
- const { createFileRouter } = require("@webtypen/webframez-react/router");
682
676
  const reactDomPkg = require.resolve("react-dom/package.json", {
683
- paths: [process.cwd(), pagesDir]
677
+ paths: [process.cwd()]
684
678
  });
685
679
  const reactDomServer = require(path.join(path.dirname(reactDomPkg), "server.node.js"));
686
- const router = createFileRouter({ pagesDir });
687
680
 
688
681
  function renderHtml(model) {
689
682
  return new Promise((resolve, reject) => {
@@ -744,33 +737,15 @@ async function renderHtmlFromFlightData(flightData, moduleMap) {
744
737
  }
745
738
 
746
739
  process.on("message", async (message) => {
747
- if (!message || (message.type !== "render-route" && message.type !== "render-flight")) {
740
+ if (!message || message.type !== "render-flight") {
748
741
  return;
749
742
  }
750
743
 
751
744
  try {
752
- let html = "";
753
-
754
- if (message.type === "render-route") {
755
- const previousBasename = globalThis.__RSC_BASENAME;
756
- globalThis.__RSC_BASENAME = message.payload.basename || "";
757
-
758
- try {
759
- const resolved = await router.resolve({
760
- pathname: message.payload.pathname,
761
- searchParams: message.payload.searchParams || {},
762
- cookies: message.payload.cookies || {},
763
- });
764
- html = await renderHtml(resolved.model);
765
- } finally {
766
- globalThis.__RSC_BASENAME = previousBasename;
767
- }
768
- } else {
769
- html = await renderHtmlFromFlightData(
770
- message.payload.flightData || "",
771
- message.payload.moduleMap || {},
772
- );
773
- }
745
+ const html = await renderHtmlFromFlightData(
746
+ message.payload.flightData || "",
747
+ message.payload.moduleMap || {},
748
+ );
774
749
 
775
750
  if (typeof process.send === "function") {
776
751
  process.send({ id: message.id, ok: true, html });
@@ -810,7 +785,7 @@ function sanitizeInitialHtmlWorkerNodeOptions(rawNodeOptions) {
810
785
  }
811
786
  return rawNodeOptions.replace(/(^|\s)--conditions\s+react-server(?=\s|$)/g, " ").replace(/(^|\s)-r\s+(\S*webframez-react\/register)(?=\s|$)/g, " ").replace(/\s+/g, " ").trim();
812
787
  }
813
- function createInitialHtmlWorker(pagesDir) {
788
+ function createInitialHtmlWorker(_pagesDir) {
814
789
  let child = null;
815
790
  let nextRequestId = 1;
816
791
  let stderrBuffer = "";
@@ -841,8 +816,7 @@ function createInitialHtmlWorker(pagesDir) {
841
816
  cwd: process.cwd(),
842
817
  env: {
843
818
  ...process.env,
844
- NODE_OPTIONS: sanitizeInitialHtmlWorkerNodeOptions(process.env.NODE_OPTIONS),
845
- WEBFRAMEZ_REACT_PAGES_DIR: pagesDir
819
+ NODE_OPTIONS: sanitizeInitialHtmlWorkerNodeOptions(process.env.NODE_OPTIONS)
846
820
  },
847
821
  stdio: ["ignore", "ignore", "pipe", "ipc"]
848
822
  });
@@ -882,34 +856,6 @@ ${stderrBuffer.trim()}` : "";
882
856
  return child;
883
857
  };
884
858
  return {
885
- render(payload) {
886
- const activeChild = startWorker();
887
- const requestId = nextRequestId++;
888
- return new Promise((resolve, reject) => {
889
- const timeout = setTimeout(() => {
890
- rejectPending(new Error("[webframez-react] Initial HTML worker timed out"));
891
- stopWorker();
892
- }, 1e4);
893
- pending.set(requestId, { resolve, reject, timeout });
894
- const request = {
895
- id: requestId,
896
- type: "render-route",
897
- payload
898
- };
899
- activeChild.send(request, (error) => {
900
- if (!error) {
901
- return;
902
- }
903
- const entry = pending.get(requestId);
904
- if (!entry) {
905
- return;
906
- }
907
- pending.delete(requestId);
908
- clearTimeout(entry.timeout);
909
- entry.reject(error instanceof Error ? error : new Error(String(error)));
910
- });
911
- });
912
- },
913
859
  renderFromFlightData(payload) {
914
860
  const activeChild = startWorker();
915
861
  const requestId = nextRequestId++;
@@ -1153,21 +1099,17 @@ function createNodeRequestHandler(options) {
1153
1099
  });
1154
1100
  let rootHtml = "";
1155
1101
  try {
1156
- rootHtml = await initialHtmlWorker.render({
1157
- pathname: stripBasePath(url.pathname, basePath),
1158
- searchParams: parseSearchParams(url.searchParams),
1159
- cookies: requestCookies,
1160
- basename: basePath
1102
+ rootHtml = await initialHtmlWorker.renderFromFlightData({
1103
+ flightData: initialFlightData,
1104
+ moduleMap
1161
1105
  });
1162
1106
  } catch (error) {
1163
1107
  console.error("[webframez-react] Failed to render initial HTML", error);
1164
1108
  try {
1165
1109
  initialHtmlWorker.dispose();
1166
- rootHtml = await initialHtmlWorker.render({
1167
- pathname: stripBasePath(url.pathname, basePath),
1168
- searchParams: parseSearchParams(url.searchParams),
1169
- cookies: requestCookies,
1170
- basename: basePath
1110
+ rootHtml = await initialHtmlWorker.renderFromFlightData({
1111
+ flightData: initialFlightData,
1112
+ moduleMap
1171
1113
  });
1172
1114
  } catch (retryError) {
1173
1115
  console.error("[webframez-react] Retry for initial HTML failed", retryError);
package/dist/http.js CHANGED
@@ -611,11 +611,6 @@ const Module = require("node:module");
611
611
  const { Writable } = require("node:stream");
612
612
  const { createFromReadableStream } = require("react-server-dom-webpack/client.node");
613
613
 
614
- const pagesDir = process.env.WEBFRAMEZ_REACT_PAGES_DIR || "";
615
- if (!pagesDir) {
616
- throw new Error("Missing WEBFRAMEZ_REACT_PAGES_DIR");
617
- }
618
-
619
614
  const originalResolveFilename = Module._resolveFilename;
620
615
  const rootParent = {
621
616
  id: "__webframez_react_worker__",
@@ -653,12 +648,10 @@ Module._resolveFilename = function(request, parent, isMain, options) {
653
648
  return originalResolveFilename.call(this, request, parent, isMain, options);
654
649
  };
655
650
 
656
- const { createFileRouter } = require("@webtypen/webframez-react/router");
657
651
  const reactDomPkg = require.resolve("react-dom/package.json", {
658
- paths: [process.cwd(), pagesDir]
652
+ paths: [process.cwd()]
659
653
  });
660
654
  const reactDomServer = require(path.join(path.dirname(reactDomPkg), "server.node.js"));
661
- const router = createFileRouter({ pagesDir });
662
655
 
663
656
  function renderHtml(model) {
664
657
  return new Promise((resolve, reject) => {
@@ -719,33 +712,15 @@ async function renderHtmlFromFlightData(flightData, moduleMap) {
719
712
  }
720
713
 
721
714
  process.on("message", async (message) => {
722
- if (!message || (message.type !== "render-route" && message.type !== "render-flight")) {
715
+ if (!message || message.type !== "render-flight") {
723
716
  return;
724
717
  }
725
718
 
726
719
  try {
727
- let html = "";
728
-
729
- if (message.type === "render-route") {
730
- const previousBasename = globalThis.__RSC_BASENAME;
731
- globalThis.__RSC_BASENAME = message.payload.basename || "";
732
-
733
- try {
734
- const resolved = await router.resolve({
735
- pathname: message.payload.pathname,
736
- searchParams: message.payload.searchParams || {},
737
- cookies: message.payload.cookies || {},
738
- });
739
- html = await renderHtml(resolved.model);
740
- } finally {
741
- globalThis.__RSC_BASENAME = previousBasename;
742
- }
743
- } else {
744
- html = await renderHtmlFromFlightData(
745
- message.payload.flightData || "",
746
- message.payload.moduleMap || {},
747
- );
748
- }
720
+ const html = await renderHtmlFromFlightData(
721
+ message.payload.flightData || "",
722
+ message.payload.moduleMap || {},
723
+ );
749
724
 
750
725
  if (typeof process.send === "function") {
751
726
  process.send({ id: message.id, ok: true, html });
@@ -785,7 +760,7 @@ function sanitizeInitialHtmlWorkerNodeOptions(rawNodeOptions) {
785
760
  }
786
761
  return rawNodeOptions.replace(/(^|\s)--conditions\s+react-server(?=\s|$)/g, " ").replace(/(^|\s)-r\s+(\S*webframez-react\/register)(?=\s|$)/g, " ").replace(/\s+/g, " ").trim();
787
762
  }
788
- function createInitialHtmlWorker(pagesDir) {
763
+ function createInitialHtmlWorker(_pagesDir) {
789
764
  let child = null;
790
765
  let nextRequestId = 1;
791
766
  let stderrBuffer = "";
@@ -816,8 +791,7 @@ function createInitialHtmlWorker(pagesDir) {
816
791
  cwd: process.cwd(),
817
792
  env: {
818
793
  ...process.env,
819
- NODE_OPTIONS: sanitizeInitialHtmlWorkerNodeOptions(process.env.NODE_OPTIONS),
820
- WEBFRAMEZ_REACT_PAGES_DIR: pagesDir
794
+ NODE_OPTIONS: sanitizeInitialHtmlWorkerNodeOptions(process.env.NODE_OPTIONS)
821
795
  },
822
796
  stdio: ["ignore", "ignore", "pipe", "ipc"]
823
797
  });
@@ -857,34 +831,6 @@ ${stderrBuffer.trim()}` : "";
857
831
  return child;
858
832
  };
859
833
  return {
860
- render(payload) {
861
- const activeChild = startWorker();
862
- const requestId = nextRequestId++;
863
- return new Promise((resolve, reject) => {
864
- const timeout = setTimeout(() => {
865
- rejectPending(new Error("[webframez-react] Initial HTML worker timed out"));
866
- stopWorker();
867
- }, 1e4);
868
- pending.set(requestId, { resolve, reject, timeout });
869
- const request = {
870
- id: requestId,
871
- type: "render-route",
872
- payload
873
- };
874
- activeChild.send(request, (error) => {
875
- if (!error) {
876
- return;
877
- }
878
- const entry = pending.get(requestId);
879
- if (!entry) {
880
- return;
881
- }
882
- pending.delete(requestId);
883
- clearTimeout(entry.timeout);
884
- entry.reject(error instanceof Error ? error : new Error(String(error)));
885
- });
886
- });
887
- },
888
834
  renderFromFlightData(payload) {
889
835
  const activeChild = startWorker();
890
836
  const requestId = nextRequestId++;
@@ -1128,21 +1074,17 @@ function createNodeRequestHandler(options) {
1128
1074
  });
1129
1075
  let rootHtml = "";
1130
1076
  try {
1131
- rootHtml = await initialHtmlWorker.render({
1132
- pathname: stripBasePath(url.pathname, basePath),
1133
- searchParams: parseSearchParams(url.searchParams),
1134
- cookies: requestCookies,
1135
- basename: basePath
1077
+ rootHtml = await initialHtmlWorker.renderFromFlightData({
1078
+ flightData: initialFlightData,
1079
+ moduleMap
1136
1080
  });
1137
1081
  } catch (error) {
1138
1082
  console.error("[webframez-react] Failed to render initial HTML", error);
1139
1083
  try {
1140
1084
  initialHtmlWorker.dispose();
1141
- rootHtml = await initialHtmlWorker.render({
1142
- pathname: stripBasePath(url.pathname, basePath),
1143
- searchParams: parseSearchParams(url.searchParams),
1144
- cookies: requestCookies,
1145
- basename: basePath
1085
+ rootHtml = await initialHtmlWorker.renderFromFlightData({
1086
+ flightData: initialFlightData,
1087
+ moduleMap
1146
1088
  });
1147
1089
  } catch (retryError) {
1148
1090
  console.error("[webframez-react] Retry for initial HTML failed", retryError);
package/dist/index.cjs CHANGED
@@ -673,11 +673,6 @@ const Module = require("node:module");
673
673
  const { Writable } = require("node:stream");
674
674
  const { createFromReadableStream } = require("react-server-dom-webpack/client.node");
675
675
 
676
- const pagesDir = process.env.WEBFRAMEZ_REACT_PAGES_DIR || "";
677
- if (!pagesDir) {
678
- throw new Error("Missing WEBFRAMEZ_REACT_PAGES_DIR");
679
- }
680
-
681
676
  const originalResolveFilename = Module._resolveFilename;
682
677
  const rootParent = {
683
678
  id: "__webframez_react_worker__",
@@ -715,12 +710,10 @@ Module._resolveFilename = function(request, parent, isMain, options) {
715
710
  return originalResolveFilename.call(this, request, parent, isMain, options);
716
711
  };
717
712
 
718
- const { createFileRouter } = require("@webtypen/webframez-react/router");
719
713
  const reactDomPkg = require.resolve("react-dom/package.json", {
720
- paths: [process.cwd(), pagesDir]
714
+ paths: [process.cwd()]
721
715
  });
722
716
  const reactDomServer = require(path.join(path.dirname(reactDomPkg), "server.node.js"));
723
- const router = createFileRouter({ pagesDir });
724
717
 
725
718
  function renderHtml(model) {
726
719
  return new Promise((resolve, reject) => {
@@ -781,33 +774,15 @@ async function renderHtmlFromFlightData(flightData, moduleMap) {
781
774
  }
782
775
 
783
776
  process.on("message", async (message) => {
784
- if (!message || (message.type !== "render-route" && message.type !== "render-flight")) {
777
+ if (!message || message.type !== "render-flight") {
785
778
  return;
786
779
  }
787
780
 
788
781
  try {
789
- let html = "";
790
-
791
- if (message.type === "render-route") {
792
- const previousBasename = globalThis.__RSC_BASENAME;
793
- globalThis.__RSC_BASENAME = message.payload.basename || "";
794
-
795
- try {
796
- const resolved = await router.resolve({
797
- pathname: message.payload.pathname,
798
- searchParams: message.payload.searchParams || {},
799
- cookies: message.payload.cookies || {},
800
- });
801
- html = await renderHtml(resolved.model);
802
- } finally {
803
- globalThis.__RSC_BASENAME = previousBasename;
804
- }
805
- } else {
806
- html = await renderHtmlFromFlightData(
807
- message.payload.flightData || "",
808
- message.payload.moduleMap || {},
809
- );
810
- }
782
+ const html = await renderHtmlFromFlightData(
783
+ message.payload.flightData || "",
784
+ message.payload.moduleMap || {},
785
+ );
811
786
 
812
787
  if (typeof process.send === "function") {
813
788
  process.send({ id: message.id, ok: true, html });
@@ -847,7 +822,7 @@ function sanitizeInitialHtmlWorkerNodeOptions(rawNodeOptions) {
847
822
  }
848
823
  return rawNodeOptions.replace(/(^|\s)--conditions\s+react-server(?=\s|$)/g, " ").replace(/(^|\s)-r\s+(\S*webframez-react\/register)(?=\s|$)/g, " ").replace(/\s+/g, " ").trim();
849
824
  }
850
- function createInitialHtmlWorker(pagesDir) {
825
+ function createInitialHtmlWorker(_pagesDir) {
851
826
  let child = null;
852
827
  let nextRequestId = 1;
853
828
  let stderrBuffer = "";
@@ -878,8 +853,7 @@ function createInitialHtmlWorker(pagesDir) {
878
853
  cwd: process.cwd(),
879
854
  env: {
880
855
  ...process.env,
881
- NODE_OPTIONS: sanitizeInitialHtmlWorkerNodeOptions(process.env.NODE_OPTIONS),
882
- WEBFRAMEZ_REACT_PAGES_DIR: pagesDir
856
+ NODE_OPTIONS: sanitizeInitialHtmlWorkerNodeOptions(process.env.NODE_OPTIONS)
883
857
  },
884
858
  stdio: ["ignore", "ignore", "pipe", "ipc"]
885
859
  });
@@ -919,34 +893,6 @@ ${stderrBuffer.trim()}` : "";
919
893
  return child;
920
894
  };
921
895
  return {
922
- render(payload) {
923
- const activeChild = startWorker();
924
- const requestId = nextRequestId++;
925
- return new Promise((resolve, reject) => {
926
- const timeout = setTimeout(() => {
927
- rejectPending(new Error("[webframez-react] Initial HTML worker timed out"));
928
- stopWorker();
929
- }, 1e4);
930
- pending.set(requestId, { resolve, reject, timeout });
931
- const request = {
932
- id: requestId,
933
- type: "render-route",
934
- payload
935
- };
936
- activeChild.send(request, (error) => {
937
- if (!error) {
938
- return;
939
- }
940
- const entry = pending.get(requestId);
941
- if (!entry) {
942
- return;
943
- }
944
- pending.delete(requestId);
945
- clearTimeout(entry.timeout);
946
- entry.reject(error instanceof Error ? error : new Error(String(error)));
947
- });
948
- });
949
- },
950
896
  renderFromFlightData(payload) {
951
897
  const activeChild = startWorker();
952
898
  const requestId = nextRequestId++;
@@ -1190,21 +1136,17 @@ function createNodeRequestHandler(options) {
1190
1136
  });
1191
1137
  let rootHtml = "";
1192
1138
  try {
1193
- rootHtml = await initialHtmlWorker.render({
1194
- pathname: stripBasePath(url.pathname, basePath),
1195
- searchParams: parseSearchParams(url.searchParams),
1196
- cookies: requestCookies,
1197
- basename: basePath
1139
+ rootHtml = await initialHtmlWorker.renderFromFlightData({
1140
+ flightData: initialFlightData,
1141
+ moduleMap
1198
1142
  });
1199
1143
  } catch (error) {
1200
1144
  console.error("[webframez-react] Failed to render initial HTML", error);
1201
1145
  try {
1202
1146
  initialHtmlWorker.dispose();
1203
- rootHtml = await initialHtmlWorker.render({
1204
- pathname: stripBasePath(url.pathname, basePath),
1205
- searchParams: parseSearchParams(url.searchParams),
1206
- cookies: requestCookies,
1207
- basename: basePath
1147
+ rootHtml = await initialHtmlWorker.renderFromFlightData({
1148
+ flightData: initialFlightData,
1149
+ moduleMap
1208
1150
  });
1209
1151
  } catch (retryError) {
1210
1152
  console.error("[webframez-react] Retry for initial HTML failed", retryError);
package/dist/index.js CHANGED
@@ -637,11 +637,6 @@ const Module = require("node:module");
637
637
  const { Writable } = require("node:stream");
638
638
  const { createFromReadableStream } = require("react-server-dom-webpack/client.node");
639
639
 
640
- const pagesDir = process.env.WEBFRAMEZ_REACT_PAGES_DIR || "";
641
- if (!pagesDir) {
642
- throw new Error("Missing WEBFRAMEZ_REACT_PAGES_DIR");
643
- }
644
-
645
640
  const originalResolveFilename = Module._resolveFilename;
646
641
  const rootParent = {
647
642
  id: "__webframez_react_worker__",
@@ -679,12 +674,10 @@ Module._resolveFilename = function(request, parent, isMain, options) {
679
674
  return originalResolveFilename.call(this, request, parent, isMain, options);
680
675
  };
681
676
 
682
- const { createFileRouter } = require("@webtypen/webframez-react/router");
683
677
  const reactDomPkg = require.resolve("react-dom/package.json", {
684
- paths: [process.cwd(), pagesDir]
678
+ paths: [process.cwd()]
685
679
  });
686
680
  const reactDomServer = require(path.join(path.dirname(reactDomPkg), "server.node.js"));
687
- const router = createFileRouter({ pagesDir });
688
681
 
689
682
  function renderHtml(model) {
690
683
  return new Promise((resolve, reject) => {
@@ -745,33 +738,15 @@ async function renderHtmlFromFlightData(flightData, moduleMap) {
745
738
  }
746
739
 
747
740
  process.on("message", async (message) => {
748
- if (!message || (message.type !== "render-route" && message.type !== "render-flight")) {
741
+ if (!message || message.type !== "render-flight") {
749
742
  return;
750
743
  }
751
744
 
752
745
  try {
753
- let html = "";
754
-
755
- if (message.type === "render-route") {
756
- const previousBasename = globalThis.__RSC_BASENAME;
757
- globalThis.__RSC_BASENAME = message.payload.basename || "";
758
-
759
- try {
760
- const resolved = await router.resolve({
761
- pathname: message.payload.pathname,
762
- searchParams: message.payload.searchParams || {},
763
- cookies: message.payload.cookies || {},
764
- });
765
- html = await renderHtml(resolved.model);
766
- } finally {
767
- globalThis.__RSC_BASENAME = previousBasename;
768
- }
769
- } else {
770
- html = await renderHtmlFromFlightData(
771
- message.payload.flightData || "",
772
- message.payload.moduleMap || {},
773
- );
774
- }
746
+ const html = await renderHtmlFromFlightData(
747
+ message.payload.flightData || "",
748
+ message.payload.moduleMap || {},
749
+ );
775
750
 
776
751
  if (typeof process.send === "function") {
777
752
  process.send({ id: message.id, ok: true, html });
@@ -811,7 +786,7 @@ function sanitizeInitialHtmlWorkerNodeOptions(rawNodeOptions) {
811
786
  }
812
787
  return rawNodeOptions.replace(/(^|\s)--conditions\s+react-server(?=\s|$)/g, " ").replace(/(^|\s)-r\s+(\S*webframez-react\/register)(?=\s|$)/g, " ").replace(/\s+/g, " ").trim();
813
788
  }
814
- function createInitialHtmlWorker(pagesDir) {
789
+ function createInitialHtmlWorker(_pagesDir) {
815
790
  let child = null;
816
791
  let nextRequestId = 1;
817
792
  let stderrBuffer = "";
@@ -842,8 +817,7 @@ function createInitialHtmlWorker(pagesDir) {
842
817
  cwd: process.cwd(),
843
818
  env: {
844
819
  ...process.env,
845
- NODE_OPTIONS: sanitizeInitialHtmlWorkerNodeOptions(process.env.NODE_OPTIONS),
846
- WEBFRAMEZ_REACT_PAGES_DIR: pagesDir
820
+ NODE_OPTIONS: sanitizeInitialHtmlWorkerNodeOptions(process.env.NODE_OPTIONS)
847
821
  },
848
822
  stdio: ["ignore", "ignore", "pipe", "ipc"]
849
823
  });
@@ -883,34 +857,6 @@ ${stderrBuffer.trim()}` : "";
883
857
  return child;
884
858
  };
885
859
  return {
886
- render(payload) {
887
- const activeChild = startWorker();
888
- const requestId = nextRequestId++;
889
- return new Promise((resolve, reject) => {
890
- const timeout = setTimeout(() => {
891
- rejectPending(new Error("[webframez-react] Initial HTML worker timed out"));
892
- stopWorker();
893
- }, 1e4);
894
- pending.set(requestId, { resolve, reject, timeout });
895
- const request = {
896
- id: requestId,
897
- type: "render-route",
898
- payload
899
- };
900
- activeChild.send(request, (error) => {
901
- if (!error) {
902
- return;
903
- }
904
- const entry = pending.get(requestId);
905
- if (!entry) {
906
- return;
907
- }
908
- pending.delete(requestId);
909
- clearTimeout(entry.timeout);
910
- entry.reject(error instanceof Error ? error : new Error(String(error)));
911
- });
912
- });
913
- },
914
860
  renderFromFlightData(payload) {
915
861
  const activeChild = startWorker();
916
862
  const requestId = nextRequestId++;
@@ -1154,21 +1100,17 @@ function createNodeRequestHandler(options) {
1154
1100
  });
1155
1101
  let rootHtml = "";
1156
1102
  try {
1157
- rootHtml = await initialHtmlWorker.render({
1158
- pathname: stripBasePath(url.pathname, basePath),
1159
- searchParams: parseSearchParams(url.searchParams),
1160
- cookies: requestCookies,
1161
- basename: basePath
1103
+ rootHtml = await initialHtmlWorker.renderFromFlightData({
1104
+ flightData: initialFlightData,
1105
+ moduleMap
1162
1106
  });
1163
1107
  } catch (error) {
1164
1108
  console.error("[webframez-react] Failed to render initial HTML", error);
1165
1109
  try {
1166
1110
  initialHtmlWorker.dispose();
1167
- rootHtml = await initialHtmlWorker.render({
1168
- pathname: stripBasePath(url.pathname, basePath),
1169
- searchParams: parseSearchParams(url.searchParams),
1170
- cookies: requestCookies,
1171
- basename: basePath
1111
+ rootHtml = await initialHtmlWorker.renderFromFlightData({
1112
+ flightData: initialFlightData,
1113
+ moduleMap
1172
1114
  });
1173
1115
  } catch (retryError) {
1174
1116
  console.error("[webframez-react] Retry for initial HTML failed", retryError);
@@ -639,11 +639,6 @@ const Module = require("node:module");
639
639
  const { Writable } = require("node:stream");
640
640
  const { createFromReadableStream } = require("react-server-dom-webpack/client.node");
641
641
 
642
- const pagesDir = process.env.WEBFRAMEZ_REACT_PAGES_DIR || "";
643
- if (!pagesDir) {
644
- throw new Error("Missing WEBFRAMEZ_REACT_PAGES_DIR");
645
- }
646
-
647
642
  const originalResolveFilename = Module._resolveFilename;
648
643
  const rootParent = {
649
644
  id: "__webframez_react_worker__",
@@ -681,12 +676,10 @@ Module._resolveFilename = function(request, parent, isMain, options) {
681
676
  return originalResolveFilename.call(this, request, parent, isMain, options);
682
677
  };
683
678
 
684
- const { createFileRouter } = require("@webtypen/webframez-react/router");
685
679
  const reactDomPkg = require.resolve("react-dom/package.json", {
686
- paths: [process.cwd(), pagesDir]
680
+ paths: [process.cwd()]
687
681
  });
688
682
  const reactDomServer = require(path.join(path.dirname(reactDomPkg), "server.node.js"));
689
- const router = createFileRouter({ pagesDir });
690
683
 
691
684
  function renderHtml(model) {
692
685
  return new Promise((resolve, reject) => {
@@ -747,33 +740,15 @@ async function renderHtmlFromFlightData(flightData, moduleMap) {
747
740
  }
748
741
 
749
742
  process.on("message", async (message) => {
750
- if (!message || (message.type !== "render-route" && message.type !== "render-flight")) {
743
+ if (!message || message.type !== "render-flight") {
751
744
  return;
752
745
  }
753
746
 
754
747
  try {
755
- let html = "";
756
-
757
- if (message.type === "render-route") {
758
- const previousBasename = globalThis.__RSC_BASENAME;
759
- globalThis.__RSC_BASENAME = message.payload.basename || "";
760
-
761
- try {
762
- const resolved = await router.resolve({
763
- pathname: message.payload.pathname,
764
- searchParams: message.payload.searchParams || {},
765
- cookies: message.payload.cookies || {},
766
- });
767
- html = await renderHtml(resolved.model);
768
- } finally {
769
- globalThis.__RSC_BASENAME = previousBasename;
770
- }
771
- } else {
772
- html = await renderHtmlFromFlightData(
773
- message.payload.flightData || "",
774
- message.payload.moduleMap || {},
775
- );
776
- }
748
+ const html = await renderHtmlFromFlightData(
749
+ message.payload.flightData || "",
750
+ message.payload.moduleMap || {},
751
+ );
777
752
 
778
753
  if (typeof process.send === "function") {
779
754
  process.send({ id: message.id, ok: true, html });
@@ -813,7 +788,7 @@ function sanitizeInitialHtmlWorkerNodeOptions(rawNodeOptions) {
813
788
  }
814
789
  return rawNodeOptions.replace(/(^|\s)--conditions\s+react-server(?=\s|$)/g, " ").replace(/(^|\s)-r\s+(\S*webframez-react\/register)(?=\s|$)/g, " ").replace(/\s+/g, " ").trim();
815
790
  }
816
- function createInitialHtmlWorker(pagesDir) {
791
+ function createInitialHtmlWorker(_pagesDir) {
817
792
  let child = null;
818
793
  let nextRequestId = 1;
819
794
  let stderrBuffer = "";
@@ -844,8 +819,7 @@ function createInitialHtmlWorker(pagesDir) {
844
819
  cwd: process.cwd(),
845
820
  env: {
846
821
  ...process.env,
847
- NODE_OPTIONS: sanitizeInitialHtmlWorkerNodeOptions(process.env.NODE_OPTIONS),
848
- WEBFRAMEZ_REACT_PAGES_DIR: pagesDir
822
+ NODE_OPTIONS: sanitizeInitialHtmlWorkerNodeOptions(process.env.NODE_OPTIONS)
849
823
  },
850
824
  stdio: ["ignore", "ignore", "pipe", "ipc"]
851
825
  });
@@ -885,34 +859,6 @@ ${stderrBuffer.trim()}` : "";
885
859
  return child;
886
860
  };
887
861
  return {
888
- render(payload) {
889
- const activeChild = startWorker();
890
- const requestId = nextRequestId++;
891
- return new Promise((resolve, reject) => {
892
- const timeout = setTimeout(() => {
893
- rejectPending(new Error("[webframez-react] Initial HTML worker timed out"));
894
- stopWorker();
895
- }, 1e4);
896
- pending.set(requestId, { resolve, reject, timeout });
897
- const request = {
898
- id: requestId,
899
- type: "render-route",
900
- payload
901
- };
902
- activeChild.send(request, (error) => {
903
- if (!error) {
904
- return;
905
- }
906
- const entry = pending.get(requestId);
907
- if (!entry) {
908
- return;
909
- }
910
- pending.delete(requestId);
911
- clearTimeout(entry.timeout);
912
- entry.reject(error instanceof Error ? error : new Error(String(error)));
913
- });
914
- });
915
- },
916
862
  renderFromFlightData(payload) {
917
863
  const activeChild = startWorker();
918
864
  const requestId = nextRequestId++;
@@ -1156,21 +1102,17 @@ function createNodeRequestHandler(options) {
1156
1102
  });
1157
1103
  let rootHtml = "";
1158
1104
  try {
1159
- rootHtml = await initialHtmlWorker.render({
1160
- pathname: stripBasePath(url.pathname, basePath),
1161
- searchParams: parseSearchParams(url.searchParams),
1162
- cookies: requestCookies,
1163
- basename: basePath
1105
+ rootHtml = await initialHtmlWorker.renderFromFlightData({
1106
+ flightData: initialFlightData,
1107
+ moduleMap
1164
1108
  });
1165
1109
  } catch (error) {
1166
1110
  console.error("[webframez-react] Failed to render initial HTML", error);
1167
1111
  try {
1168
1112
  initialHtmlWorker.dispose();
1169
- rootHtml = await initialHtmlWorker.render({
1170
- pathname: stripBasePath(url.pathname, basePath),
1171
- searchParams: parseSearchParams(url.searchParams),
1172
- cookies: requestCookies,
1173
- basename: basePath
1113
+ rootHtml = await initialHtmlWorker.renderFromFlightData({
1114
+ flightData: initialFlightData,
1115
+ moduleMap
1174
1116
  });
1175
1117
  } catch (retryError) {
1176
1118
  console.error("[webframez-react] Retry for initial HTML failed", retryError);
@@ -611,11 +611,6 @@ const Module = require("node:module");
611
611
  const { Writable } = require("node:stream");
612
612
  const { createFromReadableStream } = require("react-server-dom-webpack/client.node");
613
613
 
614
- const pagesDir = process.env.WEBFRAMEZ_REACT_PAGES_DIR || "";
615
- if (!pagesDir) {
616
- throw new Error("Missing WEBFRAMEZ_REACT_PAGES_DIR");
617
- }
618
-
619
614
  const originalResolveFilename = Module._resolveFilename;
620
615
  const rootParent = {
621
616
  id: "__webframez_react_worker__",
@@ -653,12 +648,10 @@ Module._resolveFilename = function(request, parent, isMain, options) {
653
648
  return originalResolveFilename.call(this, request, parent, isMain, options);
654
649
  };
655
650
 
656
- const { createFileRouter } = require("@webtypen/webframez-react/router");
657
651
  const reactDomPkg = require.resolve("react-dom/package.json", {
658
- paths: [process.cwd(), pagesDir]
652
+ paths: [process.cwd()]
659
653
  });
660
654
  const reactDomServer = require(path.join(path.dirname(reactDomPkg), "server.node.js"));
661
- const router = createFileRouter({ pagesDir });
662
655
 
663
656
  function renderHtml(model) {
664
657
  return new Promise((resolve, reject) => {
@@ -719,33 +712,15 @@ async function renderHtmlFromFlightData(flightData, moduleMap) {
719
712
  }
720
713
 
721
714
  process.on("message", async (message) => {
722
- if (!message || (message.type !== "render-route" && message.type !== "render-flight")) {
715
+ if (!message || message.type !== "render-flight") {
723
716
  return;
724
717
  }
725
718
 
726
719
  try {
727
- let html = "";
728
-
729
- if (message.type === "render-route") {
730
- const previousBasename = globalThis.__RSC_BASENAME;
731
- globalThis.__RSC_BASENAME = message.payload.basename || "";
732
-
733
- try {
734
- const resolved = await router.resolve({
735
- pathname: message.payload.pathname,
736
- searchParams: message.payload.searchParams || {},
737
- cookies: message.payload.cookies || {},
738
- });
739
- html = await renderHtml(resolved.model);
740
- } finally {
741
- globalThis.__RSC_BASENAME = previousBasename;
742
- }
743
- } else {
744
- html = await renderHtmlFromFlightData(
745
- message.payload.flightData || "",
746
- message.payload.moduleMap || {},
747
- );
748
- }
720
+ const html = await renderHtmlFromFlightData(
721
+ message.payload.flightData || "",
722
+ message.payload.moduleMap || {},
723
+ );
749
724
 
750
725
  if (typeof process.send === "function") {
751
726
  process.send({ id: message.id, ok: true, html });
@@ -785,7 +760,7 @@ function sanitizeInitialHtmlWorkerNodeOptions(rawNodeOptions) {
785
760
  }
786
761
  return rawNodeOptions.replace(/(^|\s)--conditions\s+react-server(?=\s|$)/g, " ").replace(/(^|\s)-r\s+(\S*webframez-react\/register)(?=\s|$)/g, " ").replace(/\s+/g, " ").trim();
787
762
  }
788
- function createInitialHtmlWorker(pagesDir) {
763
+ function createInitialHtmlWorker(_pagesDir) {
789
764
  let child = null;
790
765
  let nextRequestId = 1;
791
766
  let stderrBuffer = "";
@@ -816,8 +791,7 @@ function createInitialHtmlWorker(pagesDir) {
816
791
  cwd: process.cwd(),
817
792
  env: {
818
793
  ...process.env,
819
- NODE_OPTIONS: sanitizeInitialHtmlWorkerNodeOptions(process.env.NODE_OPTIONS),
820
- WEBFRAMEZ_REACT_PAGES_DIR: pagesDir
794
+ NODE_OPTIONS: sanitizeInitialHtmlWorkerNodeOptions(process.env.NODE_OPTIONS)
821
795
  },
822
796
  stdio: ["ignore", "ignore", "pipe", "ipc"]
823
797
  });
@@ -857,34 +831,6 @@ ${stderrBuffer.trim()}` : "";
857
831
  return child;
858
832
  };
859
833
  return {
860
- render(payload) {
861
- const activeChild = startWorker();
862
- const requestId = nextRequestId++;
863
- return new Promise((resolve, reject) => {
864
- const timeout = setTimeout(() => {
865
- rejectPending(new Error("[webframez-react] Initial HTML worker timed out"));
866
- stopWorker();
867
- }, 1e4);
868
- pending.set(requestId, { resolve, reject, timeout });
869
- const request = {
870
- id: requestId,
871
- type: "render-route",
872
- payload
873
- };
874
- activeChild.send(request, (error) => {
875
- if (!error) {
876
- return;
877
- }
878
- const entry = pending.get(requestId);
879
- if (!entry) {
880
- return;
881
- }
882
- pending.delete(requestId);
883
- clearTimeout(entry.timeout);
884
- entry.reject(error instanceof Error ? error : new Error(String(error)));
885
- });
886
- });
887
- },
888
834
  renderFromFlightData(payload) {
889
835
  const activeChild = startWorker();
890
836
  const requestId = nextRequestId++;
@@ -1128,21 +1074,17 @@ function createNodeRequestHandler(options) {
1128
1074
  });
1129
1075
  let rootHtml = "";
1130
1076
  try {
1131
- rootHtml = await initialHtmlWorker.render({
1132
- pathname: stripBasePath(url.pathname, basePath),
1133
- searchParams: parseSearchParams(url.searchParams),
1134
- cookies: requestCookies,
1135
- basename: basePath
1077
+ rootHtml = await initialHtmlWorker.renderFromFlightData({
1078
+ flightData: initialFlightData,
1079
+ moduleMap
1136
1080
  });
1137
1081
  } catch (error) {
1138
1082
  console.error("[webframez-react] Failed to render initial HTML", error);
1139
1083
  try {
1140
1084
  initialHtmlWorker.dispose();
1141
- rootHtml = await initialHtmlWorker.render({
1142
- pathname: stripBasePath(url.pathname, basePath),
1143
- searchParams: parseSearchParams(url.searchParams),
1144
- cookies: requestCookies,
1145
- basename: basePath
1085
+ rootHtml = await initialHtmlWorker.renderFromFlightData({
1086
+ flightData: initialFlightData,
1087
+ moduleMap
1146
1088
  });
1147
1089
  } catch (retryError) {
1148
1090
  console.error("[webframez-react] Retry for initial HTML failed", retryError);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webtypen/webframez-react",
3
- "version": "0.0.17",
3
+ "version": "0.0.18",
4
4
  "description": "TypeScript React RSC addition for @webtypen/webframez-core",
5
5
  "homepage": "https://webtypen.de/",
6
6
  "author": {