Skip to content

ENG-397 fix: refine initial update check condition in useAppVersion hook#16382

Open
abhimanyurajeesh wants to merge 2 commits into
developfrom
ENG-397
Open

ENG-397 fix: refine initial update check condition in useAppVersion hook#16382
abhimanyurajeesh wants to merge 2 commits into
developfrom
ENG-397

Conversation

@abhimanyurajeesh
Copy link
Copy Markdown
Contributor

@abhimanyurajeesh abhimanyurajeesh commented May 26, 2026

Proposed Changes

Fixes ENG-397

"App auto update is intended to be auto updated only on the root route; However, it seems to be auto-updating even in non-root routes as well now."
This PR fixes the above issue, now if the user is in a non-root route there will be the update available toast and if in root it auto updates as it was.

How to test
Test 1 : auto-update at root route

  1. Open the app at root level e.g... http://localhost:4000/
  2. Open the local storage and update the "app-version" value to "test" or something
  3. And reload, you can Updated successfully toast.
image Expected: App auto-reloads (auto-update triggers)

--

Test 2 :No auto-update on non-root route

  1. Open the app at non-root level e.g... http://localhost:4000/facility/3a2cb3d4-76fb-46ba-89f7-777cdd3557c2/overview
  2. Open the local storage and update the "app-version" value to "test" or something
  3. And reload, you can Software Update toast.
image Expected: No reload. Instead, an "Software Update" toast appears

Tagging: @ohcnetwork/care-fe-code-reviewers

Merge Checklist

  • Add specs that demonstrate the bug or test the new feature.
  • Update product documentation.
  • Ensure that UI text is placed in I18n files.
  • Prepare a screenshot or demo video for the changelog entry and attach it to the issue.
  • Request peer reviews.
  • Complete QA on mobile devices.
  • Complete QA on desktop devices.
  • Add or update Playwright tests for related changes

Summary by CodeRabbit

  • Bug Fixes
    • Adjusted app update flow: on initial load, automatic updates are applied only when visiting the root URL; if the app is opened on a non-root page, a pending update notification is shown and the update is deferred until user confirmation.

Review Change Stack

@abhimanyurajeesh abhimanyurajeesh requested review from a team and Copilot May 26, 2026 11:56
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 26, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 38c462de-22d4-4b80-a00a-1b928e8c673e

📥 Commits

Reviewing files that changed from the base of the PR and between 1d0cafb and bad57c7.

📒 Files selected for processing (1)
  • src/hooks/useAppVersion.ts

Walkthrough

The useAppVersion hook refines its initial-check behavior by gating automatic updates to the root path only. Initial version checks on non-root routes now defer to the standard polling confirmation flow instead of auto-updating immediately.

Changes

Route-aware version update logic

Layer / File(s) Summary
Route-aware version update condition
src/hooks/useAppVersion.ts
Initial-check condition narrowed to isInitial && window.location.pathname === "/" so automatic updates run only on root path, while non-root initial checks set pendingUpdate for user confirmation.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: refining the initial update check condition in useAppVersion to depend on route context.
Description check ✅ Passed The description is mostly complete with clear problem statement, how-to-test instructions with specific steps and screenshots, and partially completed merge checklist items.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch ENG-397

Comment @coderabbitai help to get the list of available commands and usage tips.

@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented May 26, 2026

Greptile Summary

Fixes the unintended auto-reload behaviour where the app was silently refreshing on every page load regardless of the current route. The change adds a window.location.pathname === "/" guard so auto-updates only fire on the root route; users on other routes now receive a "Software Update" toast instead.

  • src/hooks/useAppVersion.ts: narrowed the auto-update condition in the initial-check branch to require both isInitial and the root pathname, falling through to setPendingUpdate for all other cases.

Confidence Score: 4/5

Single-file change with a clear, targeted fix; the core logic is correct and the only issues are stale comments.

The behaviour change is minimal and well-scoped: users on / still get an auto-reload, users elsewhere get a toast. The only things left behind are a now-inaccurate JSDoc block and a misleading inline comment in the else branch, neither of which affects runtime behaviour.

No files require special attention beyond the comment/JSDoc updates noted in the review comments.

Important Files Changed

Filename Overview
src/hooks/useAppVersion.ts Adds a pathname === "/" guard to the auto-update path so users on non-root routes see a toast instead of a silent reload; logic is correct but JSDoc and an inline comment are now outdated.

Comments Outside Diff (2)

  1. src/hooks/useAppVersion.ts, line 30-35 (link)

    P2 The JSDoc comment on the hook's behaviour is now outdated. It still says the hook "auto-updates" whenever a stored version differs from the server, but that is only true when the user is on the root route. Anyone reading the docs will have a wrong mental model of when the silent reload actually fires.

  2. src/hooks/useAppVersion.ts, line 81-84 (link)

    P2 The inline comment "Polling check" is now misleading — the else branch also handles the initial check when the user is on a non-root route, not just periodic polling. A reader could incorrectly assume isInitial is always false here.

