Skip to content

Conversation

@ysmoradi
Copy link
Member

@ysmoradi ysmoradi commented Jul 22, 2025

closes #11159

Summary by CodeRabbit

  • New Features

    • Introduced improved handling of Progressive Web App (PWA) updates, including automatic update checks and optimized app reloads based on user activity.
  • Refactor

    • Streamlined update logic for better reliability and maintainability.
    • Adjusted integration with update-related JavaScript functions for consistency.

@ysmoradi ysmoradi requested a review from Copilot July 22, 2025 14:38
@coderabbitai
Copy link

coderabbitai bot commented Jul 22, 2025

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The update removes the static forceUpdate method from the App class and introduces a new bswup.ts script to handle PWA update logic, including periodic checks and background-aware reloads. Additionally, a service method updates its JavaScript invocation to match the new function name and casing.

Changes

File(s) Change Summary
.../Boilerplate.Client.Core/Scripts/app.ts Removed the static forceUpdate method from the App class.
.../Boilerplate.Client.Core/Scripts/bswup.ts Added new script to manage PWA updates with periodic checks, event listeners, and reload control.
.../Boilerplate.Client.Web/Services/WebAppUpdateService.cs Updated JS interop call to use the new function name tryUpdatingPwa (casing change).

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant App (Browser)
    participant bswup.ts
    participant BitBswup
    participant BitBswupProgress

    Note over App (Browser): On page load and periodically (every minute)
    App (Browser)->>bswup.ts: Invoke tryUpdatingPwa(autoReload)
    bswup.ts->>BitBswup: skipWaiting()
    alt skipWaiting returns falsy
        bswup.ts->>BitBswupProgress: configure({ autoReload })
        bswup.ts->>BitBswup: checkForUpdate()
    end
    Note over bswup.ts: On beforeunload, always autoReload
    Note over bswup.ts: Tracks app visibility to control reloads
Loading

Estimated code review effort

2 (~15 minutes)

Poem

A bunny hops through scripts anew,
With updates checked and timers true.
Old forceUpdate has hopped away,
While bswup keeps bugs at bay.
In background or in view,
The app refreshes—swift and new!
🐇✨

✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
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

This PR enhances the bit Boilerplate Bswup (Blazor Service Worker Update Progressive) functionality by refactoring the update mechanism and improving automatic update capabilities. The changes consolidate update logic into a dedicated TypeScript module while maintaining backward compatibility.

Key changes:

  • Consolidated PWA update logic into a dedicated bswup.ts module with enhanced automatic update strategies
  • Updated C# service to use the new function name for consistency
  • Removed duplicate update functionality from the main app module

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
WebAppUpdateService.cs Updated JavaScript function call to match new naming convention
bswup.ts New dedicated module implementing comprehensive PWA update logic with background detection and automatic updates
app.ts Removed duplicate forceUpdate method that's now handled by the dedicated bswup module

Copy link

@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.

Actionable comments posted: 1

🧹 Nitpick comments (2)
src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Core/Scripts/bswup.ts (2)

16-18: beforeunload handler’s async work is likely discarded.

Browsers ignore unresolved promises during beforeunload; the update check may never complete.
Consider switching to a synchronous hint (e.g., sendBeacon) or rely solely on the periodic background timer.


32-33: Hard-coded 1-minute polling interval—make configurable.

Frequent network polling can drain mobile batteries. Expose the interval via a constant or configuration so teams can tune it without touching source.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Knowledge Base: Disabled due to Reviews > Disable Knowledge Base setting

📥 Commits

Reviewing files that changed from the base of the PR and between b8efe19 and 3a2d181.

📒 Files selected for processing (3)
  • src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Core/Scripts/app.ts (0 hunks)
  • src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Core/Scripts/bswup.ts (1 hunks)
  • src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Web/Services/WebAppUpdateService.cs (1 hunks)
💤 Files with no reviewable changes (1)
  • src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Core/Scripts/app.ts
🔇 Additional comments (1)
src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Web/Services/WebAppUpdateService.cs (1)

8-11: Confirm JS interop binding exists (case-sensitive).

The C# side now looks for a global JS function named tryUpdatingPwa.
If bswup.ts is compiled as an ES module (default for TypeScript files that use import/export syntax or have "module": "esnext" in tsconfig), the function will be scoped to the module and won’t be attached to window, causing a JSDisconnectedException at runtime.

Please verify that the build pipeline outputs bswup.js as a classic script (or explicitly attach the function):

 async function tryUpdatingPwa(autoReload?: boolean) { … }

+// Make the function visible to Blazor-JS interop
+(window as any).tryUpdatingPwa = tryUpdatingPwa;

@ysmoradi ysmoradi merged commit 17fba2d into bitfoundation:develop Jul 22, 2025
3 checks passed
@ysmoradi ysmoradi deleted the boilerplate-bswup branch July 22, 2025 18:56
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.

bit Boilerplate Bswup update needs enahncements

1 participant