🐛 Fix Service Worker: New hash every build#5928
Conversation
✅ Deploy Preview for actualbudget ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Walkthrough
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested reviewers
Pre-merge checks and finishing touches✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
|
🤖 Auto-generated Release Notes Hey @lelemm! I've automatically created a release notes file based on CodeRabbit's analysis: Category: Bugfix 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. |
Bundle Stats — desktop-clientHey 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
Changeset No files were changed View detailed bundle breakdownAdded No assets were added Removed No assets were removed Bigger No assets were bigger Smaller No assets were smaller Unchanged
|
Bundle Stats — loot-coreHey 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
Changeset No files were changed View detailed bundle breakdownAdded No assets were added Removed No assets were removed Bigger No assets were bigger Smaller No assets were smaller Unchanged
|
There was a problem hiding this comment.
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
⛔ Files ignored due to path filters (1)
upcoming-release-notes/5928.mdis 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
Prefertypealiases overinterface
Avoidenum; use objects or maps instead
Avoid usinganyorunknownunless absolutely necessary; prefer existing type definitions
Avoid type assertions withasor non-null!; prefer usingsatisfies
Use thefunctionkeyword 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 registersplugin-sw.${buildHash}.js(rather than a static path) so the SW loads in production.
There was a problem hiding this comment.
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_SHAin 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
📒 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
.tsto.mtsaligns 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.
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.