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.
@@ -1,13 +1,12 @@
1
- import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
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 (_jsxs("html", { lang: "en", children: [_jsxs("head", { children: [_jsx(DynamicMetaTags, { tags: props.metaTags }), _jsx(Trackers, { position: "head" }), props.assets] }), _jsxs("body", { children: [_jsx(Trackers, { position: "body" }), _jsx(APIProvider, { children: _jsx(Suspense, { children: _jsx(BrowserRouter, {}) }) }), _jsx(DevUILoader, {}), _jsx(Trackers, { position: "footer" })] })] }));
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, jsxs as _jsxs } from "react/jsx-runtime";
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 (_jsxs("html", { lang: "en", children: [_jsxs("head", { children: [_jsx(MetaTags, { tags: props.metaTags }), props.assets] }), _jsx("body", { children: _jsx(APIProvider, { children: _jsx(Suspense, { children: _jsx(SSRRouter, { loader: loader, route: normalizeRoute({
12
- id: "initial",
13
- component: loader.getRouteComponent(props.initialData.view),
14
- key: "",
15
- props: props.initialData.viewData.data,
16
- view: props.initialData.view,
17
- search: "",
18
- pathname: props.pathname,
19
- query: {},
20
- hash: "",
21
- meta: getRouteMeta(props.initialData),
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
  }
@@ -4,5 +4,5 @@ export type DynamicComponent<T extends ComponentType<any>> = T & {
4
4
  };
5
5
  export declare function dynamic<T extends ComponentType<any>>(factory: () => Promise<{
6
6
  default: T;
7
- }>): DynamicComponent<T>;
7
+ }>, name?: string): DynamicComponent<T>;
8
8
  export default dynamic;
@@ -1,9 +1,13 @@
1
1
  import { createElement, forwardRef, lazy, memo, useRef } from "react";
2
- export function dynamic(factory) {
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
- const jsx = (_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() }));
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
- const writableStream = new Writable({
35
- emitClose: true,
36
- write(chunk, encoding, callback) {
37
- controller.enqueue(chunk);
38
- callback();
39
- },
40
- final(callback) {
41
- controller.close();
42
- callback();
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
- stream.pipe(writableStream);
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
  }
@@ -0,0 +1,2 @@
1
+ export declare const AssetCaptureContext: import("react").Context<Set<string>>;
2
+ export declare const useAssetCapture: () => Set<string>;
@@ -0,0 +1,5 @@
1
+ import { createContext, useContext } from "react";
2
+ export const AssetCaptureContext = createContext(new Set());
3
+ export const useAssetCapture = () => {
4
+ return useContext(AssetCaptureContext);
5
+ };
@@ -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
- // process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = "0"
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
  })}}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eddev",
3
- "version": "2.0.0-beta.89",
3
+ "version": "2.0.0-beta.90",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "type": "module",