Skip to content

Commit fd58c07

Browse files
fix: avoid exit on the second reload after 215a3bb
1 parent 1d48c7f commit fd58c07

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

packages/textual-hmr/textual_hmr.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,17 @@ def mark_running():
107107
reloading.clear()
108108
started.set()
109109

110-
async def mark_app_ready(_pilot):
111-
# Textual calls the auto-pilot callback after `_ready()`, which is the public hook closest to "app is running".
112-
mark_running()
110+
original_ready = app._ready # noqa: SLF001
111+
112+
async def patched_ready(original_ready=original_ready, app=app):
113+
await original_ready()
114+
app.call_after_refresh(mark_running)
115+
116+
app._ready = patched_ready # noqa: SLF001
113117

114118
async def run_app():
115119
try:
116-
return await app.run_async(headless=headless, inline=inline, inline_no_clear=inline_no_clear, mouse=mouse, auto_pilot=mark_app_ready)
120+
return await app.run_async(headless=headless, inline=inline, inline_no_clear=inline_no_clear, mouse=mouse)
117121
finally:
118122
started.set()
119123

@@ -152,6 +156,9 @@ def on_changes(self, files: set[Path]):
152156
if not (files.intersection(ReactiveModule.instances) or files.intersection(path for path, signal in fs_signals.items() if signal.subscribers)):
153157
return None
154158
changed = super().on_changes(files | {entry_file})
159+
if not self._load.dirty:
160+
# Keep startup-tracked app construction aligned with this reload.
161+
self._load.trigger()
155162
if reloading.is_set():
156163
return changed
157164
nonlocal need_restart

0 commit comments

Comments
 (0)