waku 0.21.2 → 0.21.4
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 +5 -4
- package/dist/cli.js +50 -33
- package/dist/client.d.ts +146 -62
- package/dist/client.js +5 -203
- package/dist/config.d.ts +8 -3
- package/dist/lib/builder/build.js +234 -68
- package/dist/lib/config.d.ts +3 -2
- package/dist/lib/config.js +3 -10
- package/dist/lib/constants.d.ts +3 -0
- package/dist/lib/constants.js +10 -0
- package/dist/lib/hono/ctx.d.ts +2 -0
- package/dist/lib/hono/ctx.js +11 -0
- package/dist/lib/hono/{runner.d.ts → engine.d.ts} +1 -1
- package/dist/lib/hono/{runner.js → engine.js} +7 -8
- package/dist/lib/middleware/context.d.ts +8 -0
- package/dist/lib/middleware/context.js +37 -0
- package/dist/lib/middleware/dev-server-impl.js +23 -12
- package/dist/lib/middleware/fallback.js +2 -1
- package/dist/lib/middleware/handler.d.ts +2 -0
- package/dist/lib/middleware/handler.js +121 -0
- package/dist/lib/middleware/rsc.js +6 -6
- package/dist/lib/middleware/ssr.js +4 -4
- package/dist/lib/middleware/types.d.ts +13 -5
- package/dist/lib/plugins/vite-plugin-deploy-aws-lambda.js +56 -24
- package/dist/lib/plugins/vite-plugin-deploy-cloudflare.d.ts +0 -1
- package/dist/lib/plugins/vite-plugin-deploy-cloudflare.js +73 -25
- package/dist/lib/plugins/vite-plugin-deploy-deno.js +60 -27
- package/dist/lib/plugins/vite-plugin-deploy-netlify.js +36 -25
- package/dist/lib/plugins/vite-plugin-deploy-partykit.js +70 -23
- package/dist/lib/plugins/vite-plugin-deploy-vercel.d.ts +1 -1
- package/dist/lib/plugins/vite-plugin-deploy-vercel.js +44 -29
- package/dist/lib/plugins/vite-plugin-fs-router-typegen.d.ts +8 -0
- package/dist/lib/plugins/vite-plugin-fs-router-typegen.js +188 -0
- package/dist/lib/plugins/vite-plugin-nonjs-resolve.js +7 -8
- package/dist/lib/plugins/vite-plugin-rsc-analyze.js +5 -5
- package/dist/lib/plugins/vite-plugin-rsc-delegate.js +1 -1
- package/dist/lib/plugins/vite-plugin-rsc-entries.js +1 -3
- package/dist/lib/plugins/vite-plugin-rsc-env.d.ts +1 -1
- package/dist/lib/plugins/vite-plugin-rsc-env.js +2 -2
- package/dist/lib/plugins/vite-plugin-rsc-hmr.js +4 -4
- package/dist/lib/plugins/vite-plugin-rsc-index.js +1 -3
- package/dist/lib/plugins/vite-plugin-rsc-managed.d.ts +0 -2
- package/dist/lib/plugins/vite-plugin-rsc-managed.js +1 -3
- package/dist/lib/plugins/vite-plugin-rsc-transform.d.ts +2 -0
- package/dist/lib/plugins/vite-plugin-rsc-transform.js +69 -123
- package/dist/lib/renderers/html-renderer.d.ts +7 -6
- package/dist/lib/renderers/html-renderer.js +6 -5
- package/dist/lib/renderers/html.d.ts +6 -0
- package/dist/lib/renderers/html.js +205 -0
- package/dist/lib/renderers/rsc-renderer.d.ts +10 -10
- package/dist/lib/renderers/rsc-renderer.js +31 -31
- package/dist/lib/renderers/rsc.d.ts +10 -0
- package/dist/lib/renderers/rsc.js +121 -0
- package/dist/lib/renderers/utils.d.ts +5 -5
- package/dist/lib/renderers/utils.js +38 -31
- package/dist/lib/utils/stream.d.ts +1 -0
- package/dist/lib/utils/stream.js +18 -0
- package/dist/middleware/context.d.ts +2 -0
- package/dist/middleware/context.js +2 -0
- package/dist/middleware/handler.d.ts +1 -0
- package/dist/middleware/handler.js +1 -0
- package/dist/minimal/client.d.ts +80 -0
- package/dist/minimal/client.js +214 -0
- package/dist/minimal/server.d.ts +73 -0
- package/dist/minimal/server.js +10 -0
- package/dist/router/base-types.d.ts +8 -0
- package/dist/router/base-types.js +1 -0
- package/dist/router/client.d.ts +24 -4
- package/dist/router/client.js +256 -49
- package/dist/router/common.d.ts +7 -5
- package/dist/router/common.js +26 -9
- package/dist/router/create-pages-utils/inferred-path-types.d.ts +123 -0
- package/dist/router/create-pages-utils/inferred-path-types.js +5 -0
- package/dist/router/create-pages.d.ts +39 -35
- package/dist/router/create-pages.js +38 -4
- package/dist/router/define-router.d.ts +20 -3
- package/dist/router/define-router.js +195 -48
- package/dist/router/fs-router.d.ts +5 -3
- package/dist/router/fs-router.js +11 -3
- package/dist/router/server.d.ts +1 -1
- package/dist/router/server.js +1 -1
- package/dist/router/util-types.d.ts +140 -0
- package/dist/router/util-types.js +13 -0
- package/dist/server.d.ts +18 -54
- package/dist/server.js +18 -31
- package/dist/unstable_hono.d.ts +12 -0
- package/dist/unstable_hono.js +7 -0
- package/dist/unstable_internals.d.ts +19 -0
- package/dist/unstable_internals.js +20 -0
- package/package.json +33 -17
- package/dist/internals.d.ts +0 -2
- package/dist/internals.js +0 -2
- package/dist/lib/builder/serve-aws-lambda.d.ts +0 -1
- package/dist/lib/builder/serve-aws-lambda.js +0 -27
- package/dist/lib/builder/serve-cloudflare.d.ts +0 -15
- package/dist/lib/builder/serve-cloudflare.js +0 -28
- package/dist/lib/builder/serve-deno.d.ts +0 -1
- package/dist/lib/builder/serve-deno.js +0 -28
- package/dist/lib/builder/serve-netlify.d.ts +0 -3
- package/dist/lib/builder/serve-netlify.js +0 -20
- package/dist/lib/builder/serve-partykit.d.ts +0 -6
- package/dist/lib/builder/serve-partykit.js +0 -34
- package/dist/lib/builder/serve-vercel.d.ts +0 -2
- package/dist/lib/builder/serve-vercel.js +0 -27
- package/dist/lib/middleware/headers.d.ts +0 -3
- package/dist/lib/middleware/headers.js +0 -7
- package/dist/middleware/headers.d.ts +0 -1
- package/dist/middleware/headers.js +0 -1
package/README.md
CHANGED
|
@@ -574,7 +574,7 @@ export default async function HomePage() {
|
|
|
574
574
|
return (
|
|
575
575
|
<>
|
|
576
576
|
<title>Waku</title>
|
|
577
|
-
<meta
|
|
577
|
+
<meta name="description" content="The minimal React framework" />
|
|
578
578
|
<h1>Waku</h1>
|
|
579
579
|
<div>Hello world!</div>
|
|
580
580
|
</>
|
|
@@ -607,7 +607,7 @@ const Head = async () => {
|
|
|
607
607
|
return (
|
|
608
608
|
<>
|
|
609
609
|
<title>{metadata.title}</title>
|
|
610
|
-
<meta
|
|
610
|
+
<meta name="description" content={metadata.description} />
|
|
611
611
|
</>
|
|
612
612
|
);
|
|
613
613
|
};
|
|
@@ -1021,7 +1021,7 @@ npx partykit dev # or deploy
|
|
|
1021
1021
|
|
|
1022
1022
|
```
|
|
1023
1023
|
npm run build -- --with-deno
|
|
1024
|
-
|
|
1024
|
+
deployctl deploy --prod dist/serve-deno.js --exclude node_modules
|
|
1025
1025
|
```
|
|
1026
1026
|
|
|
1027
1027
|
### AWS Lambda (experimental)
|
|
@@ -1030,7 +1030,8 @@ DENO_DEPLOY_TOKEN=... deployctl deploy --project=... --prod dist/serve.js --excl
|
|
|
1030
1030
|
npm run build -- --with-aws-lambda
|
|
1031
1031
|
```
|
|
1032
1032
|
|
|
1033
|
-
The handler entrypoint is `dist/serve.js`: see [Hono AWS Lambda Deploy Docs](https://hono.dev/getting-started/aws-lambda#_3-deploy).
|
|
1033
|
+
The handler entrypoint is `dist/serve-asw-lambda.js`: see [Hono AWS Lambda Deploy Docs](https://hono.dev/getting-started/aws-lambda#_3-deploy).
|
|
1034
|
+
Streaming can be activated by setting environment variable `DEPLOY_AWS_LAMBDA_STREAMING=true npm run build -- --with-aws-lambda`
|
|
1034
1035
|
|
|
1035
1036
|
## Community
|
|
1036
1037
|
|
package/dist/cli.js
CHANGED
|
@@ -4,10 +4,11 @@ import { pathToFileURL } from 'node:url';
|
|
|
4
4
|
import { parseArgs } from 'node:util';
|
|
5
5
|
import { createRequire } from 'node:module';
|
|
6
6
|
import { Hono } from 'hono';
|
|
7
|
+
import { compress } from 'hono/compress';
|
|
7
8
|
import { serve } from '@hono/node-server';
|
|
8
9
|
import { serveStatic } from '@hono/node-server/serve-static';
|
|
9
10
|
import * as dotenv from 'dotenv';
|
|
10
|
-
import {
|
|
11
|
+
import { serverEngine } from './lib/hono/engine.js';
|
|
11
12
|
import { build } from './lib/builder/build.js';
|
|
12
13
|
import { DIST_ENTRIES_JS, DIST_PUBLIC } from './lib/builder/constants.js';
|
|
13
14
|
const require = createRequire(new URL('.', import.meta.url));
|
|
@@ -49,6 +50,9 @@ const { values, positionals } = parseArgs({
|
|
|
49
50
|
'experimental-partial': {
|
|
50
51
|
type: 'boolean'
|
|
51
52
|
},
|
|
53
|
+
'experimental-compress': {
|
|
54
|
+
type: 'boolean'
|
|
55
|
+
},
|
|
52
56
|
port: {
|
|
53
57
|
type: 'string',
|
|
54
58
|
short: 'p'
|
|
@@ -90,22 +94,28 @@ if (values.version) {
|
|
|
90
94
|
}
|
|
91
95
|
async function runDev() {
|
|
92
96
|
const config = await loadConfig();
|
|
93
|
-
const
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
env: process.env
|
|
98
|
-
}));
|
|
99
|
-
app.notFound((c)=>{
|
|
100
|
-
// FIXME can we avoid hardcoding the public path?
|
|
101
|
-
const file = path.join('public', '404.html');
|
|
102
|
-
if (existsSync(file)) {
|
|
103
|
-
return c.html(readFileSync(file, 'utf8'), 404);
|
|
97
|
+
const honoEnhancer = config.unstable_honoEnhancer || ((createApp)=>createApp);
|
|
98
|
+
const createApp = (app)=>{
|
|
99
|
+
if (values['experimental-compress']) {
|
|
100
|
+
app.use(compress());
|
|
104
101
|
}
|
|
105
|
-
|
|
106
|
-
|
|
102
|
+
app.use(serverEngine({
|
|
103
|
+
cmd: 'dev',
|
|
104
|
+
config,
|
|
105
|
+
env: process.env
|
|
106
|
+
}));
|
|
107
|
+
app.notFound((c)=>{
|
|
108
|
+
// FIXME can we avoid hardcoding the public path?
|
|
109
|
+
const file = path.join('public', '404.html');
|
|
110
|
+
if (existsSync(file)) {
|
|
111
|
+
return c.html(readFileSync(file, 'utf8'), 404);
|
|
112
|
+
}
|
|
113
|
+
return c.text('404 Not Found', 404);
|
|
114
|
+
});
|
|
115
|
+
return app;
|
|
116
|
+
};
|
|
107
117
|
const port = parseInt(values.port || '3000', 10);
|
|
108
|
-
await startServer(
|
|
118
|
+
await startServer(honoEnhancer(createApp)(new Hono()), port);
|
|
109
119
|
}
|
|
110
120
|
async function runBuild() {
|
|
111
121
|
const config = await loadConfig();
|
|
@@ -118,27 +128,34 @@ async function runBuild() {
|
|
|
118
128
|
});
|
|
119
129
|
}
|
|
120
130
|
async function runStart() {
|
|
121
|
-
const
|
|
131
|
+
const config = await loadConfig();
|
|
132
|
+
const { distDir = 'dist' } = config;
|
|
133
|
+
const honoEnhancer = config.unstable_honoEnhancer || ((createApp)=>createApp);
|
|
122
134
|
const loadEntries = ()=>import(pathToFileURL(path.resolve(distDir, DIST_ENTRIES_JS)).toString());
|
|
123
|
-
const
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
}));
|
|
127
|
-
app.use('*', runner({
|
|
128
|
-
cmd: 'start',
|
|
129
|
-
loadEntries,
|
|
130
|
-
env: process.env
|
|
131
|
-
}));
|
|
132
|
-
app.notFound((c)=>{
|
|
133
|
-
// FIXME better implementation using node stream?
|
|
134
|
-
const file = path.join(distDir, DIST_PUBLIC, '404.html');
|
|
135
|
-
if (existsSync(file)) {
|
|
136
|
-
return c.html(readFileSync(file, 'utf8'), 404);
|
|
135
|
+
const createApp = (app)=>{
|
|
136
|
+
if (values['experimental-compress']) {
|
|
137
|
+
app.use(compress());
|
|
137
138
|
}
|
|
138
|
-
|
|
139
|
-
|
|
139
|
+
app.use(serveStatic({
|
|
140
|
+
root: path.join(distDir, DIST_PUBLIC)
|
|
141
|
+
}));
|
|
142
|
+
app.use(serverEngine({
|
|
143
|
+
cmd: 'start',
|
|
144
|
+
loadEntries,
|
|
145
|
+
env: process.env
|
|
146
|
+
}));
|
|
147
|
+
app.notFound((c)=>{
|
|
148
|
+
// FIXME better implementation using node stream?
|
|
149
|
+
const file = path.join(distDir, DIST_PUBLIC, '404.html');
|
|
150
|
+
if (existsSync(file)) {
|
|
151
|
+
return c.html(readFileSync(file, 'utf8'), 404);
|
|
152
|
+
}
|
|
153
|
+
return c.text('404 Not Found', 404);
|
|
154
|
+
});
|
|
155
|
+
return app;
|
|
156
|
+
};
|
|
140
157
|
const port = parseInt(values.port || '8080', 10);
|
|
141
|
-
await startServer(
|
|
158
|
+
await startServer(honoEnhancer(createApp)(new Hono()), port);
|
|
142
159
|
}
|
|
143
160
|
function startServer(app, port) {
|
|
144
161
|
return new Promise((resolve, reject)=>{
|
package/dist/client.d.ts
CHANGED
|
@@ -1,66 +1,150 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
interface ImportMeta {
|
|
5
|
-
readonly env: Record<string, string>;
|
|
6
|
-
}
|
|
7
|
-
}
|
|
8
|
-
type Elements = Promise<Record<string, ReactNode>> & {
|
|
9
|
-
prev?: Record<string, ReactNode> | undefined;
|
|
10
|
-
};
|
|
11
|
-
type SetElements = (updater: (prev: Elements) => Elements) => void;
|
|
12
|
-
type OnFetchData = (data: unknown) => void;
|
|
13
|
-
declare const ENTRY = "e";
|
|
14
|
-
declare const SET_ELEMENTS = "s";
|
|
15
|
-
declare const ON_FETCH_DATA = "o";
|
|
16
|
-
type FetchCache = {
|
|
17
|
-
[ENTRY]?: [input: string, params: unknown, elements: Elements];
|
|
18
|
-
[SET_ELEMENTS]?: SetElements;
|
|
19
|
-
[ON_FETCH_DATA]?: OnFetchData | undefined;
|
|
20
|
-
};
|
|
21
|
-
/**
|
|
22
|
-
* callServer callback
|
|
23
|
-
* This is not a public API.
|
|
24
|
-
*/
|
|
25
|
-
export declare const callServerRSC: (actionId: string, args?: unknown[], fetchCache?: FetchCache) => Promise<bigint | import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>> | Iterable<ReactNode> | import("react").AwaitedReactNode>;
|
|
26
|
-
export declare const fetchRSC: (input: string, params?: unknown, fetchCache?: FetchCache) => Elements;
|
|
27
|
-
export declare const prefetchRSC: (input: string, params?: unknown) => void;
|
|
28
|
-
export declare const Root: ({ initialInput, initialParams, fetchCache, unstable_onFetchData, children, }: {
|
|
29
|
-
initialInput?: string;
|
|
30
|
-
initialParams?: unknown;
|
|
31
|
-
fetchCache?: FetchCache;
|
|
32
|
-
unstable_onFetchData?: (data: unknown) => void;
|
|
33
|
-
children: ReactNode;
|
|
34
|
-
}) => import("react").FunctionComponentElement<import("react").ProviderProps<(input: string, params?: unknown) => void>>;
|
|
35
|
-
export declare const useRefetch: () => (input: string, params?: unknown) => void;
|
|
36
|
-
type OuterSlotProps = {
|
|
37
|
-
elementsPromise: Elements;
|
|
38
|
-
shouldRenderPrev: ((err: unknown) => boolean) | undefined;
|
|
39
|
-
renderSlot: (elements: Record<string, ReactNode>) => ReactNode;
|
|
40
|
-
children?: ReactNode;
|
|
41
|
-
};
|
|
42
|
-
declare class OuterSlot extends Component<OuterSlotProps, {
|
|
43
|
-
error?: unknown;
|
|
44
|
-
}> {
|
|
45
|
-
constructor(props: OuterSlotProps);
|
|
46
|
-
static getDerivedStateFromError(error: unknown): {
|
|
47
|
-
error: unknown;
|
|
48
|
-
};
|
|
49
|
-
render(): ReactNode;
|
|
50
|
-
}
|
|
1
|
+
/** @deprecated */
|
|
2
|
+
export declare const Children: () => import("react").ReactNode;
|
|
3
|
+
/** @deprecated */
|
|
51
4
|
export declare const Slot: ({ id, children, fallback, unstable_shouldRenderPrev, }: {
|
|
52
5
|
id: string;
|
|
53
|
-
children?: ReactNode;
|
|
54
|
-
fallback?: ReactNode;
|
|
6
|
+
children?: import("react").ReactNode;
|
|
7
|
+
fallback?: import("react").ReactNode;
|
|
55
8
|
unstable_shouldRenderPrev?: (err: unknown) => boolean;
|
|
56
|
-
}) => import("react").CElement<
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
9
|
+
}) => import("react").CElement<{
|
|
10
|
+
elementsPromise: Promise<Record<string, import("react").ReactNode>> & {
|
|
11
|
+
prev?: Record<string, import("react").ReactNode> | undefined;
|
|
12
|
+
};
|
|
13
|
+
shouldRenderPrev: ((err: unknown) => boolean) | undefined;
|
|
14
|
+
renderSlot: (elements: Record<string, import("react").ReactNode>) => import("react").ReactNode;
|
|
15
|
+
children?: import("react").ReactNode;
|
|
16
|
+
}, {
|
|
17
|
+
render(): import("react").ReactNode;
|
|
18
|
+
context: unknown;
|
|
19
|
+
setState<K extends "error">(state: {
|
|
20
|
+
error?: unknown;
|
|
21
|
+
} | ((prevState: Readonly<{
|
|
22
|
+
error?: unknown;
|
|
23
|
+
}>, props: Readonly<{
|
|
24
|
+
elementsPromise: Promise<Record<string, import("react").ReactNode>> & {
|
|
25
|
+
prev?: Record<string, import("react").ReactNode> | undefined;
|
|
26
|
+
};
|
|
27
|
+
shouldRenderPrev: ((err: unknown) => boolean) | undefined;
|
|
28
|
+
renderSlot: (elements: Record<string, import("react").ReactNode>) => import("react").ReactNode;
|
|
29
|
+
children?: import("react").ReactNode;
|
|
30
|
+
}>) => {
|
|
31
|
+
error?: unknown;
|
|
32
|
+
} | Pick<{
|
|
33
|
+
error?: unknown;
|
|
34
|
+
}, K> | null) | Pick<{
|
|
35
|
+
error?: unknown;
|
|
36
|
+
}, K> | null, callback?: (() => void) | undefined): void;
|
|
37
|
+
forceUpdate(callback?: (() => void) | undefined): void;
|
|
38
|
+
readonly props: Readonly<{
|
|
39
|
+
elementsPromise: Promise<Record<string, import("react").ReactNode>> & {
|
|
40
|
+
prev?: Record<string, import("react").ReactNode> | undefined;
|
|
41
|
+
};
|
|
42
|
+
shouldRenderPrev: ((err: unknown) => boolean) | undefined;
|
|
43
|
+
renderSlot: (elements: Record<string, import("react").ReactNode>) => import("react").ReactNode;
|
|
44
|
+
children?: import("react").ReactNode;
|
|
45
|
+
}>;
|
|
46
|
+
state: Readonly<{
|
|
47
|
+
error?: unknown;
|
|
48
|
+
}>;
|
|
49
|
+
refs: {
|
|
50
|
+
[key: string]: import("react").ReactInstance;
|
|
51
|
+
};
|
|
52
|
+
componentDidMount?(): void;
|
|
53
|
+
shouldComponentUpdate?(nextProps: Readonly<{
|
|
54
|
+
elementsPromise: Promise<Record<string, import("react").ReactNode>> & {
|
|
55
|
+
prev?: Record<string, import("react").ReactNode> | undefined;
|
|
56
|
+
};
|
|
57
|
+
shouldRenderPrev: ((err: unknown) => boolean) | undefined;
|
|
58
|
+
renderSlot: (elements: Record<string, import("react").ReactNode>) => import("react").ReactNode;
|
|
59
|
+
children?: import("react").ReactNode;
|
|
60
|
+
}>, nextState: Readonly<{
|
|
61
|
+
error?: unknown;
|
|
62
|
+
}>, nextContext: any): boolean;
|
|
63
|
+
componentWillUnmount?(): void;
|
|
64
|
+
componentDidCatch?(error: Error, errorInfo: import("react").ErrorInfo): void;
|
|
65
|
+
getSnapshotBeforeUpdate?(prevProps: Readonly<{
|
|
66
|
+
elementsPromise: Promise<Record<string, import("react").ReactNode>> & {
|
|
67
|
+
prev?: Record<string, import("react").ReactNode> | undefined;
|
|
68
|
+
};
|
|
69
|
+
shouldRenderPrev: ((err: unknown) => boolean) | undefined;
|
|
70
|
+
renderSlot: (elements: Record<string, import("react").ReactNode>) => import("react").ReactNode;
|
|
71
|
+
children?: import("react").ReactNode;
|
|
72
|
+
}>, prevState: Readonly<{
|
|
73
|
+
error?: unknown;
|
|
74
|
+
}>): any;
|
|
75
|
+
componentDidUpdate?(prevProps: Readonly<{
|
|
76
|
+
elementsPromise: Promise<Record<string, import("react").ReactNode>> & {
|
|
77
|
+
prev?: Record<string, import("react").ReactNode> | undefined;
|
|
78
|
+
};
|
|
79
|
+
shouldRenderPrev: ((err: unknown) => boolean) | undefined;
|
|
80
|
+
renderSlot: (elements: Record<string, import("react").ReactNode>) => import("react").ReactNode;
|
|
81
|
+
children?: import("react").ReactNode;
|
|
82
|
+
}>, prevState: Readonly<{
|
|
83
|
+
error?: unknown;
|
|
84
|
+
}>, snapshot?: any): void;
|
|
85
|
+
componentWillMount?(): void;
|
|
86
|
+
UNSAFE_componentWillMount?(): void;
|
|
87
|
+
componentWillReceiveProps?(nextProps: Readonly<{
|
|
88
|
+
elementsPromise: Promise<Record<string, import("react").ReactNode>> & {
|
|
89
|
+
prev?: Record<string, import("react").ReactNode> | undefined;
|
|
90
|
+
};
|
|
91
|
+
shouldRenderPrev: ((err: unknown) => boolean) | undefined;
|
|
92
|
+
renderSlot: (elements: Record<string, import("react").ReactNode>) => import("react").ReactNode;
|
|
93
|
+
children?: import("react").ReactNode;
|
|
94
|
+
}>, nextContext: any): void;
|
|
95
|
+
UNSAFE_componentWillReceiveProps?(nextProps: Readonly<{
|
|
96
|
+
elementsPromise: Promise<Record<string, import("react").ReactNode>> & {
|
|
97
|
+
prev?: Record<string, import("react").ReactNode> | undefined;
|
|
98
|
+
};
|
|
99
|
+
shouldRenderPrev: ((err: unknown) => boolean) | undefined;
|
|
100
|
+
renderSlot: (elements: Record<string, import("react").ReactNode>) => import("react").ReactNode;
|
|
101
|
+
children?: import("react").ReactNode;
|
|
102
|
+
}>, nextContext: any): void;
|
|
103
|
+
componentWillUpdate?(nextProps: Readonly<{
|
|
104
|
+
elementsPromise: Promise<Record<string, import("react").ReactNode>> & {
|
|
105
|
+
prev?: Record<string, import("react").ReactNode> | undefined;
|
|
106
|
+
};
|
|
107
|
+
shouldRenderPrev: ((err: unknown) => boolean) | undefined;
|
|
108
|
+
renderSlot: (elements: Record<string, import("react").ReactNode>) => import("react").ReactNode;
|
|
109
|
+
children?: import("react").ReactNode;
|
|
110
|
+
}>, nextState: Readonly<{
|
|
111
|
+
error?: unknown;
|
|
112
|
+
}>, nextContext: any): void;
|
|
113
|
+
UNSAFE_componentWillUpdate?(nextProps: Readonly<{
|
|
114
|
+
elementsPromise: Promise<Record<string, import("react").ReactNode>> & {
|
|
115
|
+
prev?: Record<string, import("react").ReactNode> | undefined;
|
|
116
|
+
};
|
|
117
|
+
shouldRenderPrev: ((err: unknown) => boolean) | undefined;
|
|
118
|
+
renderSlot: (elements: Record<string, import("react").ReactNode>) => import("react").ReactNode;
|
|
119
|
+
children?: import("react").ReactNode;
|
|
120
|
+
}>, nextState: Readonly<{
|
|
121
|
+
error?: unknown;
|
|
122
|
+
}>, nextContext: any): void;
|
|
123
|
+
}>;
|
|
124
|
+
/** @deprecated */
|
|
125
|
+
export declare const Root: ({ initialRscPath, initialRscParams, fetchCache, unstable_enhanceCreateData, children, }: {
|
|
126
|
+
initialRscPath?: string;
|
|
127
|
+
initialRscParams?: unknown;
|
|
128
|
+
fetchCache?: {
|
|
129
|
+
e?: [rscPath: string, rscParams: unknown, elements: Promise<Record<string, import("react").ReactNode>> & {
|
|
130
|
+
prev?: Record<string, import("react").ReactNode> | undefined;
|
|
131
|
+
}];
|
|
132
|
+
s?: (updater: (prev: Promise<Record<string, import("react").ReactNode>> & {
|
|
133
|
+
prev?: Record<string, import("react").ReactNode> | undefined;
|
|
134
|
+
}) => Promise<Record<string, import("react").ReactNode>> & {
|
|
135
|
+
prev?: Record<string, import("react").ReactNode> | undefined;
|
|
136
|
+
}) => void;
|
|
137
|
+
d?: ((createData: (responsePromise: Promise<Response>) => Promise<Record<string, import("react").ReactNode>>) => (responsePromise: Promise<Response>) => Promise<Record<string, import("react").ReactNode>>) | undefined;
|
|
138
|
+
};
|
|
139
|
+
unstable_enhanceCreateData?: (createData: (responsePromise: Promise<Response>) => Promise<Record<string, import("react").ReactNode>>) => (responsePromise: Promise<Response>) => Promise<Record<string, import("react").ReactNode>>;
|
|
140
|
+
children: import("react").ReactNode;
|
|
141
|
+
}) => import("react").FunctionComponentElement<import("react").ProviderProps<(rscPath: string, rscParams?: unknown) => void>>;
|
|
142
|
+
/** @deprecated */
|
|
62
143
|
export declare const ServerRoot: ({ elements, children, }: {
|
|
63
|
-
elements:
|
|
64
|
-
|
|
65
|
-
}
|
|
66
|
-
|
|
144
|
+
elements: Promise<Record<string, import("react").ReactNode>> & {
|
|
145
|
+
prev?: Record<string, import("react").ReactNode> | undefined;
|
|
146
|
+
};
|
|
147
|
+
children: import("react").ReactNode;
|
|
148
|
+
}) => import("react").FunctionComponentElement<import("react").ProviderProps<(Promise<Record<string, import("react").ReactNode>> & {
|
|
149
|
+
prev?: Record<string, import("react").ReactNode> | undefined;
|
|
150
|
+
}) | null>>;
|
package/dist/client.js
CHANGED
|
@@ -1,203 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const { createFromFetch, encodeReply } = RSDWClient;
|
|
7
|
-
const BASE_PATH = `${import.meta.env?.WAKU_CONFIG_BASE_PATH}${import.meta.env?.WAKU_CONFIG_RSC_PATH}/`;
|
|
8
|
-
const checkStatus = async (responsePromise)=>{
|
|
9
|
-
const response = await responsePromise;
|
|
10
|
-
if (!response.ok) {
|
|
11
|
-
const err = new Error(response.statusText);
|
|
12
|
-
err.statusCode = response.status;
|
|
13
|
-
throw err;
|
|
14
|
-
}
|
|
15
|
-
return response;
|
|
16
|
-
};
|
|
17
|
-
const getCached = (c, m, k)=>(m.has(k) ? m : m.set(k, c())).get(k);
|
|
18
|
-
const cache1 = new WeakMap();
|
|
19
|
-
const mergeElements = (a, b)=>{
|
|
20
|
-
const getResult = ()=>{
|
|
21
|
-
const promise = new Promise((resolve, reject)=>{
|
|
22
|
-
Promise.all([
|
|
23
|
-
a,
|
|
24
|
-
b
|
|
25
|
-
]).then(([a, b])=>{
|
|
26
|
-
const nextElements = {
|
|
27
|
-
...a,
|
|
28
|
-
...b
|
|
29
|
-
};
|
|
30
|
-
delete nextElements._value;
|
|
31
|
-
promise.prev = a;
|
|
32
|
-
resolve(nextElements);
|
|
33
|
-
}).catch((e)=>{
|
|
34
|
-
a.then((a)=>{
|
|
35
|
-
promise.prev = a;
|
|
36
|
-
reject(e);
|
|
37
|
-
}, ()=>{
|
|
38
|
-
promise.prev = a.prev;
|
|
39
|
-
reject(e);
|
|
40
|
-
});
|
|
41
|
-
});
|
|
42
|
-
});
|
|
43
|
-
return promise;
|
|
44
|
-
};
|
|
45
|
-
const cache2 = getCached(()=>new WeakMap(), cache1, a);
|
|
46
|
-
return getCached(getResult, cache2, b);
|
|
47
|
-
};
|
|
48
|
-
const ENTRY = 'e';
|
|
49
|
-
const SET_ELEMENTS = 's';
|
|
50
|
-
const ON_FETCH_DATA = 'o';
|
|
51
|
-
const defaultFetchCache = {};
|
|
52
|
-
/**
|
|
53
|
-
* callServer callback
|
|
54
|
-
* This is not a public API.
|
|
55
|
-
*/ export const callServerRSC = async (actionId, args, fetchCache = defaultFetchCache)=>{
|
|
56
|
-
const url = BASE_PATH + encodeInput(encodeActionId(actionId));
|
|
57
|
-
const response = args === undefined ? fetch(url) : encodeReply(args).then((body)=>fetch(url, {
|
|
58
|
-
method: 'POST',
|
|
59
|
-
body
|
|
60
|
-
}));
|
|
61
|
-
const data = createFromFetch(checkStatus(response), {
|
|
62
|
-
callServer: (actionId, args)=>callServerRSC(actionId, args, fetchCache)
|
|
63
|
-
});
|
|
64
|
-
fetchCache[ON_FETCH_DATA]?.(data);
|
|
65
|
-
// FIXME this causes rerenders even if data is empty
|
|
66
|
-
fetchCache[SET_ELEMENTS]?.((prev)=>mergeElements(prev, data));
|
|
67
|
-
return (await data)._value;
|
|
68
|
-
};
|
|
69
|
-
const prefetchedParams = new WeakMap();
|
|
70
|
-
const fetchRSCInternal = (url, params)=>params === undefined ? fetch(url) : typeof params === 'string' ? fetch(url, {
|
|
71
|
-
headers: {
|
|
72
|
-
'X-Waku-Params': params
|
|
73
|
-
}
|
|
74
|
-
}) : encodeReply(params).then((body)=>fetch(url, {
|
|
75
|
-
method: 'POST',
|
|
76
|
-
body
|
|
77
|
-
}));
|
|
78
|
-
export const fetchRSC = (input, params, fetchCache = defaultFetchCache)=>{
|
|
79
|
-
const entry = fetchCache[ENTRY];
|
|
80
|
-
if (entry && entry[0] === input && entry[1] === params) {
|
|
81
|
-
return entry[2];
|
|
82
|
-
}
|
|
83
|
-
const prefetched = globalThis.__WAKU_PREFETCHED__ ||= {};
|
|
84
|
-
const url = BASE_PATH + encodeInput(input);
|
|
85
|
-
const hasValidPrefetchedResponse = !!prefetched[url] && // HACK .has() is for the initial hydration
|
|
86
|
-
// It's limited and may result in a wrong result. FIXME
|
|
87
|
-
(!prefetchedParams.has(prefetched[url]) || prefetchedParams.get(prefetched[url]) === params);
|
|
88
|
-
const response = hasValidPrefetchedResponse ? prefetched[url] : fetchRSCInternal(url, params);
|
|
89
|
-
delete prefetched[url];
|
|
90
|
-
const data = createFromFetch(checkStatus(response), {
|
|
91
|
-
callServer: (actionId, args)=>callServerRSC(actionId, args, fetchCache)
|
|
92
|
-
});
|
|
93
|
-
fetchCache[ON_FETCH_DATA]?.(data);
|
|
94
|
-
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
95
|
-
fetchCache[ENTRY] = [
|
|
96
|
-
input,
|
|
97
|
-
params,
|
|
98
|
-
data
|
|
99
|
-
];
|
|
100
|
-
return data;
|
|
101
|
-
};
|
|
102
|
-
export const prefetchRSC = (input, params)=>{
|
|
103
|
-
const prefetched = globalThis.__WAKU_PREFETCHED__ ||= {};
|
|
104
|
-
const url = BASE_PATH + encodeInput(input);
|
|
105
|
-
if (!(url in prefetched)) {
|
|
106
|
-
prefetched[url] = fetchRSCInternal(url, params);
|
|
107
|
-
prefetchedParams.set(prefetched[url], params);
|
|
108
|
-
}
|
|
109
|
-
};
|
|
110
|
-
const RefetchContext = createContext(()=>{
|
|
111
|
-
throw new Error('Missing Root component');
|
|
112
|
-
});
|
|
113
|
-
const ElementsContext = createContext(null);
|
|
114
|
-
export const Root = ({ initialInput, initialParams, fetchCache = defaultFetchCache, unstable_onFetchData, children })=>{
|
|
115
|
-
fetchCache[ON_FETCH_DATA] = unstable_onFetchData;
|
|
116
|
-
const [elements, setElements] = useState(()=>fetchRSC(initialInput || '', initialParams, fetchCache));
|
|
117
|
-
useEffect(()=>{
|
|
118
|
-
fetchCache[SET_ELEMENTS] = setElements;
|
|
119
|
-
}, [
|
|
120
|
-
fetchCache,
|
|
121
|
-
setElements
|
|
122
|
-
]);
|
|
123
|
-
const refetch = useCallback((input, params)=>{
|
|
124
|
-
// clear cache entry before fetching
|
|
125
|
-
delete fetchCache[ENTRY];
|
|
126
|
-
const data = fetchRSC(input, params, fetchCache);
|
|
127
|
-
setElements((prev)=>mergeElements(prev, data));
|
|
128
|
-
}, [
|
|
129
|
-
fetchCache
|
|
130
|
-
]);
|
|
131
|
-
return createElement(RefetchContext.Provider, {
|
|
132
|
-
value: refetch
|
|
133
|
-
}, createElement(ElementsContext.Provider, {
|
|
134
|
-
value: elements
|
|
135
|
-
}, children));
|
|
136
|
-
};
|
|
137
|
-
export const useRefetch = ()=>use(RefetchContext);
|
|
138
|
-
const ChildrenContext = createContext(undefined);
|
|
139
|
-
const ChildrenContextProvider = memo(ChildrenContext.Provider);
|
|
140
|
-
class OuterSlot extends Component {
|
|
141
|
-
constructor(props){
|
|
142
|
-
super(props);
|
|
143
|
-
this.state = {};
|
|
144
|
-
}
|
|
145
|
-
static getDerivedStateFromError(error) {
|
|
146
|
-
return {
|
|
147
|
-
error
|
|
148
|
-
};
|
|
149
|
-
}
|
|
150
|
-
render() {
|
|
151
|
-
if ('error' in this.state) {
|
|
152
|
-
const e = this.state.error;
|
|
153
|
-
if (e instanceof Error && !('statusCode' in e)) {
|
|
154
|
-
// HACK we assume any error as Not Found,
|
|
155
|
-
// probably caused by history api fallback
|
|
156
|
-
e.statusCode = 404;
|
|
157
|
-
}
|
|
158
|
-
if (this.props.shouldRenderPrev?.(e) && this.props.elementsPromise.prev) {
|
|
159
|
-
const elements = this.props.elementsPromise.prev;
|
|
160
|
-
return this.props.renderSlot(elements);
|
|
161
|
-
} else {
|
|
162
|
-
throw e;
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
return this.props.children;
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
const InnerSlot = ({ elementsPromise, renderSlot })=>{
|
|
169
|
-
const elements = use(elementsPromise);
|
|
170
|
-
return renderSlot(elements);
|
|
171
|
-
};
|
|
172
|
-
export const Slot = ({ id, children, fallback, unstable_shouldRenderPrev })=>{
|
|
173
|
-
const elementsPromise = use(ElementsContext);
|
|
174
|
-
if (!elementsPromise) {
|
|
175
|
-
throw new Error('Missing Root component');
|
|
176
|
-
}
|
|
177
|
-
const renderSlot = (elements)=>{
|
|
178
|
-
if (!(id in elements)) {
|
|
179
|
-
if (fallback) {
|
|
180
|
-
return fallback;
|
|
181
|
-
}
|
|
182
|
-
throw new Error('Not found: ' + id);
|
|
183
|
-
}
|
|
184
|
-
return createElement(ChildrenContextProvider, {
|
|
185
|
-
value: children
|
|
186
|
-
}, elements[id]);
|
|
187
|
-
};
|
|
188
|
-
return createElement(OuterSlot, {
|
|
189
|
-
elementsPromise,
|
|
190
|
-
shouldRenderPrev: unstable_shouldRenderPrev,
|
|
191
|
-
renderSlot
|
|
192
|
-
}, createElement(InnerSlot, {
|
|
193
|
-
elementsPromise,
|
|
194
|
-
renderSlot
|
|
195
|
-
}));
|
|
196
|
-
};
|
|
197
|
-
export const Children = ()=>use(ChildrenContext);
|
|
198
|
-
/**
|
|
199
|
-
* ServerRoot for SSR
|
|
200
|
-
* This is not a public API.
|
|
201
|
-
*/ export const ServerRoot = ({ elements, children })=>createElement(ElementsContext.Provider, {
|
|
202
|
-
value: elements
|
|
203
|
-
}, children);
|
|
1
|
+
import { Children as ChildrenOrig, Slot as SlotOrig, Root as RootOrig, ServerRootInternal as ServerRootOrig } from './minimal/client.js';
|
|
2
|
+
/** @deprecated */ export const Children = ChildrenOrig;
|
|
3
|
+
/** @deprecated */ export const Slot = SlotOrig;
|
|
4
|
+
/** @deprecated */ export const Root = RootOrig;
|
|
5
|
+
/** @deprecated */ export const ServerRoot = ServerRootOrig;
|
package/dist/config.d.ts
CHANGED
|
@@ -31,16 +31,16 @@ export interface Config {
|
|
|
31
31
|
*/
|
|
32
32
|
privateDir?: string;
|
|
33
33
|
/**
|
|
34
|
-
*
|
|
34
|
+
* Bse path for HTTP requests to indicate RSC requests.
|
|
35
35
|
* Defaults to "RSC".
|
|
36
36
|
*/
|
|
37
|
-
|
|
37
|
+
rscBase?: string;
|
|
38
38
|
/**
|
|
39
39
|
* Middleware to use
|
|
40
40
|
* Defaults to:
|
|
41
41
|
* () => [
|
|
42
|
+
* import('waku/middleware/context'),
|
|
42
43
|
* import('waku/middleware/dev-server'),
|
|
43
|
-
* import('waku/middleware/headers'),
|
|
44
44
|
* import('waku/middleware/rsc'),
|
|
45
45
|
* import('waku/middleware/ssr'),
|
|
46
46
|
* ]
|
|
@@ -48,5 +48,10 @@ export interface Config {
|
|
|
48
48
|
middleware?: () => Promise<{
|
|
49
49
|
default: Middleware;
|
|
50
50
|
}>[];
|
|
51
|
+
/**
|
|
52
|
+
* Enhancer for Hono
|
|
53
|
+
* Defaults to `undefined`
|
|
54
|
+
*/
|
|
55
|
+
unstable_honoEnhancer?: (<Hono>(createApp: (app: Hono) => Hono) => (app: Hono) => Hono) | undefined;
|
|
51
56
|
}
|
|
52
57
|
export declare function defineConfig(config: Config): Config;
|