Skip to content

🐛 Fix Service Worker: New hash every build#5928

Merged
lelemm merged 6 commits intomasterfrom
bugfix/force-plugins-service-force-hash
Oct 15, 2025
Merged

🐛 Fix Service Worker: New hash every build#5928
lelemm merged 6 commits intomasterfrom
bugfix/force-plugins-service-force-hash

Conversation

@lelemm
Copy link
Copy Markdown
Member

@lelemm lelemm commented Oct 15, 2025

Introduction of the plugin service worker is impacting the app to recognize new versions. It was generating using [hash] syntax for vite. But hash is the checksum of the file. Since this file won't change and it's part of the service worker, it's keeping the same hash but we have changes on the "rest" of the sw.

This PR forces a new hash every build to ensure that any changes to the SW will be catch by the browser.

@actual-github-bot actual-github-bot Bot changed the title 🐛 Fix Service Worker: New hash every build [WIP] 🐛 Fix Service Worker: New hash every build Oct 15, 2025
@netlify
Copy link
Copy Markdown

netlify Bot commented Oct 15, 2025

Deploy Preview for actualbudget ready!

Name Link
🔨 Latest commit 5c6b725
🔍 Latest deploy log https://app.netlify.com/projects/actualbudget/deploys/68ef0d0a8479360008f5e2aa
😎 Deploy Preview https://deploy-preview-5928.demo.actualbudget.org
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@lelemm lelemm changed the title [WIP] 🐛 Fix Service Worker: New hash every build 🐛 Fix Service Worker: New hash every build Oct 15, 2025
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Oct 15, 2025

Walkthrough

  • packages/plugins-service/bin/build-service-worker: Switches Vite build to use ../vite.config.mts instead of ../vite.config.ts; other args unchanged.
  • packages/plugins-service/vite.config.mts: Adds a buildHash constant derived from Date.now().toString(36). Uses buildHash in the production plugin service worker filename, replacing a previously static hash. Development filename behavior (plugin-sw.dev.js) remains unchanged. No other config logic changes.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested reviewers

  • joel-jeremy

Pre-merge checks and finishing touches

✅ Passed checks (2 passed)
Check name Status Explanation
Title Check ✅ Passed The title succinctly conveys the primary change of forcing a new hash on each service worker build to address versioning issues; it clearly identifies the component and the nature of the fix without overloading with details.
Description Check ✅ Passed The description is directly related to the changeset, explaining why the default checksum-based hash was insufficient for the service worker and how forcing a new hash on each build resolves the issue.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch bugfix/force-plugins-service-force-hash

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.

@github-actions
Copy link
Copy Markdown
Contributor

🤖 Auto-generated Release Notes

Hey @lelemm! I've automatically created a release notes file based on CodeRabbit's analysis:

Category: Bugfix
Summary: Fix service worker to generate a new hash with every build for better caching.
File: upcoming-release-notes/5928.md

If you're happy with this release note, you can add it to your pull request. If not, you'll need to add your own before a maintainer can review your change.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Oct 15, 2025

Bundle Stats — desktop-client

Hey there, this message comes from a GitHub action that helps you and reviewers to understand how these changes affect the size of this project's bundle.

As this PR is updated, I'll keep you updated on how the bundle size is impacted.

Total

Files count Total bundle size % Changed
23 10.82 MB 0%

Changeset

No files were changed

View detailed bundle breakdown

Added

No assets were added

Removed

No assets were removed

Bigger

No assets were bigger

Smaller

No assets were smaller

Unchanged

Asset File Size % Changed
static/js/index.js 7.41 MB 0%
static/js/de.js 145.15 kB 0%
static/js/en-GB.js 6.84 kB 0%
static/js/en.js 132.54 kB 0%
static/js/es.js 76.53 kB 0%
static/js/fr.js 154.21 kB 0%
static/js/it.js 145.98 kB 0%
static/js/nl.js 100.38 kB 0%
static/js/pl.js 86.74 kB 0%
static/js/pt-BR.js 146.51 kB 0%
static/js/sv.js 69.03 kB 0%
static/js/th.js 188.29 kB 0%
static/js/uk.js 191.53 kB 0%
static/js/indexeddb-main-thread-worker-e59fee74.js 12.94 kB 0%
static/js/workbox-window.prod.es5.js 5.64 kB 0%
static/js/resize-observer.js 18.37 kB 0%
static/js/BackgroundImage.js 120.48 kB 0%
static/js/ReportRouter.js 1.01 MB 0%
static/js/narrow.js 653.15 kB 0%
static/js/TransactionList.js 13.87 kB 0%
static/js/wide.js 168.68 kB 0%
static/js/usePayeeRuleCounts.js 9.04 kB 0%
static/js/useTransactionBatchActions.js 13.09 kB 0%

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Oct 15, 2025

Bundle Stats — loot-core

