hadars 0.2.0 → 0.2.2-rc.0
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/README.md +247 -15
- package/cli-lib.ts +184 -15
- package/dist/chunk-H72BZXOA.js +332 -0
- package/dist/cli.js +596 -23
- package/dist/cloudflare.cjs +1394 -0
- package/dist/cloudflare.d.cts +64 -0
- package/dist/cloudflare.d.ts +64 -0
- package/dist/cloudflare.js +68 -0
- package/dist/{hadars-Bh-V5YXg.d.cts → hadars-mKu5txjW.d.cts} +93 -37
- package/dist/{hadars-Bh-V5YXg.d.ts → hadars-mKu5txjW.d.ts} +93 -37
- package/dist/index.cjs +140 -164
- package/dist/index.d.cts +5 -11
- package/dist/index.d.ts +5 -11
- package/dist/index.js +140 -163
- package/dist/lambda.cjs +6 -2
- package/dist/lambda.d.cts +1 -2
- package/dist/lambda.d.ts +1 -2
- package/dist/lambda.js +10 -317
- package/dist/ssr-render-worker.js +3 -2
- package/dist/utils/Head.tsx +149 -195
- package/dist/utils/clientScript.tsx +9 -0
- package/index.ts +3 -0
- package/package.json +7 -2
- package/src/build.ts +29 -0
- package/src/cloudflare.ts +139 -0
- package/src/index.tsx +3 -3
- package/src/source/context.ts +113 -0
- package/src/source/graphiql.ts +96 -0
- package/src/source/inference.ts +188 -0
- package/src/source/runner.ts +114 -0
- package/src/source/store.ts +48 -0
- package/src/ssr-render-worker.ts +4 -1
- package/src/static.ts +106 -0
- package/src/types/hadars.ts +91 -2
- package/src/utils/Head.tsx +149 -195
- package/src/utils/clientScript.tsx +9 -0
- package/src/utils/response.tsx +10 -3
package/src/utils/response.tsx
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type React from "react";
|
|
2
|
-
import type { AppHead, HadarsRequest, HadarsEntryBase, HadarsEntryModule, HadarsProps, AppContext } from "../types/hadars";
|
|
2
|
+
import type { AppHead, HadarsRequest, HadarsEntryBase, HadarsEntryModule, HadarsProps, AppContext, HadarsStaticContext } from "../types/hadars";
|
|
3
3
|
import { renderToString, renderPreflight, createElement } from '../slim-react/index';
|
|
4
4
|
|
|
5
5
|
interface ReactResponseOptions {
|
|
@@ -10,6 +10,7 @@ interface ReactResponseOptions {
|
|
|
10
10
|
getInitProps: HadarsEntryModule<HadarsEntryBase>['getInitProps'];
|
|
11
11
|
getFinalProps: HadarsEntryModule<HadarsEntryBase>['getFinalProps'];
|
|
12
12
|
}
|
|
13
|
+
staticCtx?: HadarsStaticContext;
|
|
13
14
|
}
|
|
14
15
|
|
|
15
16
|
// ── Head HTML serialisation ────────────────────────────────────────────────
|
|
@@ -71,7 +72,7 @@ export const getReactResponse = async (
|
|
|
71
72
|
};
|
|
72
73
|
|
|
73
74
|
let props: HadarsEntryBase = {
|
|
74
|
-
...(getInitProps ? await getInitProps(req) : {}),
|
|
75
|
+
...(getInitProps ? await getInitProps(req, opts.staticCtx) : {}),
|
|
75
76
|
location: req.location,
|
|
76
77
|
context,
|
|
77
78
|
} as HadarsEntryBase;
|
|
@@ -82,6 +83,9 @@ export const getReactResponse = async (
|
|
|
82
83
|
// await continuations even when concurrent requests are in flight.
|
|
83
84
|
const unsuspend = { cache: new Map<string, any>() };
|
|
84
85
|
(globalThis as any).__hadarsUnsuspend = unsuspend;
|
|
86
|
+
// Expose the head context so HadarsHead can write into it without needing
|
|
87
|
+
// the user to manually wrap their App with HadarsContext.
|
|
88
|
+
(globalThis as any).__hadarsContext = context;
|
|
85
89
|
|
|
86
90
|
const element = createElement(App as any, props as any);
|
|
87
91
|
|
|
@@ -94,6 +98,7 @@ export const getReactResponse = async (
|
|
|
94
98
|
// Clear the global immediately — the closure-captured `unsuspend`
|
|
95
99
|
// keeps the cache alive. Re-set inside getAppBody() for the second pass.
|
|
96
100
|
(globalThis as any).__hadarsUnsuspend = null;
|
|
101
|
+
(globalThis as any).__hadarsContext = null;
|
|
97
102
|
}
|
|
98
103
|
|
|
99
104
|
// Head is fully populated — status is known.
|
|
@@ -104,15 +109,17 @@ export const getReactResponse = async (
|
|
|
104
109
|
// (no async waits). The caller flushes head BEFORE calling this.
|
|
105
110
|
const getAppBody = async (): Promise<string> => {
|
|
106
111
|
(globalThis as any).__hadarsUnsuspend = unsuspend;
|
|
112
|
+
(globalThis as any).__hadarsContext = context;
|
|
107
113
|
try {
|
|
108
114
|
return await renderToString(element);
|
|
109
115
|
} finally {
|
|
110
116
|
(globalThis as any).__hadarsUnsuspend = null;
|
|
117
|
+
(globalThis as any).__hadarsContext = null;
|
|
111
118
|
}
|
|
112
119
|
};
|
|
113
120
|
|
|
114
121
|
const finalize = async (): Promise<{ clientProps: Record<string, unknown> }> => {
|
|
115
|
-
const
|
|
122
|
+
const restProps = getFinalProps ? await getFinalProps(props) : props;
|
|
116
123
|
const serverData: Record<string, unknown> = {};
|
|
117
124
|
let hasServerData = false;
|
|
118
125
|
for (const [key, entry] of unsuspend.cache) {
|