Skip to content

Conversation

@msynk
Copy link
Member

@msynk msynk commented Dec 11, 2025

closes #11870

Summary by CodeRabbit

Release Notes

  • Bug Fixes

    • Improved service worker reliability with additional safety measures to prevent errors during message handling.
  • Refactor

    • Enhanced cache cleanup mechanism to efficiently remove outdated caches during service worker updates and application lifecycle.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Dec 11, 2025

Walkthrough

The pull request introduces a cleanup command to the Bswup service worker system. Changes span two related files: the service worker script now handles a new 'CLEAN_UP' inter-process message to trigger cache deletion, while the main registration script creates a cleanup callback that sends this message to active and waiting service worker states.

Changes

Cohort / File(s) Summary
Cleanup command implementation
src/Bswup/Bit.Bswup/Scripts/bit-bswup.sw.ts, src/Bswup/Bit.Bswup/Scripts/bit-bswup.ts
Added inter-process messaging to trigger cache cleanup independent of reload. Service worker listens for 'CLEAN_UP' message and invokes deleteOldCaches(). Main script provides cleanup callback that posts messages to active/waiting service worker registrations using optional chaining. Cleanup callback integrated into download completion notification flow. BOM character removed from service worker version line.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Optional chaining usage in message posting — verify null-safety handling is consistent
  • Service worker message handler logic — ensure CLEAN_UP message dispatch doesn't conflict with other messaging patterns
  • Integration of cleanup callback in notification payload — confirm it's passed correctly in both "downloadFinished" and "bypass" code paths

Poem

🐰 Cleanup hops in, a new command to stay,
No reload required—the modern way!
Messages whisper 'tween worker and code,
Old caches fade down the storage road,
Keeping your app both swift and light.

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Add cleanup command (#11870)' directly matches the main objective of adding a new cleanup command to Bswup, clearly summarizing the primary change.
Linked Issues check ✅ Passed The PR implements all requirements from issue #11870: adds a cleanup command, provides it alongside the reload command, and enables storage control when reload is inappropriate.
Out of Scope Changes check ✅ Passed All changes are focused on implementing the cleanup functionality: removing a BOM character, adding CLEAN_UP message handling, and integrating cleanup with service worker registration.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent 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 98d867b and b24be9d.

📒 Files selected for processing (2)
  • src/Bswup/Bit.Bswup/Scripts/bit-bswup.sw.ts (2 hunks)
  • src/Bswup/Bit.Bswup/Scripts/bit-bswup.ts (5 hunks)
🧰 Additional context used
🪛 Biome (2.1.2)
src/Bswup/Bit.Bswup/Scripts/bit-bswup.ts

[error] 1-1: This variable is used before its declaration.

The variable is declared here:

(lint/correctness/noInvalidUseBeforeDeclaration)

🔇 Additional comments (6)
src/Bswup/Bit.Bswup/Scripts/bit-bswup.sw.ts (2)

1-1: LGTM! BOM character removal.

Removing the BOM (Byte Order Mark) character is a good cleanup that prevents potential encoding issues.


236-238: LGTM! Clean implementation of the CLEAN_UP handler.

The new message handler correctly triggers cache cleanup. The fire-and-forget pattern (not awaiting deleteOldCaches()) is consistent with existing usage at lines 223 and 228.

src/Bswup/Bit.Bswup/Scripts/bit-bswup.ts (4)

22-22: LGTM! Cleanup callback declaration.

The cleanup callback follows the same pattern as the reload callback, maintaining consistency in the codebase.


43-43: LGTM! Defensive improvement with optional chaining.

Adding optional chaining prevents potential runtime errors if reg.waiting is undefined, improving code robustness.


55-58: LGTM! Cleanup implementation is sound.

The cleanup callback correctly posts CLEAN_UP messages to both waiting and active service workers with appropriate optional chaining. Sending to both states ensures cleanup runs regardless of the service worker's current lifecycle state.


137-137: LGTM! Cleanup callback exposed to handlers.

Adding the cleanup callback to the downloadFinished payload allows consumers to manage storage cleanup independently from reload operations, fulfilling the PR's objective of providing control in scenarios where reload is not appropriate.

Also applies to: 143-143


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

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

@msynk msynk marked this pull request as draft December 11, 2025 12:02
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.

The Bswup needs a new cleanup command

1 participant