Hey there, this message comes from a GitHub action that helps you and reviewers to understand how these changes affect the size of this project's bundle.

As this PR is updated, I'll keep you updated on how the bundle size is impacted.

Total

Files count Total bundle size % Changed
1 4.31 MB 0%

Changeset

No files were changed

View detailed bundle breakdown

Added

No assets were added

Removed

No assets were removed

Bigger

No assets were bigger

Smaller

No assets were smaller

Unchanged

Asset File Size % Changed
kcab.worker.C_13DhnM.js 4.31 MB 0%

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.

Actionable comments posted: 0

🧹 Nitpick comments (1)
packages/plugins-service/vite.config.ts (1)

10-10: Consider adding a comment to document the timestamp-based approach.

The timestamp-based hash ensures every build generates a unique filename, which forces browsers to recognize new service worker versions. However, this approach makes builds non-deterministic and breaks reproducibility.

Consider adding a brief comment explaining why a timestamp is used instead of a content-based hash:

+  // Use timestamp-based hash to force unique filename on every build,
+  // ensuring browsers detect service worker updates even when content is unchanged
   const buildHash = Date.now().toString(36);
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 328dfae and 057e7ef.

⛔ Files ignored due to path filters (1)
  • upcoming-release-notes/5928.md is excluded by !**/*.md
📒 Files selected for processing (1)
  • packages/plugins-service/vite.config.ts (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/typescript.mdc)

**/*.{ts,tsx}: Use functional and declarative programming patterns; avoid classes
Favor named exports for components and utilities
Prefer type aliases over interface
Avoid enum; use objects or maps instead
Avoid using any or unknown unless absolutely necessary; prefer existing type definitions
Avoid type assertions with as or non-null !; prefer using satisfies
Use the function keyword for pure functions
Avoid unnecessary curly braces in conditionals; use concise syntax for simple statements

Files:

  • packages/plugins-service/vite.config.ts
🧬 Code graph analysis (1)
packages/plugins-service/vite.config.ts (1)
packages/desktop-client/src/browser-server.js (1)
  • isDev (63-63)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (10)
  • GitHub Check: build (macos-latest)
  • GitHub Check: build (ubuntu-22.04)
  • GitHub Check: build (windows-latest)
  • GitHub Check: Functional Desktop App
  • GitHub Check: Wait for Netlify build to finish
  • GitHub Check: validate-cli
  • GitHub Check: test
  • GitHub Check: Analyze
  • GitHub Check: web
  • GitHub Check: compare
🔇 Additional comments (1)
packages/plugins-service/vite.config.ts (1)

22-23: Ensure service worker registration discovers the hashed filename
Confirm that the consuming application (e.g. desktop-client) dynamically resolves and registers plugin-sw.${buildHash}.js (rather than a static path) so the SW loads in production.

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.

Actionable comments posted: 0

🧹 Nitpick comments (1)
packages/plugins-service/vite.config.mts (1)

9-9: Approve with suggestion: Consider git commit hash for reproducibility.

The timestamp-based hash successfully achieves the goal of forcing a new hash every build, ensuring the browser detects service worker changes. However, this approach breaks build reproducibility—identical source code will produce different artifacts at different times.

Consider using a git commit hash instead for more deterministic builds:

-  const buildHash = Date.now().toString(36);
+  const buildHash = process.env.VITE_GIT_COMMIT_SHA?.slice(0, 8) || Date.now().toString(36);

Then set VITE_GIT_COMMIT_SHA in your build process:

#!/bin/bash
# In build-service-worker script, before the vite build command:
export VITE_GIT_COMMIT_SHA=$(git rev-parse HEAD)

This provides deterministic builds from the same commit while still ensuring unique hashes across different commits. The timestamp fallback ensures builds work even without git.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 057e7ef and 5c6b725.

📒 Files selected for processing (2)
  • packages/plugins-service/bin/build-service-worker (1 hunks)
  • packages/plugins-service/vite.config.mts (2 hunks)
🔇 Additional comments (2)
packages/plugins-service/bin/build-service-worker (1)

22-22: LGTM! Config path correctly updated.

The file extension change from .ts to .mts aligns with the new configuration file and ensures the build script references the correct Vite config.

packages/plugins-service/vite.config.mts (1)

21-22: LGTM! Filename logic correctly implements cache busting.

The fileName logic correctly applies the build hash only in production mode while keeping the dev filename static (plugin-sw.dev.js), which is appropriate for development workflows.

Copy link
Copy Markdown
Member

@matt-fidd matt-fidd left a comment

Choose a reason for hiding this comment

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

lgtm

@lelemm lelemm merged commit 96ac129 into master Oct 15, 2025
24 checks passed
@lelemm lelemm deleted the bugfix/force-plugins-service-force-hash branch October 15, 2025 16:11
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.

2 participants