Skip to content

Commit 87fb7f8

Browse files
Refactor incremental rendering to use async handling for update chunks
1 parent 1dbb048 commit 87fb7f8

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

packages/react-on-rails-pro-node-renderer/src/worker.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,15 +315,15 @@ export default function run(config: Partial<Config>) {
315315
}
316316
},
317317

318-
onUpdateReceived: (obj: unknown) => {
318+
onUpdateReceived: async (obj: unknown) => {
319319
if (!incrementalSink) {
320320
log.error({ msg: 'Unexpected update chunk received after rendering was aborted', obj });
321321
return;
322322
}
323323

324324
try {
325325
log.info(`Received a new update chunk ${JSON.stringify(obj)}`);
326-
incrementalSink.add(obj);
326+
await incrementalSink.add(obj);
327327
} catch (err) {
328328
// Log error but don't stop processing
329329
log.error({ err, msg: 'Error processing update chunk' });

packages/react-on-rails-pro-node-renderer/src/worker/handleIncrementalRenderRequest.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { getRequestBundleFilePath } from '../shared/utils';
55

66
export type IncrementalRenderSink = {
77
/** Called for every subsequent NDJSON object after the first one */
8-
add: (chunk: unknown) => void;
8+
add: (chunk: unknown) => Promise<void>;
99
handleRequestClosed: () => void;
1010
};
1111

@@ -93,11 +93,11 @@ export async function handleIncrementalRenderRequest(
9393
return {
9494
response,
9595
sink: {
96-
add: (chunk: unknown) => {
96+
add: async (chunk: unknown) => {
9797
try {
9898
assertIsUpdateChunk(chunk);
9999
const bundlePath = getRequestBundleFilePath(chunk.bundleTimestamp);
100-
executionContext.runInVM(chunk.updateChunk, bundlePath).catch((err: unknown) => {
100+
await executionContext.runInVM(chunk.updateChunk, bundlePath).catch((err: unknown) => {
101101
log.error({ msg: 'Error running incremental render chunk', err, chunk });
102102
});
103103
} catch (err) {

packages/react-on-rails-pro-node-renderer/src/worker/vm.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ export async function buildExecutionContext(
365365
const objectResult = await result;
366366
result = JSON.stringify(objectResult);
367367
}
368-
if (log.level === 'debug') {
368+
if (log.level === 'debug' && result) {
369369
log.debug(`result from JS:
370370
${smartTrim(result)}`);
371371
const debugOutputPathResult = path.join(serverBundleCachePath, 'result.json');

0 commit comments

Comments
 (0)