Skip to content

Prevent unnecessary remounts of fragments in 'if' directives - #152

Merged
berendkleinhaneveld merged 1 commit into
masterfrom
fix-unnecessary-remount-if-directive
Jan 20, 2026
Merged

Prevent unnecessary remounts of fragments in 'if' directives#152
berendkleinhaneveld merged 1 commit into
masterfrom
fix-unnecessary-remount-if-directive

Conversation

@berendkleinhaneveld

@berendkleinhaneveld berendkleinhaneveld commented Jan 20, 2026

Copy link
Copy Markdown
Collaborator

Root Cause

The issue is in ControlFlowFragment.update_fragment() at collagraph/fragment.py:445-454. When the active_child watcher triggers (because a reactive dependency changed), the callback always unmounts and remounts the fragment, even when new is old (same fragment).

The added check in fragments.py prevents the unnecessary unmount/remount cycle when the selected fragment hasn't actually changed.

Why This Happens

The observ watcher with deep=True calls the callback whenever dependencies change (see watcher.py:263: if self.deep or ...), regardless of whether the returned value changed. The fix correctly short-circuits when new is old.

@berendkleinhaneveld
berendkleinhaneveld merged commit 3f12eae into master Jan 20, 2026
8 checks passed
@berendkleinhaneveld
berendkleinhaneveld deleted the fix-unnecessary-remount-if-directive branch January 20, 2026 21:19
berendkleinhaneveld added a commit that referenced this pull request Jan 27, 2026
This release includes the following features:

* Support for template refs (#140)
* Hot reloading of components (#146)

And the following fixes and improvements:

* Prevent unnecessary remounts of elements (#152)
* Remove the need for a wrapping template element around dynamic slot content (#147)
* Keep elements ordered properly (#155 , #156)
* [PySide] Improve interaction with PySide elements (#151)
* [PySide] Improve resilience of PySide in light of exceptions (#154)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant