|
34 | 34 | REACTPY_CHECK_VDOM_SPEC, |
35 | 35 | REACTPY_DEBUG, |
36 | 36 | ) |
37 | | -from reactpy.core._life_cycle_hook import LifeCycleHook |
| 37 | +from reactpy.core._life_cycle_hook import HOOK_STACK, LifeCycleHook |
38 | 38 | from reactpy.core.vdom import validate_vdom_json |
39 | 39 | from reactpy.types import ( |
40 | 40 | BaseLayout, |
@@ -162,43 +162,47 @@ async def _parallel_render(self) -> LayoutUpdateMessage: |
162 | 162 | async def _create_layout_update( |
163 | 163 | self, old_state: _ModelState |
164 | 164 | ) -> LayoutUpdateMessage: |
165 | | - component = old_state.life_cycle_state.component |
| 165 | + token = HOOK_STACK.initialize() |
166 | 166 | try: |
167 | | - parent: _ModelState | None = old_state.parent |
168 | | - except AttributeError: |
169 | | - parent = None |
170 | | - |
171 | | - async with AsyncExitStack() as exit_stack: |
172 | | - new_state = await self._render_component( |
173 | | - exit_stack, |
174 | | - old_state, |
175 | | - parent, |
176 | | - old_state.index, |
177 | | - old_state.key, |
178 | | - component, |
179 | | - ) |
| 167 | + component = old_state.life_cycle_state.component |
| 168 | + try: |
| 169 | + parent: _ModelState | None = old_state.parent |
| 170 | + except AttributeError: |
| 171 | + parent = None |
| 172 | + |
| 173 | + async with AsyncExitStack() as exit_stack: |
| 174 | + new_state = await self._render_component( |
| 175 | + exit_stack, |
| 176 | + old_state, |
| 177 | + parent, |
| 178 | + old_state.index, |
| 179 | + old_state.key, |
| 180 | + component, |
| 181 | + ) |
180 | 182 |
|
181 | | - if parent is not None: |
182 | | - parent.children_by_key[new_state.key] = new_state |
183 | | - old_parent_model = parent.model.current |
184 | | - old_parent_children = old_parent_model.setdefault("children", []) |
185 | | - parent.model.current = { |
186 | | - **old_parent_model, |
187 | | - "children": [ |
188 | | - *old_parent_children[: new_state.index], |
189 | | - new_state.model.current, |
190 | | - *old_parent_children[new_state.index + 1 :], |
191 | | - ], |
| 183 | + if parent is not None: |
| 184 | + parent.children_by_key[new_state.key] = new_state |
| 185 | + old_parent_model = parent.model.current |
| 186 | + old_parent_children = old_parent_model.setdefault("children", []) |
| 187 | + parent.model.current = { |
| 188 | + **old_parent_model, |
| 189 | + "children": [ |
| 190 | + *old_parent_children[: new_state.index], |
| 191 | + new_state.model.current, |
| 192 | + *old_parent_children[new_state.index + 1 :], |
| 193 | + ], |
| 194 | + } |
| 195 | + |
| 196 | + if REACTPY_CHECK_VDOM_SPEC.current: |
| 197 | + validate_vdom_json(new_state.model.current) |
| 198 | + |
| 199 | + return { |
| 200 | + "type": "layout-update", |
| 201 | + "path": new_state.patch_path, |
| 202 | + "model": new_state.model.current, |
192 | 203 | } |
193 | | - |
194 | | - if REACTPY_CHECK_VDOM_SPEC.current: |
195 | | - validate_vdom_json(new_state.model.current) |
196 | | - |
197 | | - return { |
198 | | - "type": "layout-update", |
199 | | - "path": new_state.patch_path, |
200 | | - "model": new_state.model.current, |
201 | | - } |
| 204 | + finally: |
| 205 | + HOOK_STACK.reset(token) |
202 | 206 |
|
203 | 207 | async def _render_component( |
204 | 208 | self, |
|
0 commit comments