Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

- Added `Content.blank` https://github.com/Textualize/textual/pull/6264

### Fixed

- Fixed exception when setting `loading` attribute before mount https://github.com/Textualize/textual/pull/6268

## [6.7.1] - 2025-12-1

### Fixed
Expand Down
5 changes: 4 additions & 1 deletion src/textual/widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -1035,7 +1035,10 @@ def set_loading(self, loading: bool) -> None:

def _watch_loading(self, loading: bool) -> None:
"""Called when the 'loading' reactive is changed."""
self.set_loading(loading)
if not self.is_mounted:
self.call_later(self.set_loading, loading)
else:
self.set_loading(loading)

ExpectType = TypeVar("ExpectType", bound="Widget")

Expand Down
24 changes: 23 additions & 1 deletion tests/test_loading.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from textual.app import App, ComposeResult
from textual.containers import VerticalScroll
from textual.widgets import Label
from textual.widgets import Label, Static


class LoadingApp(App[None]):
Expand Down Expand Up @@ -31,3 +31,25 @@ async def test_loading_disables_and_remove_scrollbars():
await pilot.pause()

assert vs._check_disabled()


async def test_premature_loading():
"""Test a widget can set the `loading` attribute before mounting."""

# No assert, we're just expecting it to not crash

class LoadingWidget(Static):
"""A widget that shows a loading indicator."""

class LoadingApp(App[None]):
"""Simple app with a single loading widget."""

def compose(self) -> ComposeResult:
"""Compose the app with the loading widget."""
widget = LoadingWidget("Loading content...")
widget.loading = True # Should not crash
yield widget

app = LoadingApp()
async with app.run_test() as pilot:
await pilot.pause()
Loading