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

Fix broadcast game screen blinking when a new move is received #1313

Merged
merged 8 commits into from
Jan 12, 2025

Conversation

julien4215
Copy link
Contributor

No description provided.

The bug was due to the following reason.
When a move is received by the BroadcastRoundController, its state
changes. During the next frame the BroadcastRoundGameProvider
state changes to AsyncLoading(value: <oldValue>) causing the broadcast
game screen to switch to the loading state instead of using the oldValue.
@julien4215 julien4215 mentioned this pull request Dec 27, 2024
final broadcastState = ref.watch(broadcastGameControllerProvider(roundId, gameId));

switch (broadcastState) {
case AsyncValue(value: final broadcastState?, hasValue: true):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the hasValue: true here? It doesn't seem necessary and this usage cannot be found in riverpod documentation (nor in any other part of the app).

Copy link
Contributor Author

@julien4215 julien4215 Jan 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not yet in documentation but it has the same effect has having skipError: true and skipLoadingOnReload: true when using when. This is what allow us to avoid the screen blinking by avoiding the loading screen.

final isLocalEvaluationEnabled = broadcastState.isLocalEvaluationEnabled;
final currentNode = broadcastState.currentNode;

return Shimmer(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume the Shimmer here is because we cannot guarantee the round is loaded.

Better put a comment above to clarify that for future readers. This situation where we load two separate controller is not seen anywhere else in the app.

Ideally they should be merged into one to remedy this situation. Creating another provider just for this purpose is OK and it is even recommended by riverpod to combine providers.


switch (game) {
case AsyncValue(value: final game?, hasValue: true):
final broadcastGameState =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another example when reading this code feels weird. First there is game async value which is pattern matched, and then we require the value of broadcastGameState.

Right now I understand the logic since I'm reviewing. But think of future readers (including ourselves of course, in a few months when we will have forgotten any of this). This code is rather confusing.

So again: a new provider must be made that combine both states. It will greatly simplify the logic and make things much less confusing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pull request did not introduce two separate providers. Its goal is to simply fix the blinking screen.

I can combine both providers in a new pull request but I think we should discuss how that should be done because it is not obvious to me.

@veloce veloce changed the title Fix broadcast game screen bliking when a new move is received Fix broadcast game screen blinking when a new move is received Jan 9, 2025
@veloce veloce merged commit b34f133 into lichess-org:main Jan 12, 2025
1 check passed
@julien4215 julien4215 deleted the broadcast-blink branch January 12, 2025 11:07
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.

2 participants