Skip to content

Commit eb254a4

Browse files
Fix double error emission when htmlStream errors after startRSC
When htmlStream errors after startRSC is running, both the htmlStream.on('error') handler and finished(htmlStream) rejection in startRSC's catch block would emit on resultStream, causing duplicate error reports. Now the htmlStream error handler only emits when startRSC hasn't been called yet; once running, finished() handles it. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent c7ec7ff commit eb254a4

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

packages/react-on-rails-pro/src/injectRSCPayload.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,9 +294,16 @@ export default function injectRSCPayload(
294294
* propagate to handleStreamError → errorReporter in the node renderer.
295295
* Error alone is not the end of the stream — termination is handled by the
296296
* 'close' event below.
297+
*
298+
* We only emit here when startRSC hasn't been called yet. Once startRSC is
299+
* running, finished(htmlStream) inside startRSC rejects on error, and the
300+
* catch block there handles reporting — emitting here too would cause the
301+
* same error to be reported twice.
297302
*/
298303
htmlStream.on('error', (err) => {
299-
resultStream.emit('error', err instanceof Error ? err : new Error(String(err)));
304+
if (!rscPromise) {
305+
resultStream.emit('error', err instanceof Error ? err : new Error(String(err)));
306+
}
300307
});
301308

302309
/**

0 commit comments

Comments
 (0)