Fix portal timers stopping when tab is backgrounded + upgrade Next.js to patch DoS CVE#2095
Draft
Fix portal timers stopping when tab is backgrounded + upgrade Next.js to patch DoS CVE#2095
Conversation
Use wall-clock time tracking in useFieldTimer and useJudgingTimer hooks to compensate for browser throttling of setInterval in backgrounded tabs. - Track lastTickAt (wall clock timestamp of last processed tick) via ref - Use 500ms polling interval for responsiveness - On each poll, calculate elapsed whole seconds and dispatch a single TICK_BY action instead of multiple TICK dispatches - Add TICK_BY reducer action to both hooks that advances time in one reducer call (handling multi-stage transitions in the judging timer) - Update endgame sound trigger in useFieldTimer to use a threshold-crossing check (prev > 30 && curr <= 30) so the sound plays even if the timer jumps past the 30-second mark while backgrounded Agent-Logs-Url: https://github.com/FIRSTIsrael/lems/sessions/862d5df0-5063-4adb-ad71-43f94de3bd0d Co-authored-by: johnmeshulam <55348702+johnmeshulam@users.noreply.github.com>
CVE: Next.js Denial of Service with Server Components Affected: >= 16.0.0-beta.0, < 16.2.3 Resolved to: 16.2.4 (latest patch release) Also update companion packages to match: - @next/eslint-plugin-next: ^16.1.1 -> ^16.2.3 - eslint-config-next: ^16.1.6 -> ^16.2.3 Agent-Logs-Url: https://github.com/FIRSTIsrael/lems/sessions/862d5df0-5063-4adb-ad71-43f94de3bd0d Co-authored-by: johnmeshulam <55348702+johnmeshulam@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix portal timers not running in background
Fix portal timers stopping when tab is backgrounded + upgrade Next.js to patch DoS CVE
Apr 21, 2026
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.
Description
Portal timers (field/scoresheet and judging/rubrics) halt when the browser tab loses focus because browsers throttle
setIntervalin backgrounded tabs, causing ticks to be skipped entirely.Timer fix (
use-field-timer.ts,use-judging-timer.ts)Replaced the tick-counting approach with wall-clock compensation:
lastTickAt(wall-clock timestamp) via ref when the timer starts/resumeselapsedTicks = Math.floor((now - lastTickAt) / 1000)and advancelastTickAtby only whole seconds — fractional time accumulates correctly across pollsTICK_BYaction instead of a loop ofTICKdispatchesTICK_BYin the judging timer handles multi-stage transitions in a single reducer call. The effect dependency is reduced to[state.isRunning]— no longer recreated on every tick.The field timer's endgame sound uses a threshold-crossing check (
prev > 30 && curr <= 30) instead of exact equality, so the 30-second cue plays even if time jumps past that mark while backgrounded.Dependency upgrade (
package.json,package-lock.json)Upgraded
nextfrom^16.1.6→^16.2.3(resolves to16.2.4) to patch a Denial of Service via Server Components vulnerability (affected>= 16.0.0-beta.0, < 16.2.3). Companion packages updated to match:next^16.1.6^16.2.3eslint-config-next^16.1.6^16.2.3@next/eslint-plugin-next^16.1.1^16.2.3Type of change
Screenshots
N/A — timer logic only, no UI changes.
Checklist