From 44095c0a040aa956265355518a602ad3d0db6e2f Mon Sep 17 00:00:00 2001 From: giles Date: Sat, 7 Mar 2026 18:24:38 +0000 Subject: [PATCH] Fix streaming: split setup (needs context) from generator (just yields) Async generator bodies don't execute until __anext__(), by which time the request context is gone. Restructure execute_page_streaming as a regular async function that does all context-dependent work (g, request, current_app access, layout resolution, task creation) while the context is live, then returns an inner async generator that only yields strings and awaits pre-created tasks. Co-Authored-By: Claude Opus 4.6 --- shared/sx/pages.py | 86 ++++++++++++++++++++++------------------------ 1 file changed, 42 insertions(+), 44 deletions(-) diff --git a/shared/sx/pages.py b/shared/sx/pages.py index 855e588..f4f7ed7 100644 --- a/shared/sx/pages.py +++ b/shared/sx/pages.py @@ -320,14 +320,10 @@ async def execute_page_streaming( ): """Execute a page with streaming response. - Returns an async generator that yields HTML chunks: - 1. HTML shell with suspense placeholders (immediate) - 2. Resolution