Skip to content

Enhanced ChatGPT Clone: Features Agents, MCP, Skills, DeepSeek, Anthropic, AWS, OpenAI, Responses API, Azure, Groq, o1, GPT-5, Mistral, OpenRouter, Vertex AI, Gemini, Artifacts, AI model switching, message search, Code Interpreter, langchain, DALL-E-3, OpenAPI Actions, Functions, Secure Multi-User Auth, Presets, open-source for self-hosting. Active

🖼️ fix: Precache PWA Icons and Let Them Refresh (#15654)

Marco Berettafdd5f9ce655b
diff --git a/.github/workflows/codegraph-e2e-votes.yml b/.github/workflows/codegraph-e2e-votes.yml
index b3783e2658..251c7a9a71 100644
--- a/.github/workflows/codegraph-e2e-votes.yml
+++ b/.github/workflows/codegraph-e2e-votes.yml
@@ -125,7 +125,7 @@ jobs:
uses: actions/cache@v5
with:
path: client/dist
- key: build-client-app-e2e-${{ runner.os }}-${{ hashFiles('package.json', 'package-lock.json', 'client/src/**', 'client/public/**', 'client/scripts/post-build.cjs', 'client/index.html', 'client/package.json', 'client/vite.config.*', 'client/tsconfig*.json', 'client/tailwind.config.*', 'client/postcss.config.*', 'packages/client/src/**', 'packages/client/tailwind.preset.cjs', 'packages/client/tsconfig*.json', 'packages/client/tsdown.config.mjs', 'packages/client/package.json', 'packages/data-provider/src/**', 'packages/data-provider/tsconfig*.json', 'packages/data-provider/tsdown.config.mjs', 'packages/data-provider/package.json') }}
+ key: build-client-app-e2e-${{ runner.os }}-${{ hashFiles('package.json', 'package-lock.json', 'client/src/**', 'client/public/**', 'client/index.html', 'client/package.json', 'client/vite.config.*', 'client/tsconfig*.json', 'client/tailwind.config.*', 'client/postcss.config.*', 'packages/client/src/**', 'packages/client/tailwind.preset.cjs', 'packages/client/tsconfig*.json', 'packages/client/tsdown.config.mjs', 'packages/client/package.json', 'packages/data-provider/src/**', 'packages/data-provider/tsconfig*.json', 'packages/data-provider/tsdown.config.mjs', 'packages/data-provider/package.json') }}
- name: Build client app
if: steps.cache-client-app.outputs.cache-hit != 'true'
diff --git a/.github/workflows/playwright-bombadil.yml b/.github/workflows/playwright-bombadil.yml
index 064a3141dc..0f37ff1b11 100644
--- a/.github/workflows/playwright-bombadil.yml
+++ b/.github/workflows/playwright-bombadil.yml
@@ -113,7 +113,7 @@ jobs:
uses: actions/cache@v4
with:
path: client/dist
- key: build-client-app-e2e-${{ runner.os }}-${{ hashFiles('package.json', 'package-lock.json', 'client/src/**', 'client/public/**', 'client/scripts/post-build.cjs', 'client/index.html', 'client/package.json', 'client/vite.config.*', 'client/tsconfig*.json', 'client/tailwind.config.*', 'client/postcss.config.*', 'packages/client/src/**', 'packages/client/tailwind.preset.cjs', 'packages/client/tsconfig*.json', 'packages/client/tsdown.config.mjs', 'packages/client/package.json', 'packages/data-provider/src/**', 'packages/data-provider/tsconfig*.json', 'packages/data-provider/tsdown.config.mjs', 'packages/data-provider/package.json') }}
+ key: build-client-app-e2e-${{ runner.os }}-${{ hashFiles('package.json', 'package-lock.json', 'client/src/**', 'client/public/**', 'client/index.html', 'client/package.json', 'client/vite.config.*', 'client/tsconfig*.json', 'client/tailwind.config.*', 'client/postcss.config.*', 'packages/client/src/**', 'packages/client/tailwind.preset.cjs', 'packages/client/tsconfig*.json', 'packages/client/tsdown.config.mjs', 'packages/client/package.json', 'packages/data-provider/src/**', 'packages/data-provider/tsconfig*.json', 'packages/data-provider/tsdown.config.mjs', 'packages/data-provider/package.json') }}
- name: Build client app
if: steps.cache-client-app.outputs.cache-hit != 'true'
diff --git a/.github/workflows/playwright-mock.yml b/.github/workflows/playwright-mock.yml
index 2d6de6b197..acb62732b1 100644
--- a/.github/workflows/playwright-mock.yml
+++ b/.github/workflows/playwright-mock.yml
@@ -260,7 +260,7 @@ jobs:
uses: actions/cache@v5
with:
path: client/dist
- key: build-client-app-e2e-${{ runner.os }}-${{ hashFiles('package.json', 'package-lock.json', 'client/src/**', 'client/public/**', 'client/scripts/post-build.cjs', 'client/index.html', 'client/package.json', 'client/vite.config.*', 'client/tsconfig*.json', 'client/tailwind.config.*', 'client/postcss.config.*', 'packages/client/src/**', 'packages/client/tailwind.preset.cjs', 'packages/client/tsconfig*.json', 'packages/client/tsdown.config.mjs', 'packages/client/package.json', 'packages/data-provider/src/**', 'packages/data-provider/tsconfig*.json', 'packages/data-provider/tsdown.config.mjs', 'packages/data-provider/package.json') }}
+ key: build-client-app-e2e-${{ runner.os }}-${{ hashFiles('package.json', 'package-lock.json', 'client/src/**', 'client/public/**', 'client/index.html', 'client/package.json', 'client/vite.config.*', 'client/tsconfig*.json', 'client/tailwind.config.*', 'client/postcss.config.*', 'packages/client/src/**', 'packages/client/tailwind.preset.cjs', 'packages/client/tsconfig*.json', 'packages/client/tsdown.config.mjs', 'packages/client/package.json', 'packages/data-provider/src/**', 'packages/data-provider/tsconfig*.json', 'packages/data-provider/tsdown.config.mjs', 'packages/data-provider/package.json') }}
- name: Build client app
if: steps.cache-client-app.outputs.cache-hit != 'true'
diff --git a/bun.lock b/bun.lock
index 3950b99681..c024ae7812 100644
--- a/bun.lock
+++ b/bun.lock
@@ -276,7 +276,6 @@
"babel-plugin-transform-import-meta": "^2.3.2",
"babel-plugin-transform-vite-meta-env": "^1.0.3",
"eslint-plugin-jest": "^29.1.0",
- "fs-extra": "^11.3.2",
"identity-obj-proxy": "^3.0.0",
"jest": "^30.2.0",
"jest-canvas-mock": "^2.5.2",
@@ -3296,8 +3295,6 @@
"fresh": ["[email protected]", "", {}, "sha512-Rx/WycZ60HOaqLKAi6cHRKKI7zxWbJ31MhntmtwMoaTeF7XFH9hhBp8vITaMidfljRQ6eYWCKkaTK+ykVJHP2A=="],
- "fs-extra": ["[email protected]", "", { "dependencies": { "graceful-fs": "^4.2.0", "jsonfile": "^6.0.1", "universalify": "^2.0.0" } }, "sha512-Xr9F6z6up6Ws+NjzMCZc6WXg2YFRlrLP9NQDO3VQrWrfiojdhS56TzueT88ze0uBdCTwEIhQ3ptnmKeWGFAe0A=="],
-
"fsevents": ["[email protected]", "", { "os": "darwin" }, "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw=="],
"function-bind": ["[email protected]", "", {}, "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA=="],
diff --git a/client/package.json b/client/package.json
index 0e73dbb04c..347c432552 100644
--- a/client/package.json
+++ b/client/package.json
@@ -7,7 +7,7 @@
"typecheck": "tsc --noEmit",
"data-provider": "cd .. && npm run build:data-provider",
"build:file": "cross-env NODE_ENV=production vite build --debug > vite-output.log 2>&1",
- "build": "cross-env NODE_ENV=production NODE_OPTIONS=--max-old-space-size=8192 vite build && node ./scripts/post-build.cjs",
+ "build": "cross-env NODE_ENV=production NODE_OPTIONS=--max-old-space-size=8192 vite build",
"build:ci": "cross-env NODE_ENV=development vite build --mode ci",
"dev": "cross-env NODE_ENV=development vite",
"preview-prod": "cross-env NODE_ENV=development vite preview",
@@ -156,7 +156,6 @@
"babel-plugin-transform-import-meta": "^2.3.2",
"babel-plugin-transform-vite-meta-env": "^1.0.3",
"eslint-plugin-jest": "^29.1.0",
- "fs-extra": "^11.3.2",
"identity-obj-proxy": "^3.0.0",
"jest": "^30.2.0",
"jest-canvas-mock": "^2.5.2",
diff --git a/client/scripts/post-build.cjs b/client/scripts/post-build.cjs
deleted file mode 100644
index 0c0f00dc14..0000000000
--- a/client/scripts/post-build.cjs
+++ /dev/null
@@ -1,14 +0,0 @@
-const fs = require('fs-extra');
-
-async function postBuild() {
- try {
- await fs.copy('public/assets', 'dist/assets');
- await fs.copy('public/robots.txt', 'dist/robots.txt');
- console.log('✅ PWA icons and robots.txt copied successfully. Glob pattern warnings resolved.');
- } catch (err) {
- console.error('❌ Error copying files:', err);
- process.exit(1);
- }
-}
-
-postBuild();
diff --git a/client/vite.config.ts b/client/vite.config.ts
index 4f39f2653c..5a279a92ca 100644
--- a/client/vite.config.ts
+++ b/client/vite.config.ts
@@ -89,6 +89,7 @@ export default defineConfig(({ command }) => ({
});
},
},
+ copyPublicAssets(),
VitePWA({
injectRegister: 'auto', // 'auto' | 'manual' | 'disabled'
registerType: 'autoUpdate', // 'prompt' | 'autoUpdate'
@@ -103,8 +104,9 @@ export default defineConfig(({ command }) => ({
'assets/favicon*.png',
'assets/icon-*.png',
'assets/apple-touch-icon*.png',
+ /** `manifest.webmanifest` is not listed: vite-plugin-pwa always appends it as an
+ * additional manifest entry, so globbing it too duplicates the precache entry. */
'assets/maskable-icon.png',
- 'manifest.webmanifest',
],
globIgnores: [
'images/**/*',
@@ -116,6 +118,14 @@ export default defineConfig(({ command }) => ({
'assets/query-devtools*.js',
],
maximumFileSizeToCacheInBytes: 4 * 1024 * 1024,
+ /**
+ * vite-plugin-pwa defaults this to `/^assets\//`, which is only true for the
+ * hashed bundle output: the icons live in `assets/` under stable filenames, so the
+ * default marks them immutable (`revision: null`) and an installed PWA would keep
+ * a rebranded icon forever. Match Vite's `[name].[hash].[ext]` shape instead so
+ * hashed chunks stay revision-free while the icons get content revisions.
+ */
+ dontCacheBustURLsMatching: /\.[\w-]{8}\.(?:js|css)$/,
/** LibreChat mutates index.html per request for subpath and language support. */
navigateFallback: null,
/** Reloads window clients that cannot answer a ping after activation —
@@ -447,3 +457,38 @@ export function sourcemapExclude(opts?: SourcemapExclude): Plugin {
},
};
}
+
+/**
+ * Production builds set `publicDir: false`, so nothing under public/ reaches dist on its
+ * own. This copies what the server actually has to serve: all of public/assets (the PWA
+ * icons plus the endpoint, tool and language logos referenced at runtime) and robots.txt.
+ * public/fonts is deliberately left out, since fonts are emitted as bundle assets through
+ * the `$fonts` alias.
+ *
+ * The copy MUST happen inside the build. vite-plugin-pwa globs dist/ for
+ * `workbox.globPatterns` from its `closeBundle` hook, which runs after every plugin's
+ * `writeBundle`, so copying here is what lets the `assets/*.png` icon patterns match. An
+ * `npm run build && node scripts/post-build.cjs` chain cannot: it runs after the service
+ * worker has already been generated, so the icons were silently absent from the precache
+ * manifest.
+ */
+export function copyPublicAssets(): Plugin {
+ const publicDir = path.resolve(import.meta.dirname, 'public');
+ let outDir = path.resolve(import.meta.dirname, 'dist');
+ return {
+ name: 'copy-public-assets',
+ apply: 'build',
+ configResolved(config) {
+ outDir = path.resolve(config.root, config.build.outDir);
+ },
+ async writeBundle() {
+ await fs.promises.cp(path.join(publicDir, 'assets'), path.join(outDir, 'assets'), {
+ recursive: true,
+ });
+ await fs.promises.copyFile(
+ path.join(publicDir, 'robots.txt'),
+ path.join(outDir, 'robots.txt'),
+ );
+ },
+ };
+}
diff --git a/package-lock.json b/package-lock.json
index 465f677018..5ebcebfa50 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1054,7 +1054,6 @@
"babel-plugin-transform-import-meta": "^2.3.2",
"babel-plugin-transform-vite-meta-env": "^1.0.3",
"eslint-plugin-jest": "^29.1.0",
- "fs-extra": "^11.3.2",
"identity-obj-proxy": "^3.0.0",
"jest": "^30.2.0",
"jest-canvas-mock": "^2.5.2",
@@ -26547,21 +26546,6 @@
"node": ">= 0.6"
}
},
- "node_modules/fs-extra": {
- "version": "11.3.2",
- "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-11.3.2.tgz",
- "integrity": "sha512-Xr9F6z6up6Ws+NjzMCZc6WXg2YFRlrLP9NQDO3VQrWrfiojdhS56TzueT88ze0uBdCTwEIhQ3ptnmKeWGFAe0A==",
- "dev": true,
- "license": "MIT",
- "dependencies": {
- "graceful-fs": "^4.2.0",
- "jsonfile": "^6.0.1",
- "universalify": "^2.0.0"
- },
- "engines": {
- "node": ">=14.14"
- }
- },
"node_modules/fsevents": {
"version": "2.3.3",
"resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz",