MCPcopy
hub / github.com/QwikDev/qwik / renderToStream

Function renderToStream

packages/qwik/src/server/render.ts:35–259  ·  view source on GitHub ↗
(
  rootNode: any,
  opts: RenderToStreamOptions
)

Source from the content-addressed store, hash-verified

33 * @public
34 */
35export async function renderToStream(
36 rootNode: any,
37 opts: RenderToStreamOptions
38): Promise<RenderToStreamResult> {
39 let stream = opts.stream;
40 let bufferSize = 0;
41 let totalSize = 0;
42 let networkFlushes = 0;
43 let firstFlushTime = 0;
44 let buffer: string = '';
45 let snapshotResult: SnapshotResult | undefined;
46 const inOrderStreaming = opts.streaming?.inOrder ?? {
47 strategy: 'auto',
48 maximunInitialChunk: 50000,
49 maximunChunk: 30000,
50 };
51 const containerTagName = opts.containerTagName ?? 'html';
52 const containerAttributes = opts.containerAttributes ?? {};
53 const nativeStream = stream;
54 const firstFlushTimer = createTimer();
55 const buildBase = getBuildBase(opts);
56 const resolvedManifest = resolveManifest(opts.manifest);
57 const nonce = opts.serverData?.nonce;
58 function flush() {
59 if (buffer) {
60 nativeStream.write(buffer);
61 buffer = '';
62 bufferSize = 0;
63 networkFlushes++;
64 if (networkFlushes === 1) {
65 firstFlushTime = firstFlushTimer();
66 }
67 }
68 }
69 function enqueue(chunk: string) {
70 const len = chunk.length;
71 bufferSize += len;
72 totalSize += len;
73 buffer += chunk;
74 }
75 switch (inOrderStreaming.strategy) {
76 case 'disabled':
77 stream = {
78 write: enqueue,
79 };
80 break;
81 case 'direct':
82 stream = nativeStream;
83 break;
84 case 'auto':
85 let count = 0;
86 let forceFlush = false;
87 const minimunChunkSize = inOrderStreaming.maximunChunk ?? 0;
88 const initialChunkSize = inOrderStreaming.maximunInitialChunk ?? 0;
89 stream = {
90 write(chunk) {
91 if (chunk === '<!--qkssr-f-->') {
92 forceFlush ||= true;

Callers 15

entry.ssr.tsxFile · 0.90
entry.ssr.tsxFile · 0.90
entry.ssr.tsxFile · 0.90
entry.ssr.tsxFile · 0.90
entry.ssr.tsxFile · 0.90
entry.ssr.tsxFile · 0.90
entry.ssr.tsxFile · 0.90
entry.ssr.tsxFile · 0.90
entry.ssr.tsxFile · 0.90
entry.ssr.tsxFile · 0.90
entry.ssr.tsxFile · 0.90
entry.ssr.tsxFile · 0.90

Calls 15

createTimerFunction · 0.90
getBuildBaseFunction · 0.90
setServerPlatformFunction · 0.90
jsxFunction · 0.90
getQwikLoaderScriptFunction · 0.90
preloaderPreFunction · 0.90
_renderSSRFunction · 0.90
_pauseFromContextsFunction · 0.90
preloaderPostFunction · 0.90
resolveManifestFunction · 0.85
serializeFunctionsFunction · 0.85
collectRenderSymbolsFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…