mirror of
https://github.com/phranck/TUIkit.git
synced 2026-06-20 09:54:37 +00:00
fix: Clear preference callbacks per render pass to prevent accumulation (H.4)
Add PreferenceStorage.beginRenderPass() that clears callbacks and resets the value stack at the start of each frame. Without this, every render pass appended duplicate callbacks via OnPreferenceChangeModifier, causing N callbacks after N renders — each fired on every setValue() call. Called from RenderLoop.render() alongside the existing clearHandlers() and focusManager.clear() calls. Follows the same per-frame reset pattern. Remove unused clearCallbacks() method (dead code, never called).
This commit is contained in:
@@ -50,8 +50,9 @@ internal struct RenderLoop<A: App> {
|
||||
/// 4. Ends lifecycle tracking (triggers `onDisappear` for removed views)
|
||||
/// 5. Renders the status bar at the bottom
|
||||
func render() {
|
||||
// Clear event handlers before re-rendering
|
||||
// Clear per-frame state before re-rendering
|
||||
tuiContext.keyEventDispatcher.clearHandlers()
|
||||
tuiContext.preferences.beginRenderPass()
|
||||
focusManager.clear()
|
||||
|
||||
// Begin lifecycle tracking for this render pass
|
||||
|
||||
@@ -174,12 +174,19 @@ public final class PreferenceStorage: @unchecked Sendable {
|
||||
callbacks[keyId]?.append(wrappedCallback)
|
||||
}
|
||||
|
||||
/// Clears all callbacks.
|
||||
public func clearCallbacks() {
|
||||
/// Prepares preference storage for a new render pass.
|
||||
///
|
||||
/// Clears all accumulated callbacks and resets the value stack
|
||||
/// to a single empty context. Called at the start of each frame
|
||||
/// by ``RenderLoop/render()`` to prevent callback accumulation.
|
||||
public func beginRenderPass() {
|
||||
callbacks.removeAll()
|
||||
stack = [PreferenceValues()]
|
||||
}
|
||||
|
||||
/// Resets all preference state.
|
||||
///
|
||||
/// Called once during app shutdown by ``TUIContext/reset()``.
|
||||
public func reset() {
|
||||
stack = [PreferenceValues()]
|
||||
callbacks.removeAll()
|
||||
|
||||
Reference in New Issue
Block a user