Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: guarantee that the first message every program always receives is the tea.WindowSizeMsg #602

Closed
bashbunni opened this issue Nov 16, 2022 · 2 comments
Labels
enhancement New feature or request

Comments

@bashbunni
Copy link
Member

We often see a problem where models are not created until a tea.WindowSizeMsg is received so it can load in with the correct sizes. However, this creates a common race condition where something tries to set the values of this bubble/model before it has been initialized as another message is received before the WindowSizeMsg, leading to a nil pointer error.

In the meantime having this issue and maybe a disclaimer in the README would be helpful for users trying to debug the issue.

Real world example of this issue: orlangure/gocovsh#38

@bashbunni bashbunni added the enhancement New feature or request label Nov 16, 2022
@deicon
Copy link

deicon commented Nov 16, 2022

If tea.WindowSizeMsg is really and in all cases the indication that the application had a chance to properly init all models, all other messages could be defered/buffered until the tea.WindowSizeMsg is pushed on the msgs channel.

Basically by waiting on a mutex which gets released once the tea.WindowSizeMsg is pushed into Update()

@meowgorithm
Copy link
Member

meowgorithm commented Nov 16, 2022

This can and should be solved in documentation.

On the technical side of things, the initial view is called before the first update which means that any view logic around unknown terminal size will need to be accounted for anyway.

More importantly, however, Bubble Tea programs are asynchronous in nature and, as a rule, message order is not guaranteed. If we encourage developers to design their programs in such a manner they'll end up with much more robust applications overall.

If we start to guarantee message order on startup we also risk complicating the mental model. What order do initial messages come in? Do they happen before or after Init()? And so on.

We can reexamine all this again down the road, but for now let's start both with documentation, and patching list.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants