Skip to content

fix/correspondence-clock-reset-issue#3005

Merged
veloce merged 2 commits into
lichess-org:mainfrom
MaartenD:fix/correspondece-clock-reset-issue
May 6, 2026
Merged

fix/correspondence-clock-reset-issue#3005
veloce merged 2 commits into
lichess-org:mainfrom
MaartenD:fix/correspondece-clock-reset-issue

Conversation

@MaartenD

Copy link
Copy Markdown
Contributor

The root course of this problem was the method didUpdateWidget

void didUpdateWidget(CorrespondenceClock oldClock) {
    super.didUpdateWidget(oldClock);
    if (widget.duration != oldClock.duration || (widget.active != oldClock.active)) {
      timeLeft = widget.duration;
    }
    if (widget.active) {
      startClock();
    } else {
      stopClock();
    }
  }

The if statement was

if (widget.duration != oldClock.duration)

I played a 1 day correspondece game. The variable timeLeft is only reset when widget.duration changes. But after every move, the server always sends 24:00:00 — so widget.duration stays the same. Meanwhile, the internal timeLeft has already counted down during your turn.

See video how it works now.

correspondece-clock-reset-issue-small.mp4

Fixes #1955

@MaartenD MaartenD changed the title fix/correspondece-clock-reset-issue fix/correspondence-clock-reset-issue Apr 17, 2026
@veloce

veloce commented May 4, 2026

Copy link
Copy Markdown
Contributor

Thanks for the fix and the explanation @MaartenD .

I am not really sure to understand everything here, because when I did this I am pretty it was working. Anyway, I think your fix makes sense indeed.

This code should be tested. This PR is a good opportunity to add tests to make sure we avoid regressions. The widget logic should be tested in a correspondence_clock_widget_test.dart.

@MaartenD

MaartenD commented May 4, 2026

Copy link
Copy Markdown
Contributor Author

fix/correspondece-clock-reset-issue

Add widget tests for CorrespondenceClock

Added test/view/game/correspondence_clock_widget_test.dart with 5 tests covering the key behaviors of the CorrespondenceClock widget:

  • displays the initial time correctly: verifies the clock renders the correct initial duration.
  • does not tick when inactive: verifies the clock does not count down when active is false.
  • resets timeLeft when active changes from true to false: verifies that when the clock becomes inactive and a new duration is - provided by the server, timeLeft is reset to the server value instead of keeping the locally ticked value. This is the core behavior tested by the fix.
  • resets timeLeft when active changes from false to true: same as above but for the opposite direction.
  • resets timeLeft when duration changes without active changing: verifies that a changed duration alone also correctly resets timeLeft.

@veloce what about this set?

@veloce veloce force-pushed the fix/correspondece-clock-reset-issue branch from 3b191b3 to 3c3e4d8 Compare May 6, 2026 09:36
@veloce veloce merged commit 3c3e4d8 into lichess-org:main May 6, 2026
1 check passed
@veloce

veloce commented May 6, 2026

Copy link
Copy Markdown
Contributor

Thanks for this @MaartenD ; I've added more tests and an even more robust clock update detection (even if yours was fine).

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.

Clocks don't correctly reset during correspondence games

2 participants