Skip to content

Fragment parenting overhaul#162

Draft
berendkleinhaneveld wants to merge 4 commits intomasterfrom
fragment-parenting-overhaul
Draft

Fragment parenting overhaul#162
berendkleinhaneveld wants to merge 4 commits intomasterfrom
fragment-parenting-overhaul

Conversation

@berendkleinhaneveld
Copy link
Collaborator

No description provided.

Separate template tree (static structure) from render tree (dynamic state):

- Rename `children` → `template_children` for static structure
- Add `render_children()` method to return currently mounted fragments
- Add `render_parent` property for anchor lookups in slot contexts
- Change `slot_contents` → `slot_content: dict[str, list[Fragment]]`

Fragment-specific changes:
- ControlFlowFragment: `_active_child` tracks current branch
- ListFragment: `_generated_fragments` separate from template
- ComponentFragment: dual mode (usage site vs render wrapper)
- SlotFragment: sets `_render_parent` on slot content during mount

Compiler changes:
- Slot content created without parent, then slot_name set, then registered
- Ensures slot_name is read correctly during register_child()

Hot reload changes:
- Traverse ListFragment._generated_fragments
- Handle ComponentFragment.rendered_fragment in element lookup

All 253 tests pass.
- Add iter_all_children() method to Fragment base class and all subclasses
- ListFragment yields template_children + _generated_fragments
- ComponentFragment yields template_children + rendered_fragment + slot_content
- DynamicFragment yields template_children + _active_fragment

Simplify hot_reload.py using iter_all_children():
- _find_affected_recursive: reduced from 50+ lines to 15 lines
- _collect_used_modules_recursive: reduced from 25+ lines to 10 lines
- _find_root_element: now uses render_children() instead of manual checks
- _collect_state_recursive/_restore_state_recursive: use iter_all_children()

Removed unused DynamicFragment import from hot_reload.py.
Use render_children() to find fragment's position among siblings instead of
manually checking each fragment type's child collection. Slot content still
needs special handling since it's rendered by SlotFragment, not directly by
the ComponentFragment that holds it.

Removed ListFragment import (no longer needed).
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