Skip to content

Fix service workers not working after upgrading to rsbuild #3143

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jun 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
"yareco": "^0.1.5"
},
"devDependencies": {
"@aaroon/workbox-rspack-plugin": "^0.3.2",
"@babel/core": "^7.24.5",
"@babel/plugin-proposal-private-property-in-object": "^7.21.11",
"@babel/preset-typescript": "^7.24.1",
Expand Down
10 changes: 10 additions & 0 deletions rsbuild.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { pluginNodePolyfill } from '@rsbuild/plugin-node-polyfill';
import { pluginReact } from '@rsbuild/plugin-react';
import { pluginSass } from '@rsbuild/plugin-sass';
import { pluginSvgr } from '@rsbuild/plugin-svgr';
import { InjectManifest } from '@aaroon/workbox-rspack-plugin';

const { publicVars, rawPublicVars } = loadEnv({ prefixes: ['REACT_APP_'] });

Expand Down Expand Up @@ -118,6 +119,15 @@ export default defineConfig({
// })
// ];

config.plugins = [
...config.plugins,
new InjectManifest({
swSrc: './src/service-worker.ts',
swDest: 'service-worker.js',
maximumFileSizeToCacheInBytes: 20 * 1024 * 1024,
})
];

// Workaround to suppress warnings caused by ts-morph in js-slang
// if (config.module) {
// config.module.noParse = /node_modules\/@ts-morph\/common\/dist\/typescript\.js$/;
Expand Down
2 changes: 1 addition & 1 deletion src/service-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ registerRoute(
// Return true to signal that we want to use the handler.
return true;
},
createHandlerBoundToURL(process.env.PUBLIC_URL + '/index.html')
createHandlerBoundToURL((process.env.PUBLIC_URL || '') + '/index.html')
);

// This allows the web app to trigger skipWaiting via
Expand Down
Loading
Loading