@rsc-kit/core 0.1.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 +95 -0
- package/SECURITY.md +60 -0
- package/dist/action.d.ts +90 -0
- package/dist/action.d.ts.map +1 -0
- package/dist/action.js +137 -0
- package/dist/action.js.map +1 -0
- package/dist/build-rsc-vite.d.ts +39 -0
- package/dist/build-rsc-vite.d.ts.map +1 -0
- package/dist/build-rsc-vite.js +172 -0
- package/dist/build-rsc-vite.js.map +1 -0
- package/dist/cache.d.ts +25 -0
- package/dist/cache.d.ts.map +1 -0
- package/dist/cache.js +108 -0
- package/dist/cache.js.map +1 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +85 -0
- package/dist/cli.js.map +1 -0
- package/dist/compile.d.ts +55 -0
- package/dist/compile.d.ts.map +1 -0
- package/dist/compile.js +141 -0
- package/dist/compile.js.map +1 -0
- package/dist/devServer.d.ts +18 -0
- package/dist/devServer.d.ts.map +1 -0
- package/dist/devServer.js +70 -0
- package/dist/devServer.js.map +1 -0
- package/dist/devUrls.d.ts +11 -0
- package/dist/devUrls.d.ts.map +1 -0
- package/dist/devUrls.js +68 -0
- package/dist/devUrls.js.map +1 -0
- package/dist/embed.d.ts +21 -0
- package/dist/embed.d.ts.map +1 -0
- package/dist/embed.js +119 -0
- package/dist/embed.js.map +1 -0
- package/dist/errors.d.ts +24 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +38 -0
- package/dist/errors.js.map +1 -0
- package/dist/export.d.ts +41 -0
- package/dist/export.d.ts.map +1 -0
- package/dist/export.js +100 -0
- package/dist/export.js.map +1 -0
- package/dist/files.d.ts +39 -0
- package/dist/files.d.ts.map +1 -0
- package/dist/files.js +146 -0
- package/dist/files.js.map +1 -0
- package/dist/headers.d.ts +81 -0
- package/dist/headers.d.ts.map +1 -0
- package/dist/headers.js +96 -0
- package/dist/headers.js.map +1 -0
- package/dist/host.d.ts +86 -0
- package/dist/host.d.ts.map +1 -0
- package/dist/host.js +590 -0
- package/dist/host.js.map +1 -0
- package/dist/js/ActivityRouter.d.ts +47 -0
- package/dist/js/ActivityRouter.d.ts.map +1 -0
- package/dist/js/ActivityRouter.js +87 -0
- package/dist/js/ActivityRouter.js.map +1 -0
- package/dist/js/DocumentTitle.d.ts +22 -0
- package/dist/js/DocumentTitle.d.ts.map +1 -0
- package/dist/js/DocumentTitle.js +28 -0
- package/dist/js/DocumentTitle.js.map +1 -0
- package/dist/js/Form.d.ts +54 -0
- package/dist/js/Form.d.ts.map +1 -0
- package/dist/js/Form.js +225 -0
- package/dist/js/Form.js.map +1 -0
- package/dist/js/Link.d.ts +29 -0
- package/dist/js/Link.d.ts.map +1 -0
- package/dist/js/Link.js +112 -0
- package/dist/js/Link.js.map +1 -0
- package/dist/js/PathnameProvider.d.ts +8 -0
- package/dist/js/PathnameProvider.d.ts.map +1 -0
- package/dist/js/PathnameProvider.js +24 -0
- package/dist/js/PathnameProvider.js.map +1 -0
- package/dist/js/RedirectBoundary.d.ts +18 -0
- package/dist/js/RedirectBoundary.d.ts.map +1 -0
- package/dist/js/RedirectBoundary.js +34 -0
- package/dist/js/RedirectBoundary.js.map +1 -0
- package/dist/js/SegmentBoundary.d.ts +8 -0
- package/dist/js/SegmentBoundary.d.ts.map +1 -0
- package/dist/js/SegmentBoundary.js +38 -0
- package/dist/js/SegmentBoundary.js.map +1 -0
- package/dist/js/SlotBoundary.d.ts +15 -0
- package/dist/js/SlotBoundary.d.ts.map +1 -0
- package/dist/js/SlotBoundary.js +17 -0
- package/dist/js/SlotBoundary.js.map +1 -0
- package/dist/js/createViteRscApp.d.ts +8 -0
- package/dist/js/createViteRscApp.d.ts.map +1 -0
- package/dist/js/createViteRscApp.js +185 -0
- package/dist/js/createViteRscApp.js.map +1 -0
- package/dist/js/errors.d.ts +51 -0
- package/dist/js/errors.d.ts.map +1 -0
- package/dist/js/errors.js +93 -0
- package/dist/js/errors.js.map +1 -0
- package/dist/js/navigate.d.ts +118 -0
- package/dist/js/navigate.d.ts.map +1 -0
- package/dist/js/navigate.js +780 -0
- package/dist/js/navigate.js.map +1 -0
- package/dist/js/onlineStore.d.ts +23 -0
- package/dist/js/onlineStore.d.ts.map +1 -0
- package/dist/js/onlineStore.js +42 -0
- package/dist/js/onlineStore.js.map +1 -0
- package/dist/js/pagePayload.d.ts +15 -0
- package/dist/js/pagePayload.d.ts.map +1 -0
- package/dist/js/pagePayload.js +39 -0
- package/dist/js/pagePayload.js.map +1 -0
- package/dist/js/router.d.ts +29 -0
- package/dist/js/router.d.ts.map +1 -0
- package/dist/js/router.js +40 -0
- package/dist/js/router.js.map +1 -0
- package/dist/js/section.d.ts +16 -0
- package/dist/js/section.d.ts.map +1 -0
- package/dist/js/section.js +55 -0
- package/dist/js/section.js.map +1 -0
- package/dist/js/segmentStore.d.ts +69 -0
- package/dist/js/segmentStore.d.ts.map +1 -0
- package/dist/js/segmentStore.js +127 -0
- package/dist/js/segmentStore.js.map +1 -0
- package/dist/js/slotStore.d.ts +35 -0
- package/dist/js/slotStore.d.ts.map +1 -0
- package/dist/js/slotStore.js +46 -0
- package/dist/js/slotStore.js.map +1 -0
- package/dist/js/standardSchema.d.ts +47 -0
- package/dist/js/standardSchema.d.ts.map +1 -0
- package/dist/js/standardSchema.js +41 -0
- package/dist/js/standardSchema.js.map +1 -0
- package/dist/js/useForm.d.ts +43 -0
- package/dist/js/useForm.d.ts.map +1 -0
- package/dist/js/useForm.js +164 -0
- package/dist/js/useForm.js.map +1 -0
- package/dist/js/useLinkStatus.d.ts +2 -0
- package/dist/js/useLinkStatus.d.ts.map +1 -0
- package/dist/js/useLinkStatus.js +3 -0
- package/dist/js/useLinkStatus.js.map +1 -0
- package/dist/js/useOnline.d.ts +8 -0
- package/dist/js/useOnline.d.ts.map +1 -0
- package/dist/js/useOnline.js +20 -0
- package/dist/js/useOnline.js.map +1 -0
- package/dist/js/usePathname.d.ts +9 -0
- package/dist/js/usePathname.d.ts.map +1 -0
- package/dist/js/usePathname.js +32 -0
- package/dist/js/usePathname.js.map +1 -0
- package/dist/js/useSearchParams.d.ts +2 -0
- package/dist/js/useSearchParams.d.ts.map +1 -0
- package/dist/js/useSearchParams.js +60 -0
- package/dist/js/useSearchParams.js.map +1 -0
- package/dist/manifest.d.ts +66 -0
- package/dist/manifest.d.ts.map +1 -0
- package/dist/manifest.js +13 -0
- package/dist/manifest.js.map +1 -0
- package/dist/prerender.d.ts +138 -0
- package/dist/prerender.d.ts.map +1 -0
- package/dist/prerender.js +387 -0
- package/dist/prerender.js.map +1 -0
- package/dist/redirect.d.ts +34 -0
- package/dist/redirect.d.ts.map +1 -0
- package/dist/redirect.js +108 -0
- package/dist/redirect.js.map +1 -0
- package/dist/redirectDigest.d.ts +20 -0
- package/dist/redirectDigest.d.ts.map +1 -0
- package/dist/redirectDigest.js +66 -0
- package/dist/redirectDigest.js.map +1 -0
- package/dist/request.d.ts +93 -0
- package/dist/request.d.ts.map +1 -0
- package/dist/request.js +308 -0
- package/dist/request.js.map +1 -0
- package/dist/revalidate.d.ts +43 -0
- package/dist/revalidate.d.ts.map +1 -0
- package/dist/revalidate.js +99 -0
- package/dist/revalidate.js.map +1 -0
- package/dist/routes.d.ts +37 -0
- package/dist/routes.d.ts.map +1 -0
- package/dist/routes.js +28 -0
- package/dist/routes.js.map +1 -0
- package/dist/routing.d.ts +52 -0
- package/dist/routing.d.ts.map +1 -0
- package/dist/routing.js +146 -0
- package/dist/routing.js.map +1 -0
- package/dist/runtime.d.ts +36 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +86 -0
- package/dist/runtime.js.map +1 -0
- package/dist/safeUrl.d.ts +10 -0
- package/dist/safeUrl.d.ts.map +1 -0
- package/dist/safeUrl.js +40 -0
- package/dist/safeUrl.js.map +1 -0
- package/dist/streaming.d.ts +62 -0
- package/dist/streaming.d.ts.map +1 -0
- package/dist/streaming.js +108 -0
- package/dist/streaming.js.map +1 -0
- package/dist/types.d.ts +82 -0
- package/dist/vite.d.ts +109 -0
- package/dist/vite.d.ts.map +1 -0
- package/dist/vite.js +1909 -0
- package/dist/vite.js.map +1 -0
- package/dist/worker.d.ts +2 -0
- package/dist/worker.d.ts.map +1 -0
- package/dist/worker.js +863 -0
- package/dist/worker.js.map +1 -0
- package/package.json +223 -0
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Read every chunk a stream already has queued, then stop.
|
|
3
|
+
*
|
|
4
|
+
* A queued chunk settles its read in a microtask, so it always beats the
|
|
5
|
+
* macrotask this races it against. A read that loses means the producer is
|
|
6
|
+
* waiting on data rather than still writing — for React's SSR stream, the
|
|
7
|
+
* moment the shell is fully out.
|
|
8
|
+
*
|
|
9
|
+
* The losing read is handed back rather than dropped, so the caller resumes
|
|
10
|
+
* without losing a chunk.
|
|
11
|
+
*/
|
|
12
|
+
export declare function drainQueuedChunks<T>(reader: {
|
|
13
|
+
read(): Promise<{
|
|
14
|
+
done: boolean;
|
|
15
|
+
value?: T;
|
|
16
|
+
}>;
|
|
17
|
+
}, onChunk: (chunk: T) => void): Promise<{
|
|
18
|
+
pending: Promise<{
|
|
19
|
+
done: boolean;
|
|
20
|
+
value?: T;
|
|
21
|
+
}> | null;
|
|
22
|
+
done: boolean;
|
|
23
|
+
}>;
|
|
24
|
+
export interface DeferredHost {
|
|
25
|
+
/** Installed in place of the real host fn for the whole request. */
|
|
26
|
+
hostFn: (fn: string, ...args: unknown[]) => Promise<unknown>;
|
|
27
|
+
/** Start queueing. Called once metadata is resolved. */
|
|
28
|
+
begin: () => void;
|
|
29
|
+
/** Release the queue. Called once React's first payload is on the socket. */
|
|
30
|
+
flush: () => void;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Queue host calls made during the render, so React's first payload — the HTML
|
|
34
|
+
* shell, or the Flight root model and fallback rows — is on the socket before
|
|
35
|
+
* PHP blocks on one.
|
|
36
|
+
*
|
|
37
|
+
* PHP runs a host callback synchronously on the same thread that pumps that
|
|
38
|
+
* socket. Once a call starts, nothing the worker writes reaches the browser
|
|
39
|
+
* until it returns, so anything React had not yet produced is stranded for the
|
|
40
|
+
* duration. Both streaming paths share this: it is the difference between a
|
|
41
|
+
* page painting its skeletons at once and painting nothing for the length of
|
|
42
|
+
* the slowest call in it.
|
|
43
|
+
*/
|
|
44
|
+
export declare function createDeferredHost(realHostFn: (fn: string, ...args: unknown[]) => Promise<unknown>): DeferredHost;
|
|
45
|
+
/**
|
|
46
|
+
* Write a React stream out, releasing the deferred host calls at the one safe
|
|
47
|
+
* moment: after everything already queued — the shell, or the Flight root model
|
|
48
|
+
* and fallback rows — is on the socket, and before anything that arrives later.
|
|
49
|
+
*
|
|
50
|
+
* Both worker paths stream through this so the ordering cannot drift between
|
|
51
|
+
* them. It already had: the HTML path released after its first chunk and the
|
|
52
|
+
* Flight path never deferred at all, so a slow host call blocked PHP with most
|
|
53
|
+
* of the payload still unwritten and the browser rendered nothing until the
|
|
54
|
+
* call returned.
|
|
55
|
+
*/
|
|
56
|
+
export declare function streamWithDeferredRelease<T>(reader: {
|
|
57
|
+
read(): Promise<{
|
|
58
|
+
done: boolean;
|
|
59
|
+
value?: T;
|
|
60
|
+
}>;
|
|
61
|
+
}, onChunk: (chunk: T) => void, release: () => void, idle?: () => Promise<void>): Promise<void>;
|
|
62
|
+
//# sourceMappingURL=streaming.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"streaming.d.ts","sourceRoot":"","sources":["../src/streaming.ts"],"names":[],"mappings":"AAUA;;;;;;;;;;GAUG;AACH,wBAAsB,iBAAiB,CAAC,CAAC,EACvC,MAAM,EAAE;IAAE,IAAI,IAAI,OAAO,CAAC;QAAE,IAAI,EAAE,OAAO,CAAC;QAAC,KAAK,CAAC,EAAE,CAAC,CAAA;KAAE,CAAC,CAAA;CAAE,EACzD,OAAO,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,GAC1B,OAAO,CAAC;IAAE,OAAO,EAAE,OAAO,CAAC;QAAE,IAAI,EAAE,OAAO,CAAC;QAAC,KAAK,CAAC,EAAE,CAAC,CAAA;KAAE,CAAC,GAAG,IAAI,CAAC;IAAC,IAAI,EAAE,OAAO,CAAA;CAAE,CAAC,CAenF;AAED,MAAM,WAAW,YAAY;IAC3B,oEAAoE;IACpE,MAAM,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IAC7D,wDAAwD;IACxD,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB,6EAA6E;IAC7E,KAAK,EAAE,MAAM,IAAI,CAAC;CACnB;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC,OAAO,CAAC,GAAG,YAAY,CA4CjH;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,yBAAyB,CAAC,CAAC,EAC/C,MAAM,EAAE;IAAE,IAAI,IAAI,OAAO,CAAC;QAAE,IAAI,EAAE,OAAO,CAAC;QAAC,KAAK,CAAC,EAAE,CAAC,CAAA;KAAE,CAAC,CAAA;CAAE,EACzD,OAAO,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,EAC3B,OAAO,EAAE,MAAM,IAAI,EACnB,IAAI,GAAE,MAAM,OAAO,CAAC,IAAI,CAAoB,GAC3C,OAAO,CAAC,IAAI,CAAC,CAcf"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
// Streaming coordination shared by both worker paths — initial-load HTML and
|
|
2
|
+
// SPA-navigation Flight.
|
|
3
|
+
//
|
|
4
|
+
// Both stream React output over a socket that PHP pumps on the same thread it
|
|
5
|
+
// runs host callbacks on. That single fact drives everything here: React's
|
|
6
|
+
// first payload has to be on the socket before a callback can block, or the
|
|
7
|
+
// browser sees nothing until the slowest call in the page returns.
|
|
8
|
+
import { yieldToEventLoop } from './runtime.js';
|
|
9
|
+
/**
|
|
10
|
+
* Read every chunk a stream already has queued, then stop.
|
|
11
|
+
*
|
|
12
|
+
* A queued chunk settles its read in a microtask, so it always beats the
|
|
13
|
+
* macrotask this races it against. A read that loses means the producer is
|
|
14
|
+
* waiting on data rather than still writing — for React's SSR stream, the
|
|
15
|
+
* moment the shell is fully out.
|
|
16
|
+
*
|
|
17
|
+
* The losing read is handed back rather than dropped, so the caller resumes
|
|
18
|
+
* without losing a chunk.
|
|
19
|
+
*/
|
|
20
|
+
export async function drainQueuedChunks(reader, onChunk) {
|
|
21
|
+
let pending = reader.read();
|
|
22
|
+
while (true) {
|
|
23
|
+
const settled = await Promise.race([
|
|
24
|
+
pending.then((result) => ({ result })),
|
|
25
|
+
yieldToEventLoop().then(() => null),
|
|
26
|
+
]);
|
|
27
|
+
if (settled === null)
|
|
28
|
+
return { pending, done: false };
|
|
29
|
+
if (settled.result.done)
|
|
30
|
+
return { pending: null, done: true };
|
|
31
|
+
onChunk(settled.result.value);
|
|
32
|
+
pending = reader.read();
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Queue host calls made during the render, so React's first payload — the HTML
|
|
37
|
+
* shell, or the Flight root model and fallback rows — is on the socket before
|
|
38
|
+
* PHP blocks on one.
|
|
39
|
+
*
|
|
40
|
+
* PHP runs a host callback synchronously on the same thread that pumps that
|
|
41
|
+
* socket. Once a call starts, nothing the worker writes reaches the browser
|
|
42
|
+
* until it returns, so anything React had not yet produced is stranded for the
|
|
43
|
+
* duration. Both streaming paths share this: it is the difference between a
|
|
44
|
+
* page painting its skeletons at once and painting nothing for the length of
|
|
45
|
+
* the slowest call in it.
|
|
46
|
+
*/
|
|
47
|
+
export function createDeferredHost(realHostFn) {
|
|
48
|
+
const pendingCalls = [];
|
|
49
|
+
let flushed = false;
|
|
50
|
+
let deferring = false;
|
|
51
|
+
let backstop;
|
|
52
|
+
const flush = () => {
|
|
53
|
+
if (flushed)
|
|
54
|
+
return;
|
|
55
|
+
flushed = true;
|
|
56
|
+
clearTimeout(backstop);
|
|
57
|
+
for (const call of pendingCalls) {
|
|
58
|
+
realHostFn(call.fn, ...call.args).then(call.resolve, call.reject);
|
|
59
|
+
}
|
|
60
|
+
pendingCalls.length = 0;
|
|
61
|
+
};
|
|
62
|
+
return {
|
|
63
|
+
hostFn: (functionName, ...args) => {
|
|
64
|
+
if (!deferring || flushed)
|
|
65
|
+
return realHostFn(functionName, ...args);
|
|
66
|
+
return new Promise((resolve, reject) => {
|
|
67
|
+
pendingCalls.push({ fn: functionName, args, resolve, reject });
|
|
68
|
+
});
|
|
69
|
+
},
|
|
70
|
+
// Deferral covers the render only. Metadata resolves before any payload
|
|
71
|
+
// exists, so a host call there has nothing to strand — queueing it would
|
|
72
|
+
// just stall generateMetadata until the backstop fired.
|
|
73
|
+
begin: () => {
|
|
74
|
+
deferring = true;
|
|
75
|
+
// Backstop only, for a render that awaits a host call before it can
|
|
76
|
+
// produce the payload that would release the queue. The build rejects
|
|
77
|
+
// such a page unless it ships a loading.tsx, whose shell does not block,
|
|
78
|
+
// so in practice the drain always gets there first. Long on purpose: it
|
|
79
|
+
// must never race a cold start.
|
|
80
|
+
backstop = setTimeout(flush, 5000);
|
|
81
|
+
},
|
|
82
|
+
flush,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Write a React stream out, releasing the deferred host calls at the one safe
|
|
87
|
+
* moment: after everything already queued — the shell, or the Flight root model
|
|
88
|
+
* and fallback rows — is on the socket, and before anything that arrives later.
|
|
89
|
+
*
|
|
90
|
+
* Both worker paths stream through this so the ordering cannot drift between
|
|
91
|
+
* them. It already had: the HTML path released after its first chunk and the
|
|
92
|
+
* Flight path never deferred at all, so a slow host call blocked PHP with most
|
|
93
|
+
* of the payload still unwritten and the browser rendered nothing until the
|
|
94
|
+
* call returned.
|
|
95
|
+
*/
|
|
96
|
+
export async function streamWithDeferredRelease(reader, onChunk, release, idle = yieldToEventLoop) {
|
|
97
|
+
let { pending, done } = await drainQueuedChunks(reader, onChunk);
|
|
98
|
+
release();
|
|
99
|
+
while (!done) {
|
|
100
|
+
const result = await (pending ?? reader.read());
|
|
101
|
+
pending = null;
|
|
102
|
+
if (result.done)
|
|
103
|
+
break;
|
|
104
|
+
onChunk(result.value);
|
|
105
|
+
await idle();
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=streaming.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"streaming.js","sourceRoot":"","sources":["../src/streaming.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,yBAAyB;AACzB,EAAE;AACF,8EAA8E;AAC9E,2EAA2E;AAC3E,4EAA4E;AAC5E,mEAAmE;AAEnE,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AAE/C;;;;;;;;;;GAUG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,MAAyD,EACzD,OAA2B;IAE3B,IAAI,OAAO,GAAG,MAAM,CAAC,IAAI,EAAE,CAAA;IAE3B,OAAO,IAAI,EAAE,CAAC;QACZ,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC;YACjC,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC;YACtC,gBAAgB,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC;SACpC,CAAC,CAAA;QAEF,IAAI,OAAO,KAAK,IAAI;YAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,CAAA;QACrD,IAAI,OAAO,CAAC,MAAM,CAAC,IAAI;YAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,CAAA;QAE7D,OAAO,CAAC,OAAO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E,wEAAwE;YACxE,gCAAgC;YAChC,QAAQ,GAAG,UAAU,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;QACrC,CAAC;QAED,KAAK;KACN,CAAC;AACJ,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,CAAC,KAAK,UAAU,yBAAyB,CAC7C,MAAyD,EACzD,OAA2B,EAC3B,OAAmB,EACnB,IAAI,GAAwB,gBAAgB;IAE5C,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,MAAM,iBAAiB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAEhE,OAAO,EAAE,CAAA;IAET,OAAO,CAAC,IAAI,EAAE,CAAC;QACb,MAAM,MAAM,GAAG,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC,IAAI,EAAE,CAAC,CAAA;QAC/C,OAAO,GAAG,IAAI,CAAA;QAEd,IAAI,MAAM,CAAC,IAAI;YAAE,MAAK;QAEtB,OAAO,CAAC,MAAM,CAAC,KAAU,CAAC,CAAA;QAC1B,MAAM,IAAI,EAAE,CAAA;IACd,CAAC;AACH,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
// Ambient types for an RSC app. Copied into the project's source directory by
|
|
2
|
+
// the host's build, so a page can annotate its metadata without importing
|
|
3
|
+
// anything.
|
|
4
|
+
//
|
|
5
|
+
// The host global (rpc) is NOT declared here: its name is configurable, so the
|
|
6
|
+
// host generates that declaration with the name it actually installed. Two
|
|
7
|
+
// ambient declarations of the same function would conflict.
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Page metadata for RSC pages.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```tsx
|
|
14
|
+
* export const metadata: Metadata = {
|
|
15
|
+
* title: 'My Page',
|
|
16
|
+
* description: 'Page description',
|
|
17
|
+
* keywords: ['react', 'laravel'],
|
|
18
|
+
* };
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
interface IconDescriptor {
|
|
22
|
+
url: string | URL;
|
|
23
|
+
type?: string;
|
|
24
|
+
sizes?: string;
|
|
25
|
+
color?: string;
|
|
26
|
+
rel?: string;
|
|
27
|
+
media?: string;
|
|
28
|
+
fetchPriority?: 'high' | 'low' | 'auto';
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
type IconURL = string | URL;
|
|
32
|
+
|
|
33
|
+
interface Icons {
|
|
34
|
+
icon?: IconURL | IconDescriptor | (IconURL | IconDescriptor)[];
|
|
35
|
+
apple?: IconURL | IconDescriptor | (IconURL | IconDescriptor)[];
|
|
36
|
+
shortcut?: IconURL | IconDescriptor | (IconURL | IconDescriptor)[];
|
|
37
|
+
other?: IconDescriptor | IconDescriptor[];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** A layout's title, wrapping the titles of the pages beneath it. */
|
|
41
|
+
interface TitleTemplate {
|
|
42
|
+
/** `%s` stands in for the page's own title. */
|
|
43
|
+
template?: string;
|
|
44
|
+
/** Used by a page that exports no title of its own. */
|
|
45
|
+
default?: string;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
interface Metadata {
|
|
49
|
+
/** A string on a page; a template on a layout, applied to the pages below it. */
|
|
50
|
+
title?: string | TitleTemplate;
|
|
51
|
+
description?: string;
|
|
52
|
+
keywords?: string | string[];
|
|
53
|
+
author?: string;
|
|
54
|
+
robots?: string;
|
|
55
|
+
icons?: IconURL | (IconURL | IconDescriptor)[] | Icons | null;
|
|
56
|
+
'og:title'?: string;
|
|
57
|
+
'og:description'?: string;
|
|
58
|
+
'og:image'?: string;
|
|
59
|
+
'og:url'?: string;
|
|
60
|
+
'og:type'?: string;
|
|
61
|
+
'og:site_name'?: string;
|
|
62
|
+
'twitter:card'?: string;
|
|
63
|
+
'twitter:title'?: string;
|
|
64
|
+
'twitter:description'?: string;
|
|
65
|
+
'twitter:image'?: string;
|
|
66
|
+
'twitter:site'?: string;
|
|
67
|
+
[key: string]: string | string[] | TitleTemplate | Icons | IconURL | (IconURL | IconDescriptor)[] | null | undefined;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Metadata that depends on the request.
|
|
72
|
+
*
|
|
73
|
+
* Receives the same awaitables a page does, so one shape is learned rather
|
|
74
|
+
* than two:
|
|
75
|
+
*
|
|
76
|
+
* export const generateMetadata: GenerateMetadata<{ slug: string }> =
|
|
77
|
+
* async ({ params }) => ({ title: (await params).slug })
|
|
78
|
+
*/
|
|
79
|
+
type GenerateMetadata<P = Record<string, string>> = (args: {
|
|
80
|
+
params: Promise<P>;
|
|
81
|
+
searchParams: Promise<URLSearchParams>;
|
|
82
|
+
}) => Metadata | Promise<Metadata>;
|
package/dist/vite.d.ts
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import type { PluginOption } from 'vite';
|
|
2
|
+
export interface RscRoutesOptions {
|
|
3
|
+
/** Project root. Defaults to RSC_PROJECT_ROOT, then cwd. */
|
|
4
|
+
projectRoot?: string;
|
|
5
|
+
/** Directory holding the app/ route tree. Defaults to `src`. */
|
|
6
|
+
sourceDir?: string;
|
|
7
|
+
/** Where the server bundles and generated entries go. Defaults to `.rsc`. */
|
|
8
|
+
outDir?: string;
|
|
9
|
+
/** Where the browser bundle is written. Defaults to `dist/client`. */
|
|
10
|
+
assetsDir?: string;
|
|
11
|
+
/** Public URL the browser bundle is served from. Defaults to `/`. */
|
|
12
|
+
assetsUrl?: string;
|
|
13
|
+
/**
|
|
14
|
+
* This package's directory, holding the client runtime the browser entry
|
|
15
|
+
* imports. Vite stages configs through node_modules/.vite-temp, so
|
|
16
|
+
* import.meta.dir is not this file's real location by the time the plugin
|
|
17
|
+
* runs — a host invoking the build out of process passes the real path
|
|
18
|
+
* through RSC_PACKAGE_DIR.
|
|
19
|
+
*/
|
|
20
|
+
packageDir?: string;
|
|
21
|
+
/**
|
|
22
|
+
* Name of the global the host installs for calling its own functions from a
|
|
23
|
+
* server component — `await rpc('getUser', id)`. The mechanism is
|
|
24
|
+
* host-agnostic; only the name is a convention, so a host that prefers
|
|
25
|
+
* something else can say so.
|
|
26
|
+
*/
|
|
27
|
+
hostGlobal?: string;
|
|
28
|
+
/**
|
|
29
|
+
* JSON file of `{urlPattern, slot}` entries naming the routes the client
|
|
30
|
+
* router should intercept rather than navigate to. Written by the host,
|
|
31
|
+
* which owns route discovery.
|
|
32
|
+
*/
|
|
33
|
+
interceptManifestFile?: string;
|
|
34
|
+
/**
|
|
35
|
+
* Bare-specifier prefix for importing the client runtime, as in
|
|
36
|
+
* `import Link from '<prefix>/Link'`, aliased to this package's js/
|
|
37
|
+
* directory.
|
|
38
|
+
*
|
|
39
|
+
* Only needed when this package is not resolvable from the project's
|
|
40
|
+
* node_modules — a host that vendors it through its own package manager,
|
|
41
|
+
* say. Installed from npm, the package name resolves on its own and no
|
|
42
|
+
* alias is required.
|
|
43
|
+
*/
|
|
44
|
+
packageAlias?: string;
|
|
45
|
+
/**
|
|
46
|
+
* Origin the Vite dev server is reachable at, e.g. `http://localhost:5173`.
|
|
47
|
+
*
|
|
48
|
+
* Set only when running under the dev server. @vitejs/plugin-rsc emits its
|
|
49
|
+
* bootstrap and CSS links root-relative in dev and no Vite setting moves
|
|
50
|
+
* them, so with the host serving the page the browser would ask the host for
|
|
51
|
+
* modules only Vite can answer. Given this, the SSR entry rewrites them onto
|
|
52
|
+
* the dev origin — see devUrls.ts. Empty in a build, where the URLs are real
|
|
53
|
+
* built assets.
|
|
54
|
+
*/
|
|
55
|
+
devOrigin?: string;
|
|
56
|
+
/**
|
|
57
|
+
* What the build produces.
|
|
58
|
+
*
|
|
59
|
+
* 'server' the default: pages are served by a host, and a payload is
|
|
60
|
+
* asked for with a header on the page's own url.
|
|
61
|
+
* 'export' files any static host can serve. Payloads get addresses of
|
|
62
|
+
* their own, because a host serving files cannot act on a
|
|
63
|
+
* header, and the client is built to ask for those instead.
|
|
64
|
+
*/
|
|
65
|
+
output?: 'server' | 'export';
|
|
66
|
+
/** Where an exported site is written, relative to the project root. */
|
|
67
|
+
exportPath?: string;
|
|
68
|
+
/**
|
|
69
|
+
* Filename payloads are served under on a static host, e.g. `index.rsc`.
|
|
70
|
+
*
|
|
71
|
+
* Only for an exported build. Normally the payload shares the page's url and
|
|
72
|
+
* is asked for with a header; a host that serves files cannot answer that,
|
|
73
|
+
* so the payload needs an address of its own.
|
|
74
|
+
*/
|
|
75
|
+
staticPayloads?: string;
|
|
76
|
+
/**
|
|
77
|
+
* How to tell that a route's props are resolved dynamically by the host, so
|
|
78
|
+
* the page cannot be prerendered whole.
|
|
79
|
+
*
|
|
80
|
+
* Entirely host-defined: a host that writes a config file beside the page
|
|
81
|
+
* names that file and the pattern that marks it dynamic. Omitted, no page is
|
|
82
|
+
* classified dynamic on this basis.
|
|
83
|
+
*/
|
|
84
|
+
routeConfig?: {
|
|
85
|
+
file: string;
|
|
86
|
+
dynamicPattern: RegExp;
|
|
87
|
+
};
|
|
88
|
+
/**
|
|
89
|
+
* Functions the host exposes to the app, as `{ exportedName: target }`.
|
|
90
|
+
*
|
|
91
|
+
* The build writes a "use server" module of stubs for these, each one
|
|
92
|
+
* calling the host global with its target — so app code imports an ordinary
|
|
93
|
+
* async function and never names the transport. Discovery belongs to the
|
|
94
|
+
* host, whose functions these are; only the rendering is here, because the
|
|
95
|
+
* module has to land beside the app's source and that path is the build's.
|
|
96
|
+
*
|
|
97
|
+
* A host whose functions are already JavaScript passes nothing.
|
|
98
|
+
*/
|
|
99
|
+
hostActions?: Record<string, string>;
|
|
100
|
+
/**
|
|
101
|
+
* Freeze what can be frozen at the end of `vite build`. Defaults to true.
|
|
102
|
+
*
|
|
103
|
+
* Off, the build produces bundles and nothing else, and every route renders
|
|
104
|
+
* per request. See the note on the hook for when you would want that.
|
|
105
|
+
*/
|
|
106
|
+
prerender?: boolean;
|
|
107
|
+
}
|
|
108
|
+
export declare function rscRoutes(options?: RscRoutesOptions): PluginOption[];
|
|
109
|
+
//# sourceMappingURL=vite.d.ts.map
|
|
@@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