eddev 2.0.0-beta.103 → 2.0.0-beta.105

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.
@@ -18,4 +18,10 @@ type RenderErrorPageArgs = {
18
18
  realError?: Error;
19
19
  };
20
20
  export declare function renderErrorPage(args: RenderErrorPageArgs): Promise<Response>;
21
+ type Asset = {
22
+ tag: string;
23
+ attrs: Record<string, string | boolean>;
24
+ children?: string;
25
+ };
26
+ export declare function renderAsset({ tag, attrs, children }: Asset): string;
21
27
  export {};
@@ -1,5 +1,4 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { renderAsset } from "@vinxi/react";
3
2
  import { renderToPipeableStream, renderToString } from "react-dom/server";
4
3
  import { Writable } from "stream";
5
4
  import { MetaTags } from "../entry/MetaTags.js";
@@ -7,7 +6,6 @@ import { SSRRoot } from "../entry/ssr-root.js";
7
6
  import { RouteLoader } from "../lib/routing/loader.js";
8
7
  import { AssetCaptureContext } from "../utils/asset-capture.js";
9
8
  import { ServerContext } from "./server-context.js";
10
- import { Fragment } from "react/jsx-runtime";
11
9
  export async function getSsrStream(args) {
12
10
  const clientManifest = ServerContext.main.runtime.getManifest("client");
13
11
  const preloadAssets = new Set([clientManifest.handler]);
@@ -66,10 +64,16 @@ export async function getSsrStream(args) {
66
64
  controller.enqueue(new TextEncoder().encode(`\n<!-- ${JSON.stringify(assets)} -->\n`));
67
65
  for (const _asset of assets) {
68
66
  const asset = _asset;
69
- if (preloadAssets.has(asset.key))
67
+ // Ensure that each asset is only included once
68
+ const key = asset?.attrs?.key;
69
+ if (!key) {
70
+ throw new Error("Asset must have a key: " + JSON.stringify(asset));
71
+ }
72
+ if (preloadAssets.has(key))
70
73
  continue;
71
- controller.enqueue(new TextEncoder().encode(renderToString(_jsx(Fragment, { children: renderAsset(asset) }))));
72
- preloadAssets.add(asset.key);
74
+ preloadAssets.add(key);
75
+ // Render the asset
76
+ controller.enqueue(new TextEncoder().encode(renderAsset(asset)));
73
77
  }
74
78
  }
75
79
  // console.log("ASSETS", await clientManifest)
@@ -158,3 +162,34 @@ export async function renderErrorPage(args) {
158
162
  newOrigin: args.newOrigin,
159
163
  });
160
164
  }
165
+ export function renderAsset({ tag, attrs, children }) {
166
+ const formatAttributes = (attributes) => {
167
+ return Object.entries(attributes)
168
+ .map(([attr, value]) => {
169
+ if (value === true) {
170
+ return attr;
171
+ }
172
+ else if (value !== false && value != null) {
173
+ return `${attr}="${String(value).replace(/"/g, "&quot;")}"`;
174
+ }
175
+ return "";
176
+ })
177
+ .filter(Boolean)
178
+ .join(" ");
179
+ };
180
+ switch (tag) {
181
+ case "script":
182
+ if (attrs.src) {
183
+ return `<script ${formatAttributes(attrs)}></script>`;
184
+ }
185
+ else {
186
+ return `<script ${formatAttributes(attrs)}>${children ?? ""}</script>`;
187
+ }
188
+ case "link":
189
+ return `<link ${formatAttributes(attrs)} />`;
190
+ case "style":
191
+ return `<style ${formatAttributes(attrs)}>${children ?? ""}</style>`;
192
+ default:
193
+ return "";
194
+ }
195
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eddev",
3
- "version": "2.0.0-beta.103",
3
+ "version": "2.0.0-beta.105",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "type": "module",