Skip to content

Fix #6444: Crash when using Input in a DEFAULT_MODE screen#6492

Open
Birnendampf wants to merge 3 commits intoTextualize:mainfrom
Birnendampf:DEFAULT_MODE-input-fix
Open

Fix #6444: Crash when using Input in a DEFAULT_MODE screen#6492
Birnendampf wants to merge 3 commits intoTextualize:mainfrom
Birnendampf:DEFAULT_MODE-input-fix

Conversation

@Birnendampf
Copy link
Copy Markdown

This PR fixes the issue described in #6444
This was specifically caused by textual's use of eager task factories, causing the widgets in the screen to start processing messages before the screen is ever added to the screen stack. This may be a larger underlying oversight which is not fixed here and might require further investigation.

There are also some other things to note:

  1. App.run_test() does not use asyncio.eager_task_factory. This does not seem correct, as it causes a discrepancy between tests and reality. E.g. this bug does not occur with run_test() by default.
    This is beyond the scope of this PR and should probably be a separate issue, unless this is intended.
  2. This is one of three ways to fix this. The issue suggested using except NoScreen, ScreenStackError here:

    textual/src/textual/app.py

    Lines 4555 to 4560 in 0f0849f

    def clear_selection(self) -> None:
    """Clear text selection on the active screen."""
    try:
    self.screen.clear_selection()
    except NoScreen:
    pass
    I chose to copy what TextArea does instead.
  3. Should screens be composed before or after they are added to the screenstack? currently, that behavior depends on the choice of task factory for user screens, which is probably not intended.
    Furthermore, the _default screen is composed after being added to the stack.
    If that is the correct behavior, it would likely also fix this issue, making this PR obsolete.

Link to issue or discussion
fixes #6444

@Birnendampf Birnendampf marked this pull request as ready for review April 15, 2026 14:43
@Birnendampf
Copy link
Copy Markdown
Author

If there is anything I can do to make this more mergeable please lmk! I can move the concerns raised here to a discussion instead if that is preferred.

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.

Crash on first Input in compose of app.DEFAULT_MODE screen

1 participant