@rsc-kit/core 0.3.0 → 0.4.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/dist/action.d.ts +2 -1
- package/dist/action.d.ts.map +1 -1
- package/dist/action.js +21 -1
- package/dist/action.js.map +1 -1
- package/dist/host.d.ts +9 -0
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +76 -10
- package/dist/host.js.map +1 -1
- package/dist/hostCalls.d.ts +86 -0
- package/dist/hostCalls.d.ts.map +1 -0
- package/dist/hostCalls.js +144 -0
- package/dist/hostCalls.js.map +1 -0
- package/dist/manifest.d.ts +15 -0
- package/dist/manifest.d.ts.map +1 -1
- package/dist/prerender.d.ts +10 -1
- package/dist/prerender.d.ts.map +1 -1
- package/dist/prerender.js +12 -1
- package/dist/prerender.js.map +1 -1
- package/dist/serve.d.ts +55 -0
- package/dist/serve.d.ts.map +1 -0
- package/dist/serve.js +40 -0
- package/dist/serve.js.map +1 -0
- package/dist/vite.d.ts +27 -0
- package/dist/vite.d.ts.map +1 -1
- package/dist/vite.js +313 -15
- package/dist/vite.js.map +1 -1
- package/package.json +9 -9
- package/dist/streaming.d.ts +0 -62
- package/dist/streaming.d.ts.map +0 -1
- package/dist/streaming.js +0 -108
- package/dist/streaming.js.map +0 -1
- package/dist/worker.d.ts +0 -2
- package/dist/worker.d.ts.map +0 -1
- package/dist/worker.js +0 -944
- package/dist/worker.js.map +0 -1
package/dist/streaming.d.ts
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
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
|
package/dist/streaming.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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"}
|
package/dist/streaming.js
DELETED
|
@@ -1,108 +0,0 @@
|
|
|
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
|
package/dist/streaming.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"streaming.js","sourceRoot":"","sources":["../src/streaming.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,yBA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AAI,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/worker.d.ts
DELETED
package/dist/worker.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"worker.d.ts","sourceRoot":"","sources":["../src/worker.ts"],"names":[],"mappings":""}
|