mirror of
https://github.com/phranck/TUIkit.git
synced 2026-06-20 09:54:37 +00:00
Fix: Cache scene in RenderLoop to preserve @State across render passes
This commit is contained in:
@@ -99,6 +99,7 @@ internal final class AppRunner<A: App> {
|
||||
)
|
||||
self.renderer = RenderLoop(
|
||||
app: app,
|
||||
scene: app.body,
|
||||
terminal: terminal,
|
||||
statusBar: statusBar,
|
||||
focusManager: focusManager,
|
||||
|
||||
@@ -40,6 +40,14 @@ internal struct RenderLoop<A: App> {
|
||||
/// 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<A: App> {
|
||||
)
|
||||
|
||||
// Render main content (background fill happens in renderScene)
|
||||
let scene = app.body
|
||||
renderScene(scene, context: context)
|
||||
|
||||
// End lifecycle tracking - triggers onDisappear for removed views
|
||||
|
||||
Reference in New Issue
Block a user