eddev 2.0.0-beta.100 → 2.0.0-beta.102

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.
@@ -1,4 +1,4 @@
1
- import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { renderAsset } from "@vinxi/react";
3
3
  import { renderToPipeableStream, renderToString } from "react-dom/server";
4
4
  import { Writable } from "stream";
@@ -9,17 +9,9 @@ import { AssetCaptureContext } from "../utils/asset-capture.js";
9
9
  import { ServerContext } from "./server-context.js";
10
10
  export async function getSsrStream(args) {
11
11
  const clientManifest = ServerContext.main.runtime.getManifest("client");
12
- const assets = await clientManifest.inputs[clientManifest.handler].assets();
13
- // console.log(
14
- // "M",
15
- // assets.filter((f) => (f as any).tag === "script"),
16
- // clientManifest.inputs[clientManifest.handler],
17
- // )
18
- // for (let k in clientManifest.chunks) {
19
- // console.log(k)
20
- // }
21
- const dynamicAssets = new Set([]);
22
- const jsx = (_jsx(AssetCaptureContext.Provider, { value: dynamicAssets, children: _jsx(SSRRoot, { metaTags: args.initialData?.meta?.head || [], pathname: args.pathname, initialData: args.initialData, loader: new RouteLoader() }) }));
12
+ const preloadAssets = new Set([clientManifest.handler]);
13
+ const includedAssets = new Set();
14
+ const jsx = (_jsx(AssetCaptureContext.Provider, { value: preloadAssets, children: _jsx(SSRRoot, { metaTags: args.initialData?.meta?.head || [], pathname: args.pathname, initialData: args.initialData, loader: new RouteLoader() }) }));
23
15
  const stream = await new Promise(async (resolve, reject) => {
24
16
  // console.log("Rendering to pipable")
25
17
  const stream = renderToPipeableStream(jsx, {
@@ -42,7 +34,7 @@ export async function getSsrStream(args) {
42
34
  })};\n`,
43
35
  });
44
36
  });
45
- const [initial, middle, end] = renderToString(_jsxs("html", { lang: "en", children: [_jsxs("head", { children: [_jsx(MetaTags, { tags: args.initialData.meta?.head ?? [] }), "%%trackers_head%%", assets.map((m) => renderAsset(m)), "%%$%%"] }), _jsxs("body", { children: ["%%trackers_body%%", _jsx("div", { id: "_root", children: "%%$%%" }), "%%trackers_footer%%"] })] }))
37
+ const [initial, middle, end] = renderToString(_jsxs("html", { lang: "en", children: [_jsxs("head", { children: [_jsx(MetaTags, { tags: args.initialData.meta?.head ?? [] }), "%%trackers_head%% %%$%%"] }), _jsxs("body", { children: ["%%trackers_body%%", _jsx("div", { id: "_root", children: "%%$%%" }), "%%trackers_footer%%"] })] }))
46
38
  .replace(/%%trackers_(head|body|footer)%%/g, (_, name) => {
47
39
  return args.initialData.trackers?.[name] || "";
48
40
  })
@@ -67,16 +59,21 @@ export async function getSsrStream(args) {
67
59
  });
68
60
  stream.pipe(writableStream);
69
61
  });
70
- for (const asset of dynamicAssets) {
71
- const assets = await clientManifest.inputs[asset].assets();
62
+ for (const input of preloadAssets) {
63
+ const assets = await clientManifest.inputs[input].assets();
72
64
  // console.log(assets)
73
65
  // console.log("A", assets.output, (await assets.assets())?.[0])
74
66
  // const assets = await clientManifest.inputs[assets.output.path!]?.assets()
75
67
  // console.log("F?", inputs)
76
- controller.enqueue(new TextEncoder().encode(`\n<!-- for ${asset} -->`));
77
- controller.enqueue(new TextEncoder().encode(`\n<!-- ${JSON.stringify(assets)} -->`));
78
- // controller.enqueue(new TextEncoder().encode(`\n<script>${JSON.stringify(assets)}</script>`))
79
- controller.enqueue(new TextEncoder().encode(renderToString(_jsx(_Fragment, { children: assets.map((a) => renderAsset(asset)) }))));
68
+ controller.enqueue(new TextEncoder().encode(`\n<!-- for ${input} -->`));
69
+ controller.enqueue(new TextEncoder().encode(`\n<!-- ${JSON.stringify(assets)} -->\n`));
70
+ for (const _asset of assets) {
71
+ const asset = _asset;
72
+ if (preloadAssets.has(asset.key))
73
+ continue;
74
+ controller.enqueue(new TextEncoder().encode(renderToString(renderAsset(asset)) + "\n"));
75
+ preloadAssets.add(asset.key);
76
+ }
80
77
  }
81
78
  // console.log("ASSETS", await clientManifest)
82
79
  controller.enqueue(new TextEncoder().encode(middle));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eddev",
3
- "version": "2.0.0-beta.100",
3
+ "version": "2.0.0-beta.102",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "type": "module",