Skip to content

Commit 8cdcb58

Browse files
committed
fix: avoid premature endRoute on live streams and voidRoot with DataRoot wrapper
- production.js: Track the streaming Response from renderRoute. When a before-middleware throws after next() has returned a live stream, cancel the stream body (triggering composeHtmlStream's cancel handler for proper cleanup) instead of calling endRoute directly, which would retire the data store while renderToReadableStream is still running. - vite-plugin-octane: Add !config.data to the voidRoot condition in hydrate_entry_features so a data module's DataRoot wrapper disables voidRoot, matching the existing rootBoundary guard.
1 parent ad05a5f commit 8cdcb58

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

‎packages/app-core/src/server/production.js‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -428,19 +428,28 @@ export function createHandler(manifest, deps) {
428428
if (manifest.clientAssets != null)
429429
Object.defineProperty(context, 'clientAssets', { value: manifest.clientAssets });
430430
const run = async () => {
431+
let liveResponse = null;
431432
try {
432433
if (match.route.type === 'render') {
433434
return await runMiddlewareChain(
434435
context,
435436
globalMiddlewares,
436437
match.route.before || [],
437-
async () => renderRoute(/** @type {RenderRoute} */ (match.route), context),
438+
async () => {
439+
const response = await renderRoute(/** @type {RenderRoute} */ (match.route), context);
440+
liveResponse = response;
441+
return response;
442+
},
438443
[],
439444
);
440445
}
441446
return await handleServerRoute(match.route, context, globalMiddlewares);
442447
} catch (error) {
443-
endRoute(context);
448+
if (liveResponse?.body) {
449+
await liveResponse.body.cancel(error).catch(() => {});
450+
} else {
451+
endRoute(context);
452+
}
444453
console.error('[octane] Request error:', error);
445454
return new Response('Internal Server Error', { status: 500 });
446455
}

‎packages/vite-plugin-octane/src/index.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,7 @@ async function hydrate_entry_features(context, config, entries, clientBuild, pro
453453
streamedSignals: clientBuild.hasStreamedSignals,
454454
voidRoot:
455455
!rootBoundary &&
456+
!config.data &&
456457
imports.length > 0 &&
457458
(await provenVoidImports(context, RESOLVED_VIRTUAL_HYDRATE_ID, imports)).length ===
458459
imports.length,

0 commit comments

Comments
 (0)