eddev 2.0.0-beta.104 → 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]);
@@ -75,7 +73,7 @@ export async function getSsrStream(args) {
75
73
  continue;
76
74
  preloadAssets.add(key);
77
75
  // Render the asset
78
- controller.enqueue(new TextEncoder().encode(renderToString(_jsx(Fragment, { children: renderAsset(asset) }))));
76
+ controller.enqueue(new TextEncoder().encode(renderAsset(asset)));
79
77
  }
80
78
  }
81
79
  // console.log("ASSETS", await clientManifest)
@@ -164,3 +162,34 @@ export async function renderErrorPage(args) {
164
162
  newOrigin: args.newOrigin,
165
163
  });
166
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.104",
3
+ "version": "2.0.0-beta.105",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "type": "module",