Reviews (1): Last reviewed commit: "fix: refine initial update check conditi..." | Re-trigger Greptile

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
src/hooks/useAppVersion.ts (2)

77-84: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Clarify the else branch comment to include initial non-root checks.

The comment on line 82 states "Polling check: notify user, wait for confirmation", but this else block now handles two scenarios:

  1. Polling checks (when isInitial is false)
  2. Initial checks on non-root routes (when isInitial is true but pathname is not "/")
💬 Suggested comment update
     // Version differs
     if (isInitial && window.location.pathname === "/") {
       // Initial check on root route: auto-update
       performAppUpdate(data.version);
     } else {
-      // Polling check: notify user, wait for confirmation
+      // Polling check or initial check on non-root route: notify user, wait for confirmation
       setPendingUpdate(data.version);
     }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/hooks/useAppVersion.ts` around lines 77 - 84, Update the comment above
the else block in useAppVersion to accurately describe both scenarios it
handles: (a) polling checks when isInitial is false and (b) the initial check
when isInitial is true but window.location.pathname !== "/", i.e., initial
non-root routes—clarify that in these cases we setPendingUpdate(data.version) to
notify the user and wait for confirmation rather than auto-updating via
performAppUpdate.

27-36: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Update JSDoc to reflect route-dependent initial update behavior.

The JSDoc states that on initial mount, if the stored version differs, the app "auto-updates (clears caches + reloads)". However, with the new logic, auto-update only occurs when the initial check happens on the root route ("/"). On non-root routes, the initial check now sets pendingUpdate and waits for user confirmation.

📝 Suggested JSDoc update
 /**
  * Hook for managing app version updates with React Query.
  *
  * On initial mount:
  * - If no stored version (first visit): stores current version without reload
- * - If stored version differs from server: auto-updates (clears caches + reloads)
+ * - If stored version differs from server:
+ *   - On root route ("/"): auto-updates (clears caches + reloads)
+ *   - On non-root routes: sets pendingUpdate state (user must confirm)
  *
  * On subsequent polling checks:
  * - If version differs: sets pendingUpdate state (user must confirm)
  */
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/hooks/useAppVersion.ts` around lines 27 - 36, The JSDoc for useAppVersion
is inaccurate about initial-mount behavior: update only auto-applies on initial
checks when the current route is root ("/"); on non-root routes the hook now
sets pendingUpdate instead of forcing reload. Update the comment block for
useAppVersion to mention route-dependent initial behavior, explicitly state that
on initial mount the stored/version mismatch will auto-update (clear caches +
reload) only when location.pathname === "/" and otherwise will set pendingUpdate
and await user confirmation.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@src/hooks/useAppVersion.ts`:
- Around line 77-84: Update the comment above the else block in useAppVersion to
accurately describe both scenarios it handles: (a) polling checks when isInitial
is false and (b) the initial check when isInitial is true but
window.location.pathname !== "/", i.e., initial non-root routes—clarify that in
these cases we setPendingUpdate(data.version) to notify the user and wait for
confirmation rather than auto-updating via performAppUpdate.
- Around line 27-36: The JSDoc for useAppVersion is inaccurate about
initial-mount behavior: update only auto-applies on initial checks when the
current route is root ("/"); on non-root routes the hook now sets pendingUpdate
instead of forcing reload. Update the comment block for useAppVersion to mention
route-dependent initial behavior, explicitly state that on initial mount the
stored/version mismatch will auto-update (clear caches + reload) only when
location.pathname === "/" and otherwise will set pendingUpdate and await user
confirmation.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: c7f8e45e-d983-4085-bd10-d8705d7b5eec

📥 Commits

Reviewing files that changed from the base of the PR and between fb2f624 and 1d0cafb.

📒 Files selected for processing (1)
  • src/hooks/useAppVersion.ts

@cloudflare-workers-and-pages
Copy link
Copy Markdown

Deploying care-preview with  Cloudflare Pages  Cloudflare Pages

Latest commit: bad57c7
Status: ✅  Deploy successful!
Preview URL: https://a7757ba5.care-preview-a7w.pages.dev
Branch Preview URL: https://eng-397.care-preview-a7w.pages.dev

View logs

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Refines the useAppVersion update flow so that automatic cache clear + reload only happens on the root route (/) during the initial version check, while non-root routes surface an “update available” prompt instead of forcing a reload.

Changes:

  • Restricts initial auto-update behavior to window.location.pathname === "/".
  • Updates hook documentation to reflect differing behavior for root vs non-root routes.

Comment on lines +81 to 86
if (isInitial && window.location.pathname === "/") {
// Initial check on root route: auto-update
performAppUpdate(data.version);
} else {
// Polling check: notify user, wait for confirmation
// Non-root initial check or polling check: notify user, wait for confirmation
setPendingUpdate(data.version);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants