Recommend async tasks over #[Lazy] for slow screens - #548
Merged
Merged
Conversation
#[Lazy] runs mount() on the UI thread, so the screen can't be used or left until it returns. Async tasks render the real screen straight away and keep it interactive, so recommend them for slow screens. Also drop "in the background" from the #[Lazy] intro, since mount() doesn't run in the background. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds an aside to the `#[Lazy]` section of the mobile v4 lifecycle hooks page recommending async tasks instead.
`#[Lazy]` shows a placeholder, but `mount()` still runs on the UI thread. Until it returns the user can't interact with the screen or go back. Dispatching the slow work from `mount()` with `$this->async()` renders the real screen straight away, keeps it interactive, and lets the dev choose where the loading state goes. The aside includes a short example of that.
I also removed "in the background" from the intro sentence, because `mount()` doesn't run in the background.
Dispatching from `mount()` is covered by `AsyncTaskCompletionTest` in mobile-air.
🤖 Generated with Claude Code