Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

fix(web): add rewrite rule to fix Serwist precaching 404 errors (#31770)

lif9e54f086dc4b
diff --git a/web/app/serwist/[path]/route.ts b/web/app/serwist/[path]/route.ts
index ad371756b59..beca2cd412a 100644
--- a/web/app/serwist/[path]/route.ts
+++ b/web/app/serwist/[path]/route.ts
@@ -1,14 +1,11 @@
-import { spawnSync } from 'node:child_process'
-import { randomUUID } from 'node:crypto'
import { createSerwistRoute } from '@serwist/turbopack'
const basePath = process.env.NEXT_PUBLIC_BASE_PATH || ''
-const revision = spawnSync('git', ['rev-parse', 'HEAD'], { encoding: 'utf-8' }).stdout?.trim() || randomUUID()
export const { dynamic, dynamicParams, revalidate, generateStaticParams, GET } = createSerwistRoute({
- additionalPrecacheEntries: [{ url: `${basePath}/_offline.html`, revision }],
swSrc: 'app/sw.ts',
nextConfig: {
basePath,
},
+ useNativeEsbuild: true,
})
diff --git a/web/app/sw.ts b/web/app/sw.ts
index 99ef2c35444..f4011ee2248 100644
--- a/web/app/sw.ts
+++ b/web/app/sw.ts
@@ -3,7 +3,9 @@
/// <reference lib="webworker" />
import type { PrecacheEntry, SerwistGlobalConfig } from 'serwist'
-import { CacheableResponsePlugin, CacheFirst, ExpirationPlugin, NetworkFirst, Serwist, StaleWhileRevalidate } from 'serwist'
+import { defaultCache } from '@serwist/turbopack/worker'
+import { Serwist } from 'serwist'
+import { withLeadingSlash } from 'ufo'
declare global {
// eslint-disable-next-line ts/consistent-type-definitions
@@ -18,78 +20,30 @@ const scopePathname = new URL(self.registration.scope).pathname
const basePath = scopePathname.replace(/\/serwist\/$/, '').replace(/\/$/, '')
const offlineUrl = `${basePath}/_offline.html`
+const normalizeManifestUrl = (url: string): string => {
+ if (url.startsWith('/serwist/'))
+ return url.replace(/^\/serwist\//, '/')
+
+ return withLeadingSlash(url)
+}
+
+const manifest = self.__SW_MANIFEST?.map((entry) => {
+ if (typeof entry === 'string')
+ return normalizeManifestUrl(entry)
+
+ return {
+ ...entry,
+ url: normalizeManifestUrl(entry.url),
+ }
+})
+
const serwist = new Serwist({
- precacheEntries: self.__SW_MANIFEST,
+ precacheEntries: manifest,
skipWaiting: true,
disableDevLogs: true,
clientsClaim: true,
navigationPreload: true,
- runtimeCaching: [
- {
- matcher: ({ url }) => url.origin === 'https://fonts.googleapis.com',
- handler: new CacheFirst({
- cacheName: 'google-fonts',
- plugins: [
- new CacheableResponsePlugin({ statuses: [0, 200] }),
- new ExpirationPlugin({
- maxEntries: 4,
- maxAgeSeconds: 365 * 24 * 60 * 60,
- }),
- ],
- }),
- },
- {
- matcher: ({ url }) => url.origin === 'https://fonts.gstatic.com',
- handler: new CacheFirst({
- cacheName: 'google-fonts-webfonts',
- plugins: [
- new CacheableResponsePlugin({ statuses: [0, 200] }),
- new ExpirationPlugin({
- maxEntries: 4,
- maxAgeSeconds: 365 * 24 * 60 * 60,
- }),
- ],
- }),
- },
- {
- matcher: ({ request }) => request.destination === 'image',
- handler: new CacheFirst({
- cacheName: 'images',
- plugins: [
- new CacheableResponsePlugin({ statuses: [0, 200] }),
- new ExpirationPlugin({
- maxEntries: 64,
- maxAgeSeconds: 30 * 24 * 60 * 60,
- }),
- ],
- }),
- },
- {
- matcher: ({ request }) => request.destination === 'script' || request.destination === 'style',
- handler: new StaleWhileRevalidate({
- cacheName: 'static-resources',
- plugins: [
- new ExpirationPlugin({
- maxEntries: 32,
- maxAgeSeconds: 24 * 60 * 60,
- }),
- ],
- }),
- },
- {
- matcher: ({ url, sameOrigin }) => sameOrigin && url.pathname.startsWith('/api/'),
- handler: new NetworkFirst({
- cacheName: 'api-cache',
- networkTimeoutSeconds: 10,
- plugins: [
- new ExpirationPlugin({
- maxEntries: 16,
- maxAgeSeconds: 60 * 60,
- }),
- ],
- }),
- },
- ],
+ runtimeCaching: defaultCache,
fallbacks: {
entries: [
{
diff --git a/web/next.config.ts b/web/next.config.ts
index 05f4158ac84..0bbdbaf32c8 100644
--- a/web/next.config.ts
+++ b/web/next.config.ts
@@ -29,7 +29,7 @@ const remoteImageURLs = ([hasSetWebPrefix ? new URL(`${process.env.NEXT_PUBLIC_W
const nextConfig: NextConfig = {
basePath: process.env.NEXT_PUBLIC_BASE_PATH || '',
- serverExternalPackages: ['esbuild-wasm'],
+ serverExternalPackages: ['esbuild'],
transpilePackages: ['echarts', 'zrender'],
turbopack: {
rules: codeInspectorPlugin({
diff --git a/web/package.json b/web/package.json
index b37a46681f0..c85de48b5d9 100644
--- a/web/package.json
+++ b/web/package.json
@@ -156,6 +156,7 @@
"string-ts": "2.3.1",
"tailwind-merge": "2.6.0",
"tldts": "7.0.17",
+ "ufo": "1.6.3",
"use-context-selector": "2.0.0",
"uuid": "10.0.0",
"zod": "3.25.76",
@@ -172,7 +173,7 @@
"@next/eslint-plugin-next": "16.1.6",
"@next/mdx": "16.1.5",
"@rgrove/parse-xml": "4.2.0",
- "@serwist/turbopack": "9.5.0",
+ "@serwist/turbopack": "9.5.4",
"@storybook/addon-docs": "10.2.0",
"@storybook/addon-links": "10.2.0",
"@storybook/addon-onboarding": "10.2.0",
@@ -210,7 +211,7 @@
"autoprefixer": "10.4.21",
"code-inspector-plugin": "1.3.6",
"cross-env": "10.1.0",
- "esbuild-wasm": "0.27.2",
+ "esbuild": "0.27.2",
"eslint": "9.39.2",
"eslint-plugin-react-hooks": "7.0.1",
"eslint-plugin-react-refresh": "0.4.26",
@@ -226,7 +227,7 @@
"postcss": "8.5.6",
"react-scan": "0.4.3",
"sass": "1.93.2",
- "serwist": "9.5.0",
+ "serwist": "9.5.4",
"storybook": "10.2.0",
"tailwindcss": "3.4.18",
"tsx": "4.21.0",
diff --git a/web/pnpm-lock.yaml b/web/pnpm-lock.yaml
index 5266b4ac6f0..d7ba2570d46 100644
--- a/web/pnpm-lock.yaml
+++ b/web/pnpm-lock.yaml
@@ -347,6 +347,9 @@ importers:
tldts:
specifier: 7.0.17
version: 7.0.17
+ ufo:
+ specifier: 1.6.3
+ version: 1.6.3
use-context-selector:
specifier: 2.0.0
@@ -391,8 +394,8 @@ importers:
specifier: 4.2.0
version: 4.2.0
'@serwist/turbopack':
- specifier: 9.5.0
+ specifier: 9.5.4
'@storybook/addon-docs':
specifier: 10.2.0
@@ -504,7 +507,7 @@ importers:
cross-env:
specifier: 10.1.0
version: 10.1.0
- esbuild-wasm:
+ esbuild:
specifier: 0.27.2
version: 0.27.2
eslint:
@@ -553,8 +556,8 @@ importers:
specifier: 1.93.2
version: 1.93.2
serwist:
- specifier: 9.5.0
- version: 9.5.0([email protected])
+ specifier: 9.5.4
storybook:
specifier: 10.2.0
@@ -2542,8 +2545,8 @@ packages:
peerDependencies:
react: ^16.14.0 || 17.x || 18.x || 19.x
- '@serwist/[email protected]':
- resolution: {integrity: sha512-8D330WwYjBI5MadyVOphwUqJLMNQK76KWBoDykIPrbtt0C3uGFPxG4XNZCFXBkRG3O1QLedv9BWqH27SeqhcLg==}
+ '@serwist/[email protected]':
+ resolution: {integrity: sha512-FTiNsNb3luKsLIxjKCvkPiqFZSbx7yVNOFGSUhp4lyfzgnelT1M3/lMC88kLiak90emkuFjSkQgwa6OnyhMZlQ==}
engines: {node: '>=18.0.0'}
peerDependencies:
typescript: '>=5.0.0'
@@ -2551,23 +2554,33 @@ packages:
typescript:
optional: true
- '@serwist/[email protected]':
- resolution: {integrity: sha512-MPxDapkN6LPG25I8LgOxQHc2ifIWK8WY+4pOdAbAFmN4FvsgLwYJ/W4531lsRWu08sq5IZ9JlRtt6KLNm5DHSQ==}
+ '@serwist/[email protected]':
+ resolution: {integrity: sha512-HerOIc2z3LWbFVq/gXK44I99KdF+x0uBI7cPHb+Q3q0WpF50d/i5fV5pZZXCf3LCqtc9oH0VlY6FWDcjWjHI8g==}
engines: {node: '>=18.0.0'}
peerDependencies:
+ esbuild: 0.27.2
esbuild-wasm: '>=0.25.0 <1.0.0'
next: '>=14.0.0'
react: '>=18.0.0'
typescript: '>=5.0.0'
peerDependenciesMeta:
+ esbuild:
+ optional: true
+ esbuild-wasm:
+ optional: true
typescript:
optional: true
- '@serwist/[email protected]':
- resolution: {integrity: sha512-DBzmJgL63/VYcQ/TpSYXW1FJKRILesOxytu+1MHY0vW2WFhW7pYkLgVuHqksP5K+3ypt54M3+2QNDDMixrnutQ==}
+ '@serwist/[email protected]':
+ resolution: {integrity: sha512-uyriGQF1qjNEHXXfsd8XJ5kfK3/MezEaUw//XdHjZeJ0LvLamrgnLJGQQoyJqUfEPCiJ4jJwc4uYMB9LjLiHxA==}
+ peerDependencies:
+ browserslist: '>=4'
+ peerDependenciesMeta:
+ browserslist:
+ optional: true
- '@serwist/[email protected]':
- resolution: {integrity: sha512-WqmEZjJ+u841sbUJh2LAbtPNrz8mU/wCTo9sEVqsMOk+EM5oBz5FRpF3kDzx1cF5rTIfXer1df0D354lIdFw1Q==}
+ '@serwist/[email protected]':
+ resolution: {integrity: sha512-52t2G+TgiWDdRwGG0ArU28uy6/oQYICQfNLHs4ywybyS6mHy3BxHFl+JjB5vhg8znIG1LMpGvOmS5b7AuPVYDw==}
peerDependencies:
typescript: '>=5.0.0'
peerDependenciesMeta:
@@ -2719,68 +2732,68 @@ packages:
'@svgdotjs/[email protected]':
resolution: {integrity: sha512-/VNHWYhNu+BS7ktbYoVGrCmsXDh+chFMaONMwGNdIBcFHrWqk2jY8fNyr3DLdtQUIalvkPfM554ZSFa3dm3nxQ==}
- resolution: {integrity: sha512-M9cK5GwyWWRkRGwwCbREuj6r8jKdES/haCZ3Xckgkl8MUQJZA3XB7IXXK1IXRNeLjg6m7cnoMICpXv1v1hlJOg==}
+ resolution: {integrity: sha512-QoIupRWVH8AF1TgxYyeA5nS18dtqMuxNwchjBIwJo3RdwLEFiJq6onOx9JAxHtuPwUkIVuU2Xbp+jCJ7Vzmgtg==}
engines: {node: '>=10'}
cpu: [arm64]
os: [darwin]
- resolution: {integrity: sha512-j47DasuOvXl80sKJHSi2X25l44CMc3VDhlJwA7oewC1nV1VsSzwX+KOwE5tLnfORvVJJyeiXgJORNYg4jeIjYQ==}
+ resolution: {integrity: sha512-S52Gu1QtPSfBYDiejlcfp9GlN+NjTZBRRNsz8PNwBgSE626/FUf2PcllVUix7jqkoMC+t0rS8t+2/aSWlMuQtA==}
engines: {node: '>=10'}
cpu: [x64]
os: [darwin]
- resolution: {integrity: sha512-siAzDENu2rUbwr9+fayWa26r5A9fol1iORG53HWxQL1J8ym4k7xt9eME0dMPXlYZDytK5r9sW8zEA10F2U3Xwg==}
+ resolution: {integrity: sha512-lXJs8oXo6Z4yCpimpQ8vPeCjkgoHu5NoMvmJZ8qxDyU99KVdg6KwU9H79vzrmB+HfH+dCZ7JGMqMF//f8Cfvdg==}
engines: {node: '>=10'}
cpu: [arm]
os: [linux]
- resolution: {integrity: sha512-o+1y5u6k2FfPYbTRUPvurwzNt5qd0NTumCTFscCNuBksycloXY16J8L+SMW5QRX59n4Hp9EmFa3vpvNHRVv1+Q==}
+ resolution: {integrity: sha512-chRsz1K52/vj8Mfq/QOugVphlKPWlMh10V99qfH41hbGvwAU6xSPd681upO4bKiOr9+mRIZZW+EfJqY42ZzRyA==}
engines: {node: '>=10'}
cpu: [arm64]
os: [linux]
- resolution: {integrity: sha512-koiCqL09EwOP1S2RShCI7NbsQuG6r2brTqUYE7pV7kZm9O17wZ0LSz22m6gVibpwEnw8jI3IE1yYsQTVpluALw==}
+ resolution: {integrity: sha512-PYftgsTaGnfDK4m6/dty9ryK1FbLk+LosDJ/RJR2nkXGc8rd+WenXIlvHjWULiBVnS1RsjHHOXmTS4nDhe0v0w==}
engines: {node: '>=10'}
cpu: [arm64]
os: [linux]
- resolution: {integrity: sha512-4p6lOMU3bC+Vd5ARtKJ/FxpIC5G8v3XLoPEZ5s7mLR8h7411HWC/LmTXDHcrSXRC55zvAVia1eldy6zDLz8iFQ==}
+ resolution: {integrity: sha512-DKtnJKIHiZdARyTKiX7zdRjiDS1KihkQWatQiCHMv+zc2sfwb4Glrodx2VLOX4rsa92NLR0Sw8WLcPEMFY1szQ==}
engines: {node: '>=10'}
cpu: [x64]
os: [linux]
- resolution: {integrity: sha512-z3XBnbrZAL+6xDGAhJoN4lOueIxC/8rGrJ9tg+fEaeqLEuAtHSW2QHDHxDwkxZMjuF/pZ6MUTjHjbp8wLbuRLA==}
+ resolution: {integrity: sha512-mUjjntHj4+8WBaiDe5UwRNHuEzLjIWBTSGTw0JT9+C9/Yyuh4KQqlcEQ3ro6GkHmBGXBFpGIj/o5VMyRWfVfWw==}
engines: {node: '>=10'}
cpu: [x64]
os: [linux]
- resolution: {integrity: sha512-djQPJ9Rh9vP8GTS/Df3hcc6XP6xnG5c8qsngWId/BLA9oX6C7UzCPAn74BG/wGb9a6j4w3RINuoaieJB3t+7iQ==}
+ resolution: {integrity: sha512-ZkNNG5zL49YpaFzfl6fskNOSxtcZ5uOYmWBkY4wVAvgbSAQzLRVBp+xArGWh2oXlY/WgL99zQSGTv7RI5E6nzA==}
engines: {node: '>=10'}
cpu: [arm64]
os: [win32]
- resolution: {integrity: sha512-/wfAgxORg2VBaUoFdytcVBVCgf1isWZIEXB9MZEUty4wwK93M/PxAkjifOho9RN3WrM3inPLabICRCEgdHpKKQ==}
+ resolution: {integrity: sha512-6XnzORkZCQzvTQ6cPrU7iaT9+i145oLwnin8JrfsLG41wl26+5cNQ2XV3zcbrnFEV6esjOceom9YO1w9mGJByw==}
engines: {node: '>=10'}
cpu: [ia32]
os: [win32]
- resolution: {integrity: sha512-GpMePrh9Sl4d61o4KAHOOv5is5+zt6BEXCOCgs/H0FLGeii7j9bWDE8ExvKFy2GRRZVNR1ugsnzaGWHKM6kuzA==}
+ resolution: {integrity: sha512-IQ2n6af7XKLL6P1gIeZACskSxK8jWtoKpJWLZmdXTDj1MGzktUy4i+FvpdtxFmJWNavRWH1VmTr6kAubRDHeKw==}
engines: {node: '>=10'}
cpu: [x64]
os: [win32]
- resolution: {integrity: sha512-T8keoJjXaSUoVBCIjgL6wAnhADIb09GOELzKg10CjNg+vLX48P93SME6jTfte9MZIm5m+Il57H3rTSk/0kzDUw==}
+ resolution: {integrity: sha512-iLmLTodbYxU39HhMPaMUooPwO/zqJWvsqkrXv1ZI38rMb048p6N7qtAtTp37sw9NzSrvH6oli8EdDygo09IZ/w==}
engines: {node: '>=10'}
peerDependencies:
'@swc/helpers': '>=0.5.17'
@@ -4877,11 +4890,13 @@ packages:
resolution: {integrity: sha512-DfXN8DfhJ7NH3Oe7cFmu3NCu1wKbkReJ8TorzSAFbSKrlNaQSKfIzqYqVY8zlbs2NLBbWpRiU52GX2PbaBVNkg==}
+ deprecated: Old versions of glob are not supported, and contain widely publicized security vulnerabilities, which have been fixed in the current version. Please update. Support for old versions may be purchased (at exorbitant rates) by contacting [email protected]
hasBin: true
resolution: {integrity: sha512-vuNwKSaKiqm7g0THUBu2x7ckSs3XJLXE+2ssL7/MfTGPLLcrJQ/4Uq1CjPTtO5cCIiRxqvN6Twy1qOwhL0Xjcw==}
engines: {node: 20 || >=22}
+ deprecated: Old versions of glob are not supported, and contain widely publicized security vulnerabilities, which have been fixed in the current version. Please update. Support for old versions may be purchased (at exorbitant rates) by contacting [email protected]
hasBin: true
@@ -6601,8 +6616,8 @@ packages:
resolution: {integrity: sha512-qepMx2JxAa5jjfzxG79yPPq+8BuFToHd1hm7kI+Z4zAq1ftQiP7HcxMhDDItrbtwVeLg/cY2JnKnrcFkmiswNA==}
- resolution: {integrity: sha512-wjrsPWHI5ZM20jIsVKZGN/uAdS2aKOgmIOE4dqUaFhK6SVIzgoJZjTnZ3v29T+NmneuD753jlhGui9eYypsj0A==}
+ resolution: {integrity: sha512-uTHBzpIeA6rE3oyRt392MbtNQDs2JVZelKD1KkT18UkhX6HRwCeassoI1Nd1h52DqYqa7ZfBeldJ4awy+PYrnQ==}
peerDependencies:
typescript: '>=5.0.0'
peerDependenciesMeta:
@@ -7480,9 +7495,6 @@ packages:
resolution: {integrity: sha512-gzUt/qt81nXsFGKIFcC3YnfEAx5NkunCfnDlvuBSSFS02bcXu4Lmea0AFIUwbLWxWPx3d9p8S5QoaujKcNQxcQ==}
- resolution: {integrity: sha512-k7Nwx6vuWx1IJ9Bjuf4Zt1PEllcwe7cls3VNzm4CQ1/hgtFUK2bRNG3rvnpPUhFjmqJKAKtjV576KnUkHocg/g==}
-
resolution: {integrity: sha512-rftlrkhHZOcjDwkGlnUtZZkvaPHCsDATp4pGpuOOMDaTdDDXF91wuVDJoWoPsKX/3YPQ5fHuF3STjcYyKr+Qhg==}
@@ -9603,43 +9615,51 @@ snapshots:
hoist-non-react-statics: 3.3.2
react: 19.2.4
dependencies:
- '@serwist/utils': 9.5.0
+ '@serwist/utils': 9.5.4([email protected])
common-tags: 1.8.2
glob: 10.5.0
pretty-bytes: 6.1.1
source-map: 0.8.0-beta.0
- zod: 4.3.5
+ zod: 4.3.6
optionalDependencies:
typescript: 5.9.3
+ transitivePeerDependencies:
+ - browserslist
dependencies:
- '@serwist/build': 9.5.0([email protected])
- '@serwist/utils': 9.5.0
- '@serwist/window': 9.5.0([email protected])
- '@swc/core': 1.15.8(@swc/[email protected])
- esbuild-wasm: 0.27.2
+ '@serwist/build': 9.5.4([email protected])([email protected])
+ '@serwist/utils': 9.5.4([email protected])
+ '@serwist/window': 9.5.4([email protected])([email protected])
+ '@swc/core': 1.15.11(@swc/[email protected])
+ browserslist: 4.28.1
kolorist: 1.8.0
react: 19.2.4
semver: 7.7.3
- serwist: 9.5.0([email protected])
- zod: 4.3.5
+ zod: 4.3.6
optionalDependencies:
+ esbuild: 0.27.2
+ esbuild-wasm: 0.27.2
typescript: 5.9.3
transitivePeerDependencies:
- '@swc/helpers'
- '@serwist/[email protected]': {}
+ optionalDependencies:
+ browserslist: 4.28.1
dependencies:
'@types/trusted-types': 2.0.7
- serwist: 9.5.0([email protected])
optionalDependencies:
typescript: 5.9.3
+ transitivePeerDependencies:
+ - browserslist
'@sindresorhus/[email protected]': {}
@@ -9821,51 +9841,51 @@ snapshots:
'@svgdotjs/[email protected]': {}
optional: true
optional: true
optional: true
optional: true
optional: true
optional: true
optional: true
optional: true
optional: true
optional: true
dependencies:
'@swc/counter': 0.1.3
'@swc/types': 0.1.25
optionalDependencies:
- '@swc/core-darwin-arm64': 1.15.8
- '@swc/core-darwin-x64': 1.15.8
- '@swc/core-linux-arm-gnueabihf': 1.15.8
- '@swc/core-linux-arm64-gnu': 1.15.8
- '@swc/core-linux-arm64-musl': 1.15.8
- '@swc/core-linux-x64-gnu': 1.15.8
- '@swc/core-linux-x64-musl': 1.15.8
- '@swc/core-win32-arm64-msvc': 1.15.8
- '@swc/core-win32-ia32-msvc': 1.15.8
- '@swc/core-win32-x64-msvc': 1.15.8
+ '@swc/core-darwin-arm64': 1.15.11
+ '@swc/core-darwin-x64': 1.15.11
+ '@swc/core-linux-arm-gnueabihf': 1.15.11
+ '@swc/core-linux-arm64-gnu': 1.15.11
+ '@swc/core-linux-arm64-musl': 1.15.11
+ '@swc/core-linux-x64-gnu': 1.15.11
+ '@swc/core-linux-x64-musl': 1.15.11
+ '@swc/core-win32-arm64-msvc': 1.15.11
+ '@swc/core-win32-ia32-msvc': 1.15.11
+ '@swc/core-win32-x64-msvc': 1.15.11
'@swc/helpers': 0.5.18
'@swc/[email protected]': {}
@@ -11653,7 +11673,8 @@ snapshots:
esast-util-from-estree: 2.0.0
vfile-message: 4.0.3
+ optional: true
optionalDependencies:
@@ -14563,12 +14584,14 @@ snapshots:
dependencies:
- '@serwist/utils': 9.5.0
+ '@serwist/utils': 9.5.4([email protected])
idb: 8.0.3
optionalDependencies:
typescript: 5.9.3
+ transitivePeerDependencies:
+ - browserslist
dependencies:
@@ -15487,8 +15510,6 @@ snapshots:
-