eddev 2.0.0-beta.89 → 2.0.0-beta.90
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/app/entry/ssr-root-client.js +2 -3
- package/dist/app/entry/ssr-root.js +13 -14
- package/dist/app/lib/dynamic/dynamic.d.ts +1 -1
- package/dist/app/lib/dynamic/dynamic.js +5 -1
- package/dist/app/server/render-ssr-page.js +50 -14
- package/dist/app/utils/asset-capture.d.ts +2 -0
- package/dist/app/utils/asset-capture.js +5 -0
- package/dist/node/cli/cli.js +1 -1
- package/dist/node/compiler/vinxi-codegen.js +3 -4
- package/package.json +1 -1
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import { jsx as _jsx,
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
import { Suspense, useEffect, useState } from "react";
|
|
3
3
|
import { useSnapshot } from "valtio";
|
|
4
|
-
import { DevUILoader } from "../lib/devtools/loader.js";
|
|
5
4
|
import { BrowserRouter } from "../lib/routing/components/BrowserRouter.js";
|
|
6
5
|
import { clientMetaTags } from "../lib/routing/context.js";
|
|
7
6
|
import { APIProvider } from "../utils/APIProvider.js";
|
|
8
7
|
import { MetaTags } from "./MetaTags.js";
|
|
9
8
|
export function SSRClientRoot(props) {
|
|
10
|
-
return (
|
|
9
|
+
return (_jsx(APIProvider, { children: _jsx(Suspense, { children: _jsx(BrowserRouter, {}) }) }));
|
|
11
10
|
}
|
|
12
11
|
function DynamicMetaTags(props) {
|
|
13
12
|
const dynamicTags = useSnapshot(clientMetaTags).tags;
|
|
@@ -1,23 +1,22 @@
|
|
|
1
|
-
import { jsx as _jsx
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { Suspense } from "react";
|
|
3
3
|
import { SSRRouter } from "../lib/routing/components/SSRRouter.js";
|
|
4
4
|
import { getRouteMeta, normalizeRoute } from "../lib/routing/utils.js";
|
|
5
5
|
import { APIProvider } from "../utils/APIProvider.js";
|
|
6
|
-
import { MetaTags } from "./MetaTags.js";
|
|
7
6
|
export function SSRRoot(props) {
|
|
8
7
|
const loader = props.loader;
|
|
9
8
|
loader.setAppData(props.initialData.appData.data);
|
|
10
9
|
loader.populateRouteData(props.pathname, props.initialData);
|
|
11
|
-
return (
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
10
|
+
return (_jsx(APIProvider, { children: _jsx(Suspense, { children: _jsx(SSRRouter, { loader: loader, route: normalizeRoute({
|
|
11
|
+
id: "initial",
|
|
12
|
+
component: loader.getRouteComponent(props.initialData.view),
|
|
13
|
+
key: "",
|
|
14
|
+
props: props.initialData.viewData.data,
|
|
15
|
+
view: props.initialData.view,
|
|
16
|
+
search: "",
|
|
17
|
+
pathname: props.pathname,
|
|
18
|
+
query: {},
|
|
19
|
+
hash: "",
|
|
20
|
+
meta: getRouteMeta(props.initialData),
|
|
21
|
+
}) }) }) }));
|
|
23
22
|
}
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import { createElement, forwardRef, lazy, memo, useRef } from "react";
|
|
2
|
-
|
|
2
|
+
import { useAssetCapture } from "../../utils/asset-capture";
|
|
3
|
+
export function dynamic(factory, name) {
|
|
3
4
|
const ReactLazyComponent = lazy(factory);
|
|
4
5
|
let PreloadedComponent;
|
|
5
6
|
let factoryPromise;
|
|
6
7
|
const Component = memo(forwardRef(function LazyWithPreload(props, ref) {
|
|
8
|
+
if (env.serverless && !env.client && name) {
|
|
9
|
+
useAssetCapture()?.add(name);
|
|
10
|
+
}
|
|
7
11
|
// Once one of these is chosen, we must ensure that it continues to be
|
|
8
12
|
// used for all subsequent renders, otherwise it can cause the
|
|
9
13
|
// underlying component to be unmounted and remounted.
|
|
@@ -1,15 +1,26 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
import { renderAsset } from "@vinxi/react";
|
|
3
3
|
import { Suspense } from "react";
|
|
4
|
-
import { renderToPipeableStream } from "react-dom/server";
|
|
4
|
+
import { renderToPipeableStream, renderToString } from "react-dom/server";
|
|
5
5
|
import { SSRRoot } from "../entry/ssr-root.js";
|
|
6
6
|
import { RouteLoader } from "../lib/routing/loader.js";
|
|
7
7
|
import { ServerContext } from "./server-context.js";
|
|
8
8
|
import { Writable } from "stream";
|
|
9
|
+
import { MetaTags } from "../entry/MetaTags.js";
|
|
10
|
+
import { AssetCaptureContext } from "../utils/asset-capture.js";
|
|
9
11
|
export async function getSsrStream(args) {
|
|
10
12
|
const clientManifest = ServerContext.main.runtime.getManifest("client");
|
|
11
13
|
const assets = await clientManifest.inputs[clientManifest.handler].assets();
|
|
12
|
-
|
|
14
|
+
// console.log(
|
|
15
|
+
// "M",
|
|
16
|
+
// assets.filter((f) => (f as any).tag === "script"),
|
|
17
|
+
// clientManifest.inputs[clientManifest.handler],
|
|
18
|
+
// )
|
|
19
|
+
// for (let k in clientManifest.chunks) {
|
|
20
|
+
// console.log(k)
|
|
21
|
+
// }
|
|
22
|
+
const dynamicAssets = new Set([]);
|
|
23
|
+
const jsx = (_jsx(AssetCaptureContext.Provider, { value: dynamicAssets, children: _jsx(SSRRoot, { assets: _jsx(Suspense, { children: assets.map((m) => renderAsset(m)) }), metaTags: args.initialData?.meta?.head || [], pathname: args.pathname, initialData: args.initialData, loader: new RouteLoader() }) }));
|
|
13
24
|
const stream = await new Promise(async (resolve, reject) => {
|
|
14
25
|
// console.log("Rendering to pipable")
|
|
15
26
|
const stream = renderToPipeableStream(jsx, {
|
|
@@ -29,20 +40,45 @@ export async function getSsrStream(args) {
|
|
|
29
40
|
bootstrapScriptContent: `window.manifest = ${JSON.stringify(await clientManifest.json())};\nwindow._PAGE_DATA = ${JSON.stringify(args.initialData)};\nwindow._TRACKERS = ${JSON.stringify(args.initialData.trackers)};`,
|
|
30
41
|
});
|
|
31
42
|
});
|
|
43
|
+
const [initial, middle, end] = renderToString(_jsxs("html", { lang: "en", children: [_jsxs("head", { children: [_jsx(MetaTags, { tags: args.initialData.meta?.head ?? [] }), _jsx(MetaTags, { tags: args.initialData.trackers?.head ?? [] }), assets.map((m) => renderAsset(m)), "%%%%"] }), _jsxs("body", { children: [_jsx(MetaTags, { tags: args.initialData.trackers?.body ?? [] }), _jsx("div", { id: "_root", children: "%%%%" }), _jsx(MetaTags, { tags: args.initialData.trackers?.footer ?? [] })] })] })).split("%%%%");
|
|
32
44
|
return new ReadableStream({
|
|
33
45
|
async start(controller) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
46
|
+
controller.enqueue(new TextEncoder().encode(initial));
|
|
47
|
+
const inner = await new Promise((resolve, reject) => {
|
|
48
|
+
let buffer = [];
|
|
49
|
+
const writableStream = new Writable({
|
|
50
|
+
emitClose: true,
|
|
51
|
+
write(chunk, encoding, callback) {
|
|
52
|
+
buffer.push(chunk);
|
|
53
|
+
// controller.enqueue(chunk)
|
|
54
|
+
callback();
|
|
55
|
+
},
|
|
56
|
+
final(callback) {
|
|
57
|
+
resolve(buffer);
|
|
58
|
+
// controller.close()
|
|
59
|
+
callback();
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
stream.pipe(writableStream);
|
|
44
63
|
});
|
|
45
|
-
|
|
64
|
+
console.log(clientManifest.json());
|
|
65
|
+
for (const asset of dynamicAssets) {
|
|
66
|
+
const assets = await clientManifest.inputs["/" + asset].assets();
|
|
67
|
+
// console.log(assets)
|
|
68
|
+
// console.log("A", assets.output, (await assets.assets())?.[0])
|
|
69
|
+
// const assets = await clientManifest.inputs[assets.output.path!]?.assets()
|
|
70
|
+
// console.log("F?", inputs)
|
|
71
|
+
controller.enqueue(new TextEncoder().encode(`\n<!-- for ${asset} -->`));
|
|
72
|
+
controller.enqueue(new TextEncoder().encode(renderToString(_jsx(_Fragment, { children: assets.map((a) => renderAsset(asset)) }))));
|
|
73
|
+
}
|
|
74
|
+
// console.log("ASSETS", await clientManifest)
|
|
75
|
+
controller.enqueue(new TextEncoder().encode(middle));
|
|
76
|
+
for (const chunk of inner) {
|
|
77
|
+
controller.enqueue(chunk);
|
|
78
|
+
}
|
|
79
|
+
controller.enqueue(new TextEncoder().encode(end));
|
|
80
|
+
// console.log("Assets", dynamicAssets)
|
|
81
|
+
controller.close();
|
|
46
82
|
},
|
|
47
83
|
});
|
|
48
84
|
}
|
package/dist/node/cli/cli.js
CHANGED
|
@@ -218,7 +218,7 @@ program
|
|
|
218
218
|
.option("--host", "Hostname to serve the application", "127.0.0.1")
|
|
219
219
|
.option("--port", "Port to serve the application", "3000")
|
|
220
220
|
.action(async (options) => {
|
|
221
|
-
|
|
221
|
+
process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = "0";
|
|
222
222
|
process.env["NODE_ENV"] = "production";
|
|
223
223
|
process.env["HOST"] = options.host;
|
|
224
224
|
process.env["PORT"] = options.port;
|
|
@@ -132,14 +132,13 @@ export function createVinxiCodegen(opts) {
|
|
|
132
132
|
window.$reactRoot =
|
|
133
133
|
window.$reactRoot ||
|
|
134
134
|
hydrateRoot(
|
|
135
|
-
document
|
|
135
|
+
document.getElementById('_root')!,
|
|
136
136
|
<SSRClientRoot assets={getAssets()} metaTags={window._PAGE_DATA.meta.head} />,
|
|
137
137
|
)
|
|
138
138
|
|
|
139
139
|
if (import.meta.hot) {
|
|
140
140
|
import.meta.hot.accept((mod) => {
|
|
141
141
|
if (mod) {
|
|
142
|
-
const Assets = createAssets(getManifest("client").handler, getManifest("client"))
|
|
143
142
|
const app = <SSRClientRoot assets={getAssets()} metaTags={window._PAGE_DATA.meta.head} />
|
|
144
143
|
window.$reactRoot?.render(app)
|
|
145
144
|
}
|
|
@@ -397,7 +396,7 @@ export function createVinxiCodegen(opts) {
|
|
|
397
396
|
${Object.entries(blockManifest.blocks)
|
|
398
397
|
.filter(([name]) => !name.match(/^_[a-z]+$/i))
|
|
399
398
|
.map(([name, block]) => {
|
|
400
|
-
const importStatement = `dynamic(() => import(${JSON.stringify("../../../" + block.fileName)}))`;
|
|
399
|
+
const importStatement = `dynamic(() => import(${JSON.stringify("../../../" + block.fileName)}), ${JSON.stringify(block.fileName)})`;
|
|
401
400
|
return JSON.stringify(block.acfName) + ": " + importStatement;
|
|
402
401
|
})
|
|
403
402
|
.join(",\n")},
|
|
@@ -488,7 +487,7 @@ export function createVinxiCodegen(opts) {
|
|
|
488
487
|
importStatement = imp(name + "=" + src);
|
|
489
488
|
}
|
|
490
489
|
else {
|
|
491
|
-
importStatement = code `dynamic(() => import(${JSON.stringify(src)}))`;
|
|
490
|
+
importStatement = code `dynamic(() => import(${JSON.stringify(src)}), ${JSON.stringify(view.fileName)})`;
|
|
492
491
|
}
|
|
493
492
|
return code `${JSON.stringify(view.slug)}: ${importStatement},\n`;
|
|
494
493
|
})}}
|