diff --git a/Sources/TUIkit/App/App.swift b/Sources/TUIkit/App/App.swift index a66be04..413529c 100644 --- a/Sources/TUIkit/App/App.swift +++ b/Sources/TUIkit/App/App.swift @@ -99,6 +99,7 @@ internal final class AppRunner { ) self.renderer = RenderLoop( app: app, + scene: app.body, terminal: terminal, statusBar: statusBar, focusManager: focusManager, diff --git a/Sources/TUIkit/App/RenderLoop.swift b/Sources/TUIkit/App/RenderLoop.swift index 81d46dd..17692a0 100644 --- a/Sources/TUIkit/App/RenderLoop.swift +++ b/Sources/TUIkit/App/RenderLoop.swift @@ -40,6 +40,14 @@ internal struct RenderLoop { /// The user's app instance (provides `body`). let app: A + /// The cached scene from the app's body. + /// + /// Evaluated once at construction time and reused for every frame. + /// This ensures that `@State` properties on views inside the scene + /// survive across render passes — their `Storage` reference stays alive + /// as long as the scene exists. + let scene: A.Body + /// The terminal for output and size queries. let terminal: Terminal @@ -93,7 +101,6 @@ internal struct RenderLoop { ) // Render main content (background fill happens in renderScene) - let scene = app.body renderScene(scene, context: context) // End lifecycle tracking - triggers onDisappear for removed views