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.

chore: use react-grab to replace code-inspector-plugin (#33078)

Stephen Zhouf05f0be55ff5
diff --git a/web/app/components/devtools/react-grab/loader.tsx b/web/app/components/devtools/react-grab/loader.tsx
new file mode 100644
index 00000000000..3a1ecc6be8e
--- /dev/null
+++ b/web/app/components/devtools/react-grab/loader.tsx
@@ -0,0 +1,17 @@
+import Script from 'next/script'
+import { IS_DEV } from '@/config'
+
+export function ReactGrabLoader() {
+ if (!IS_DEV)
+ return null
+
+ return (
+ <>
+ <Script
+ src="//unpkg.com/react-grab/dist/index.global.js"
+ crossOrigin="anonymous"
+ strategy="beforeInteractive"
+ />
+ </>
+ )
+}
diff --git a/web/app/layout.tsx b/web/app/layout.tsx
index 2aaa4dc5ce4..44af079eea1 100644
--- a/web/app/layout.tsx
+++ b/web/app/layout.tsx
@@ -11,6 +11,7 @@ import { cn } from '@/utils/classnames'
import { ToastProvider } from './components/base/toast'
import { TooltipProvider } from './components/base/ui/tooltip'
import BrowserInitializer from './components/browser-initializer'
+import { ReactGrabLoader } from './components/devtools/react-grab/loader'
import { ReactScanLoader } from './components/devtools/react-scan/loader'
import { I18nServerProvider } from './components/provider/i18n-server'
import SentryInitializer from './components/sentry-initializer'
@@ -56,6 +57,7 @@ const LocaleLayout = async ({
<meta name="msapplication-TileColor" content="#1C64F2" />
<meta name="msapplication-config" content="/browserconfig.xml" />
+ <ReactGrabLoader />
<ReactScanLoader />
</head>
<body
diff --git a/web/eslint.config.mjs b/web/eslint.config.mjs
index f8d2b4ca6cf..145df1484e0 100644
--- a/web/eslint.config.mjs
+++ b/web/eslint.config.mjs
@@ -5,8 +5,8 @@ import tailwindcss from 'eslint-plugin-better-tailwindcss'
import hyoban from 'eslint-plugin-hyoban'
import sonar from 'eslint-plugin-sonarjs'
import storybook from 'eslint-plugin-storybook'
-import dify from './eslint-rules/index.js'
import { OVERLAY_MIGRATION_LEGACY_BASE_FILES } from './eslint.constants.mjs'
+import dify from './plugins/eslint/index.js'
// Enable Tailwind CSS IntelliSense mode for ESLint runs
// See: tailwind-css-plugin.ts
diff --git a/web/next.config.ts b/web/next.config.ts
index 414e45318f2..3c726c96f14 100644
--- a/web/next.config.ts
+++ b/web/next.config.ts
@@ -1,21 +1,9 @@
import type { NextConfig } from 'next'
import createMDX from '@next/mdx'
-import { codeInspectorPlugin } from 'code-inspector-plugin'
import { env } from './env'
const isDev = process.env.NODE_ENV === 'development'
-const withMDX = createMDX({
- extension: /\.mdx?$/,
- options: {
- // If you use remark-gfm, you'll need to use next.config.mjs
- // as the package is ESM only
- // https://github.com/remarkjs/remark-gfm#install
- remarkPlugins: [],
- rehypePlugins: [],
- // If you use `MDXProvider`, uncomment the following line.
- // providerImportSource: "@mdx-js/react",
- },
-})
+const withMDX = createMDX()
// the default url to prevent parse url error when running jest
const hasSetWebPrefix = env.NEXT_PUBLIC_WEB_PREFIX
@@ -26,11 +14,6 @@ const remoteImageURLs = ([hasSetWebPrefix ? new URL(`${env.NEXT_PUBLIC_WEB_PREFI
const nextConfig: NextConfig = {
basePath: env.NEXT_PUBLIC_BASE_PATH,
transpilePackages: ['@t3-oss/env-core', '@t3-oss/env-nextjs', 'echarts', 'zrender'],
- turbopack: {
- rules: codeInspectorPlugin({
- bundler: 'turbopack',
- }),
- },
productionBrowserSourceMaps: false, // enable browser source map generation during the production build
// Configure pageExtensions to include md and mdx
pageExtensions: ['ts', 'tsx', 'js', 'jsx', 'md', 'mdx'],
@@ -48,7 +31,6 @@ const nextConfig: NextConfig = {
// https://nextjs.org/docs/api-reference/next.config.js/ignoring-typescript-errors
ignoreBuildErrors: true,
},
- reactStrictMode: true,
async redirects() {
return [
{
diff --git a/web/package.json b/web/package.json
index e987b761e7c..934f9c2995c 100644
--- a/web/package.json
+++ b/web/package.json
@@ -217,7 +217,6 @@
"@vitejs/plugin-rsc": "0.5.21",
"@vitest/coverage-v8": "4.0.18",
"autoprefixer": "10.4.21",
- "code-inspector-plugin": "1.3.6",
"cross-env": "10.1.0",
"eslint": "10.0.2",
"eslint-plugin-better-tailwindcss": "https://pkg.pr.new/hyoban/eslint-plugin-better-tailwindcss@a520d15",
@@ -235,7 +234,6 @@
"nock": "14.0.10",
"postcss": "8.5.6",
"postcss-js": "5.0.3",
- "react-scan": "0.5.3",
"react-server-dom-webpack": "19.2.4",
"sass": "1.93.2",
"storybook": "10.2.13",
diff --git a/web/eslint-rules/index.js b/web/plugins/eslint/index.js
similarity index 100%
rename from web/eslint-rules/index.js
rename to web/plugins/eslint/index.js
diff --git a/web/eslint-rules/namespaces.js b/web/plugins/eslint/namespaces.js
similarity index 100%
rename from web/eslint-rules/namespaces.js
rename to web/plugins/eslint/namespaces.js
diff --git a/web/eslint-rules/rules/consistent-placeholders.js b/web/plugins/eslint/rules/consistent-placeholders.js
similarity index 100%
rename from web/eslint-rules/rules/consistent-placeholders.js
rename to web/plugins/eslint/rules/consistent-placeholders.js
diff --git a/web/eslint-rules/rules/no-as-any-in-t.js b/web/plugins/eslint/rules/no-as-any-in-t.js
similarity index 100%
rename from web/eslint-rules/rules/no-as-any-in-t.js
rename to web/plugins/eslint/rules/no-as-any-in-t.js
diff --git a/web/eslint-rules/rules/no-extra-keys.js b/web/plugins/eslint/rules/no-extra-keys.js
similarity index 100%
rename from web/eslint-rules/rules/no-extra-keys.js
rename to web/plugins/eslint/rules/no-extra-keys.js
diff --git a/web/eslint-rules/rules/no-legacy-namespace-prefix.js b/web/plugins/eslint/rules/no-legacy-namespace-prefix.js
similarity index 100%
rename from web/eslint-rules/rules/no-legacy-namespace-prefix.js
rename to web/plugins/eslint/rules/no-legacy-namespace-prefix.js
diff --git a/web/eslint-rules/rules/require-ns-option.js b/web/plugins/eslint/rules/require-ns-option.js
similarity index 100%
rename from web/eslint-rules/rules/require-ns-option.js
rename to web/plugins/eslint/rules/require-ns-option.js
diff --git a/web/eslint-rules/utils.js b/web/plugins/eslint/utils.js
similarity index 100%
rename from web/eslint-rules/utils.js
rename to web/plugins/eslint/utils.js
diff --git a/web/plugins/vite/custom-i18n-hmr.ts b/web/plugins/vite/custom-i18n-hmr.ts
new file mode 100644
index 00000000000..0e65c5727ae
--- /dev/null
+++ b/web/plugins/vite/custom-i18n-hmr.ts
@@ -0,0 +1,80 @@
+import type { Plugin } from 'vite'
+import fs from 'node:fs'
+import { injectClientSnippet, normalizeViteModuleId } from './utils'
+
+type CustomI18nHmrPluginOptions = {
+ injectTarget: string
+}
+
+export const customI18nHmrPlugin = ({ injectTarget }: CustomI18nHmrPluginOptions): Plugin => {
+ const i18nHmrClientMarker = 'custom-i18n-hmr-client'
+ const i18nHmrClientSnippet = `/* ${i18nHmrClientMarker} */
+if (import.meta.hot) {
+ const getI18nUpdateTarget = (file) => {
+ const match = file.match(/[/\\\\]i18n[/\\\\]([^/\\\\]+)[/\\\\]([^/\\\\]+)\\.json$/)
+ if (!match)
+ return null
+ const [, locale, namespaceFile] = match
+ return { locale, namespaceFile }
+ }
+
+ import.meta.hot.on('i18n-update', async ({ file, content }) => {
+ const target = getI18nUpdateTarget(file)
+ if (!target)
+ return
+
+ const [{ getI18n }, { camelCase }] = await Promise.all([
+ import('react-i18next'),
+ import('es-toolkit/string'),
+ ])
+
+ const i18n = getI18n()
+ if (!i18n)
+ return
+ if (target.locale !== i18n.language)
+ return
+
+ let resources
+ try {
+ resources = JSON.parse(content)
+ }
+ catch {
+ return
+ }
+
+ const namespace = camelCase(target.namespaceFile)
+ i18n.addResourceBundle(target.locale, namespace, resources, true, true)
+ i18n.emit('languageChanged', i18n.language)
+ })
+}
+`
+
+ return {
+ name: 'custom-i18n-hmr',
+ apply: 'serve',
+ handleHotUpdate({ file, server }) {
+ if (file.endsWith('.json') && file.includes('/i18n/')) {
+ server.ws.send({
+ type: 'custom',
+ event: 'i18n-update',
+ data: {
+ file,
+ content: fs.readFileSync(file, 'utf-8'),
+ },
+ })
+
+ return []
+ }
+ },
+ transform(code, id) {
+ const cleanId = normalizeViteModuleId(id)
+ if (cleanId !== injectTarget)
+ return null
+
+ const nextCode = injectClientSnippet(code, i18nHmrClientMarker, i18nHmrClientSnippet)
+ if (nextCode === code)
+ return null
+ return { code: nextCode, map: null }
+ },
+ }
+}
diff --git a/web/plugins/vite/react-grab-open-file.ts b/web/plugins/vite/react-grab-open-file.ts
new file mode 100644
index 00000000000..42e0ace3afd
--- /dev/null
+++ b/web/plugins/vite/react-grab-open-file.ts
@@ -0,0 +1,92 @@
+import type { Plugin } from 'vite'
+import { injectClientSnippet, normalizeViteModuleId } from './utils'
+
+type ReactGrabOpenFilePluginOptions = {
+ injectTarget: string
+ projectRoot: string
+}
+
+export const reactGrabOpenFilePlugin = ({
+ injectTarget,
+ projectRoot,
+}: ReactGrabOpenFilePluginOptions): Plugin => {
+ const reactGrabOpenFileClientMarker = 'react-grab-open-file-client'
+ const reactGrabOpenFileClientSnippet = `/* ${reactGrabOpenFileClientMarker} */
+if (typeof window !== 'undefined') {
+ const projectRoot = ${JSON.stringify(projectRoot)};
+ const pluginName = 'dify-vite-open-file';
+ const rootRelativeSourcePathPattern = /^\\/(?!@|node_modules)(?:.+)\\.(?:[cm]?[jt]sx?|mdx?)$/;
+
+ const normalizeProjectRoot = (input) => {
+ return input.endsWith('/') ? input.slice(0, -1) : input;
+ };
+
+ const resolveFilePath = (filePath) => {
+ if (filePath.startsWith('/@fs/')) {
+ return filePath.slice('/@fs'.length);
+ }
+
+ if (!rootRelativeSourcePathPattern.test(filePath)) {
+ return filePath;
+ }
+
+ const normalizedProjectRoot = normalizeProjectRoot(projectRoot);
+ if (filePath.startsWith(normalizedProjectRoot)) {
+ return filePath;
+ }
+
+ return \`\${normalizedProjectRoot}\${filePath}\`;
+ };
+
+ const registerPlugin = () => {
+ if (window.__DIFY_REACT_GRAB_OPEN_FILE_PLUGIN_REGISTERED__) {
+ return;
+ }
+
+ const reactGrab = window.__REACT_GRAB__;
+ if (!reactGrab) {
+ return;
+ }
+
+ reactGrab.registerPlugin({
+ name: pluginName,
+ hooks: {
+ onOpenFile(filePath, lineNumber) {
+ const params = new URLSearchParams({
+ file: resolveFilePath(filePath),
+ column: '1',
+ });
+
+ if (lineNumber) {
+ params.set('line', String(lineNumber));
+ }
+
+ void fetch(\`/__open-in-editor?\${params.toString()}\`);
+ return true;
+ },
+ },
+ });
+
+ window.__DIFY_REACT_GRAB_OPEN_FILE_PLUGIN_REGISTERED__ = true;
+ };
+
+ registerPlugin();
+ window.addEventListener('react-grab:init', registerPlugin);
+}
+`
+
+ return {
+ name: 'react-grab-open-file',
+ apply: 'serve',
+ transform(code, id) {
+ const cleanId = normalizeViteModuleId(id)
+ if (cleanId !== injectTarget)
+ return null
+
+ const nextCode = injectClientSnippet(code, reactGrabOpenFileClientMarker, reactGrabOpenFileClientSnippet)
+ if (nextCode === code)
+ return null
+ return { code: nextCode, map: null }
+ },
+ }
+}
diff --git a/web/plugins/vite/utils.ts b/web/plugins/vite/utils.ts
new file mode 100644
index 00000000000..52bcc5bbbe9
--- /dev/null
+++ b/web/plugins/vite/utils.ts
@@ -0,0 +1,20 @@
+export const normalizeViteModuleId = (id: string): string => {
+ const withoutQuery = id.split('?', 1)[0]
+
+ if (withoutQuery.startsWith('/@fs/'))
+ return withoutQuery.slice('/@fs'.length)
+
+ return withoutQuery
+}
+
+export const injectClientSnippet = (code: string, marker: string, snippet: string): string => {
+ if (code.includes(marker))
+ return code
+
+ const useClientMatch = code.match(/(['"])use client\1;?\s*\n/)
+ if (!useClientMatch)
+ return `${snippet}\n${code}`
+
+ const insertAt = (useClientMatch.index ?? 0) + useClientMatch[0].length
+ return `${code.slice(0, insertAt)}\n${snippet}\n${code.slice(insertAt)}`
+}
diff --git a/web/pnpm-lock.yaml b/web/pnpm-lock.yaml
index 77109cdbb37..0308a68d2d4 100644
--- a/web/pnpm-lock.yaml
+++ b/web/pnpm-lock.yaml
@@ -215,7 +215,7 @@ importers:
version: 11.1.0
jotai:
specifier: 2.16.1
js-audio-recorder:
specifier: 1.0.7
version: 1.0.7
@@ -254,13 +254,13 @@ importers:
version: 1.0.0
next:
specifier: 16.1.5
next-themes:
specifier: 0.4.6
nuqs:
specifier: 2.8.6
pinyin-pro:
specifier: 3.27.0
version: 3.27.0
@@ -420,7 +420,7 @@ importers:
'@storybook/nextjs-vite':
specifier: 10.2.13
'@storybook/react':
specifier: 10.2.13
@@ -517,9 +517,6 @@ importers:
autoprefixer:
specifier: 10.4.21
version: 10.4.21([email protected])
- code-inspector-plugin:
- specifier: 1.3.6
- version: 1.3.6
cross-env:
specifier: 10.1.0
version: 10.1.0
@@ -571,9 +568,6 @@ importers:
postcss-js:
specifier: 5.0.3
version: 5.0.3([email protected])
- react-scan:
- specifier: 0.5.3
react-server-dom-webpack:
specifier: 19.2.4
@@ -597,7 +591,7 @@ importers:
version: 3.19.3
vinext:
specifier: https://pkg.pr.new/hyoban/vinext@556a6d6
vite:
specifier: 8.0.0-beta.16
@@ -955,24 +949,6 @@ packages:
resolution: {integrity: sha512-/42G73JkuYdyWZ6m8d/CJtBrGl1Hegyc7Fy78m5Ob+jF85TOUmLR5XLce/U3LxYAw0kJ8CT5aI99RIvPHcGp/Q==}
- '@code-inspector/[email protected]':
- resolution: {integrity: sha512-bSxf/PWDPY6rv9EFf0mJvTnLnz3927PPrpX6BmQcRKQab+Ez95yRqrVZY8IcBUpaqA/k3etA5rZ1qkN0V4ERtw==}
-
- '@code-inspector/[email protected]':
- resolution: {integrity: sha512-s35dseBXI2yqfX6ZK29Ix941jaE/4KPlZZeMk6B5vDahj75FDUfVxQ7ORy4cX2hyz8CmlOycsY/au5mIvFpAFg==}
-
- '@code-inspector/[email protected]':
- resolution: {integrity: sha512-FJvuTElOi3TUCWTIaYTFYk2iTUD6MlO51SC8SYfwmelhuvnOvTMa2TkylInX16OGb4f7sGNLRj2r+7NNx/gqpw==}
-
- '@code-inspector/[email protected]':
- resolution: {integrity: sha512-pfXgvZCn4/brpTvqy8E0HTe6V/ksVKEPQo697Nt5k22kBnlEM61UT3rI2Art+fDDEMPQTxVOFpdbwCKSLwMnmQ==}
-
- '@code-inspector/[email protected]':
- resolution: {integrity: sha512-vXYvzGc0S1NR4p3BeD1Xx2170OnyecZD0GtebLlTiHw/cetzlrBHVpbkIwIEzzzpTYYshwwDt8ZbuvdjmqhHgw==}
-
- '@code-inspector/[email protected]':
- resolution: {integrity: sha512-bi/+vsym9d6NXQQ++Phk74VLMiVoGKjgPHr445j/D43URG8AN8yYa+gRDBEDcZx4B128dihrVMxEO8+OgWGjTw==}
-
'@csstools/[email protected]':
resolution: {integrity: sha512-S11EXWJyy0Mz5SYvRmY8nJYTFFd1LCNV+7cXyAgQtOOuzb4EsgfqDufL+9esx72/eLhsRdGZwaldu/h+E4t4BA==}
engines: {node: '>=18'}
@@ -2188,11 +2164,6 @@ packages:
'@preact/[email protected]':
resolution: {integrity: sha512-5Yf8h1Ke3SMHr15xl630KtwPTW4sYDFkkxS0vQ8UiQLWwZQnrF9IKaVG1mN5VcJz52EcWs2acsc/Npjha/7ysA==}
- '@preact/[email protected]':
- resolution: {integrity: sha512-naxcJgUJ6BTOROJ7C3QML7KvwKwCXQJYTc5L/b0eEsdYgPB6SxwoQ1vDGcS0Q7GVjAenVq/tXrybVdFShHYZWg==}
- peerDependencies:
- preact: 10.x
-
'@radix-ui/[email protected]':
resolution: {integrity: sha512-JTF99U/6XIjCBo0wqkU5sK10glYe27MRRsfwoiq5zzOEZLHU3A3KCMa5X/azekYRCJ0HlwI0crAXS/5dEHTzDg==}
@@ -3295,9 +3266,6 @@ packages:
resolution: {integrity: sha512-elf6BsTq+AkyNsb2h5cGNst2Mc7dPliVoAPm1fXglC/BM3f2pFA40BaSSv3E5lyHteEawVKLP+8TwiY1DMNb3A==}
- '@types/[email protected]':
- resolution: {integrity: sha512-WJtwWJu7UdlvzEAUm484QNg5eAoq5QR08KDNx7g45Usrs2NtOPiX8ugDqmKdXkyL03rBqU5dYNYVQetEpBHq2g==}
-
resolution: {integrity: sha512-68e+T28EbdmLSTkPgs3+UacC6rzmqrcWFPQs1C8mwJhI/r5Uxr0yEuQotczNRROd1gq30NGxee+fo0rSIxpyAw==}
@@ -3315,11 +3283,6 @@ packages:
peerDependencies:
'@types/react': ^19.2.0
- '@types/[email protected]':
- resolution: {integrity: sha512-HHM3nxyUZ3zAylX8ZEyrDNd2XZOnQ0D5XfunJF5FLQnZbHHYq4UWvW1QfelQNXv1ICNkwYhfxjwfnqivYB6bFg==}
- peerDependencies:
- '@types/react': '*'
-
resolution: {integrity: sha512-RS8XN5O159YQ6tu3tGZIQz1/9StMLTg/FCIPxwqh2gwVixJnlfIodtVx+fpXVMZHe7A58lAX1Q4XTgAGOQaCQg==}
@@ -3818,9 +3781,6 @@ packages:
resolution: {integrity: sha512-LElXdjswlqjWrPpJFg1Fx4wpkOCxj1TDHlSV4PlaRxHGWko024xICaa97ZkMfs6DRKlCguiAI+rbXv5GWwXIkg==}
hasBin: true
- resolution: {integrity: sha512-htCUDlxyyCLMgaM3xXg0C0LW2xqfuQ6p05pCEIsXuyQ+a1koYKTuBMzRNwmybfLgvJDMd0r1LTn4+E0Ti6C2AA==}
-
resolution: {integrity: sha512-O+A6LWV5LDHSJD3LjHYoNi4VLsj/Whi7k6zG12xTYaU4cQ8oxQGckXNX8cRHK5yOZ/ppVHe0ZBXGzSV9jXdVbQ==}
engines: {node: ^10 || ^12 || >=14}
@@ -3862,11 +3822,6 @@ packages:
resolution: {integrity: sha512-Ceh+7ox5qe7LJuLHoY0feh3pHuUDHAcRUeyL2VYghZwfpkNIy/+8Ocg0a3UuSoYzavmylwuLWQOf3hl0jjMMIw==}
engines: {node: '>=8'}
- resolution: {integrity: sha512-8CFmJAHD3gmTLDOCDHuWhjm1nxHSFZdlGoWtak9r53Uxn36ynOjxBLyxXHh/7h/XiKLyPvfdXa0gXWcD9o9lLQ==}
- peerDependencies:
- react: '>=17.0.1'
-
resolution: {integrity: sha512-VUpsf/qykW0heRlC8LooCq28Kxn3mAqKohhDG/49rrsQ1dT1CXyj/pgXS+5BSRzFTR/3DyIBOqQOrGyZOh71Aw==}
@@ -3949,10 +3904,6 @@ packages:
resolution: {integrity: sha512-NUPRluOfOiTKBKvWPtSD4PhFvWCqOi0BGStNWs57X9js7XGTprSmFoz5F0tWhR4WPjNeR9jXqdC7/UpSJTnlRg==}
engines: {node: '>=18'}
- resolution: {integrity: sha512-diHzdDKxcU+bAsUboHLPEDQiw0qEe0qd7SYUn3HgcFlWgbDcfLGswOHYeGrHKzG9z6UYf01d9VFMfZxPM1xZSg==}
- engines: {node: '>=10'}
-
resolution: {integrity: sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==}
engines: {node: '>=10'}
@@ -4077,9 +4028,6 @@ packages:
react: ^18 || ^19 || ^19.0.0-rc
react-dom: ^18 || ^19 || ^19.0.0-rc
- resolution: {integrity: sha512-ddTg8embDqLZxKEdSNOm+/0YnVVgWKr10+Bu2qFqQDObj/3twGh0Z23TIz+5/URxfRhTPbp2sUSpWlw78piJbQ==}
-
resolution: {integrity: sha512-loKTxY1zCOuG4j9f6EPnuyyYkf58RnhhWTvRoZEokgB+WbdXehfjFviyOVYkqzEWz1Q5kRiZdBYS5SwxbQYwzw==}
@@ -4110,10 +4058,6 @@ packages:
resolution: {integrity: sha512-/rFeCpNJQbhSZjGVwO9RFV3xPqbnERS8MmIQzCtD/zl6gpJuV/bMLuN92oG3F7d8oDEHHRrujSXNUr8fpjntKw==}
engines: {node: '>=18'}
- resolution: {integrity: sha512-H+y0Jo/T1RZ9qPP4Eh1pkcQcLRglraJaSLoyOtHxu6AapkjWVCy2Sit1QQ4x3Dng8qDlSsZEet7g5Pq06MvTgw==}
- engines: {node: '>=20'}
-
resolution: {integrity: sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==}
@@ -4499,10 +4443,6 @@ packages:
resolution: {integrity: sha512-6kZKyUajlDuqlHKVX1w7gyslj9MPIXzIFiz/rGu35uC1wMi+kMhQwGhl4lt9unC9Vb9INnY9Z3/ZA3+FhASLaw==}
- resolution: {integrity: sha512-uBq4egWHTcTt33a72vpSG0z3HnPuIl6NqYcTrKEg2azoEyl2hpW0zqlxysq2pK9HlDIHyHyakeYaYnSAwd8bow==}
- engines: {node: '>=12'}
-
resolution: {integrity: sha512-YpEI5Ty7O/2nvCfQ7ybNa+S90DwE8KYZWacGvJW4luUqywP7qStQ+pxDlYOmr4jGDu10mhEkiAuMKcUlT4W5vg==}
peerDependencies:
@@ -5612,10 +5552,6 @@ packages:
resolution: {integrity: sha512-Ls993zuzfayK269Svk9hzpeGUKob/sIgZzyHYdjQoAdQetRKpOLj+k/QQQ/6Qi0Yz65mlROrfd+Ev+1+7dz9Kw==}
- resolution: {integrity: sha512-eTIzlVOSUR+JxdDFepEYcBMtZ9Qqdef+rnzWdRZuMbOywu5tO2w2N7rqjoANZ5k9vywhL6Br1VRjUIgTQx4E8w==}
- engines: {node: '>=6'}
-
resolution: {integrity: sha512-nB7i/fgiJl7WVxdv5lX4ZPfDt9/zrw/lOgZtyioy988xtFhKuFJCRdHWT1Zg9Avc0yaojvnmEuAXU8SeMblKww==}
engines: {node: '>=18.18.0'}
@@ -5638,9 +5574,6 @@ packages:
resolution: {integrity: sha512-QJv/h939gDpvT+9SiLVlY7tZC3xB2qK57v0J04Sh9wpMb6MP1q8gB21L3WIo8T5P1MSMg3Ep14L7KkDCFG3y4w==}
engines: {node: '>=16.0.0'}
- resolution: {integrity: sha512-c2mcqZy7mNhzXiWoBFV0lDsEOfpSFGqqxKubPffhqcnv3GV0xpeGcHWLxYFm+jz1/5VAKp796QkyVV4++07eiw==}
-
resolution: {integrity: sha512-8h2oVEZNktL4BH2JCOI90iD1yXwL6iNW7KcCKT2QZgQJR2vbqDsldCTPRU9NifTCqHZci57XvQQ15YTu+sTYPg==}
@@ -6416,10 +6349,6 @@ packages:
resolution: {integrity: sha512-25ClnWWuw7JbWZcgqY/gJ4FQWadKxGWk+3kR/7kD0tCaDtPPMj7oHu2ToLaVhfpnHrZzYby2w6tUA0eOIuUg8g==}
- resolution: {integrity: sha512-rEwq/ZHlJIKw++XtLAO8PPuOQA/zaPJOZJ37BVuN97nLpMJeuDVLVGRwbFoBgLudgdTMP2hdRJP++H+8QOA3vg==}
- engines: {node: '>= 10.12'}
-
resolution: {integrity: sha512-hpr+J05B2FVYUAXHeK1YyI267J/dDDhMU6B6civm8hSY1jYJnBXxzKDKDswzJmtLHryrjhnDjqqp/49t8FALew==}
engines: {node: '>=14.0.0'}
@@ -6506,10 +6435,6 @@ packages:
resolution: {integrity: sha512-DEvV2ZF2r2/63V+tK8hQvrR2ZGn10srHbXviTlcv7Kpzw8jWiNTqbVgjO3IY8RxrrOUF8VPMQQFysYYYv0YZxw==}
engines: {node: '>=6'}
- resolution: {integrity: sha512-NxNv/kLguCA7p3jE8oL2aEBsrJWgAakBpgmgK6lpPWV+WuOmY6r2/zbAVnP+T8bQlA0nzHXSJSJW0Hq7ylaD2Q==}
- engines: {node: '>= 6'}
-
resolution: {integrity: sha512-oj87CgZICdulUohogVAR7AjlC0327U4el4L6eAvOqCeudMDVU0NThNaV+b9Df4dXgSP1gXMTnPdhfe/2qDH5cg==}
@@ -6678,13 +6603,6 @@ packages:
react: '>=16.3.0'
react-dom: '>=16.3.0'
- resolution: {integrity: sha512-qde9PupmUf0L3MU1H6bjmoukZNbCXdMyTEwP4Gh8RQ4rZPd2GGNBgEKWszwLm96E8k+sGtMpc0B9P0KyFDP6Bw==}
- hasBin: true
- peerDependencies:
- react: ^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0
- react-dom: ^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0
-
resolution: {integrity: sha512-zEhkWv6RhXDctC2N7yEUHg3751nvFg81ydHj8LTTZuukF/IF1gcOKqqAL6Ds+kS5HtDVACYPik0IvzkgYXPhlQ==}
engines: {node: '>=0.10.0'}
@@ -7401,9 +7319,6 @@ packages:
engines: {node: '>=0.8.0'}
hasBin: true
- resolution: {integrity: sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ==}
-
resolution: {integrity: sha512-Zz+aZWSj8LE6zoxD+xrjh4VfkIG8Ya6LvYkZqtUQGJPZjYl53ypCaUwWqo7eI0x66KBGeRo+mlBEkMSeSZ38Nw==}
@@ -7455,10 +7370,6 @@ packages:
resolution: {integrity: sha512-5lWVjgi6vuHhJ526bI4nlCOmkCIF3nnfXkCMDeMJrtdvxTs6ZFCM8oNufGTsDbKv/tJ/xj8RpvXjRuPBZJuJog==}
engines: {node: '>=20.19.0'}
- resolution: {integrity: sha512-us4j03/499KhbGP8BU7Hrzrgseo+KdfJYWcbcajCOqsAyb8Gk0Yn2kiUIcZISYCb1JFaZfIuG3b42HmguVOKCQ==}
- engines: {node: '>=18.12.0'}
-
resolution: {integrity: sha512-5uKD0nqiYVzlmCRs01Fhs2BdkEgBS3SAVP6ndrBsuK42iC2+JHyxM05Rm9G8+5mkmRtzMZGY8Ct5+mliZxU/Ww==}
engines: {node: '>=18.12.0'}
@@ -8467,48 +8378,6 @@ snapshots:
picocolors: 1.1.1
sisteransi: 1.0.5
- '@code-inspector/[email protected]':
- dependencies:
- '@vue/compiler-dom': 3.5.27
- chalk: 4.1.2
- dotenv: 16.6.1
- launch-ide: 1.4.0
- portfinder: 1.0.38
- transitivePeerDependencies:
- - supports-color
-
- '@code-inspector/[email protected]':
- dependencies:
- '@code-inspector/core': 1.3.6
- transitivePeerDependencies:
- - supports-color
-
- '@code-inspector/[email protected]':
- dependencies:
- '@code-inspector/core': 1.3.6
- transitivePeerDependencies:
- - supports-color
-
- '@code-inspector/[email protected]':
- dependencies:
- '@code-inspector/core': 1.3.6
- '@code-inspector/webpack': 1.3.6
- transitivePeerDependencies:
- - supports-color
-
- '@code-inspector/[email protected]':
- dependencies:
- '@code-inspector/core': 1.3.6
- chalk: 4.1.1
- transitivePeerDependencies:
- - supports-color
-
- '@code-inspector/[email protected]':
- dependencies:
- '@code-inspector/core': 1.3.6
- transitivePeerDependencies:
- - supports-color
-
'@csstools/[email protected]': {}
'@csstools/[email protected](@csstools/[email protected](@csstools/[email protected]))(@csstools/[email protected])':
@@ -9752,11 +9621,6 @@ snapshots:
'@preact/[email protected]': {}
- dependencies:
- '@preact/signals-core': 1.12.2
- preact: 10.28.2
-
'@radix-ui/[email protected]': {}
@@ -10329,18 +10193,18 @@ snapshots:
react: 19.2.4
react-dom: 19.2.4([email protected])
dependencies:
react: 19.2.4
react-dom: 19.2.4([email protected])
- styled-jsx: 5.1.6(@babel/[email protected])([email protected])
+ styled-jsx: 5.1.6(@babel/[email protected])([email protected])
optionalDependencies:
typescript: 5.9.3
transitivePeerDependencies:
@@ -10869,10 +10733,6 @@ snapshots:
'@types/[email protected]': {}
- '@types/[email protected]':
- dependencies:
- undici-types: 6.21.0
-
dependencies:
undici-types: 7.16.0
@@ -10891,10 +10751,6 @@ snapshots:
dependencies:
'@types/react': 19.2.9
- dependencies:
- '@types/react': 19.2.9
-
dependencies:
'@types/react': 19.2.9
@@ -11138,13 +10994,13 @@ snapshots:
dependencies:
unpic: 4.2.2
dependencies:
'@unpic/core': 1.0.3
react: 19.2.4
react-dom: 19.2.4([email protected])
optionalDependencies:
dependencies:
@@ -11286,7 +11142,7 @@ snapshots:
dependencies:
- '@babel/parser': 7.28.6
+ '@babel/parser': 7.29.0
'@vue/shared': 3.5.27
entities: 7.0.1
estree-walker: 2.0.2
@@ -11522,8 +11378,6 @@ snapshots:
-
dependencies:
browserslist: 4.28.1
@@ -11557,13 +11411,6 @@ snapshots:
- dependencies:
- '@types/react-reconciler': 0.28.9(@types/[email protected])
- react: 19.2.4
- transitivePeerDependencies:
- - '@types/react'
-
@@ -11641,11 +11488,6 @@ snapshots:
- dependencies:
- ansi-styles: 4.3.0
- supports-color: 7.2.0
-
dependencies:
ansi-styles: 4.3.0
@@ -11774,18 +11616,6 @@ snapshots:
- '@types/react'
- '@types/react-dom'
- dependencies:
- '@code-inspector/core': 1.3.6
- '@code-inspector/esbuild': 1.3.6
- '@code-inspector/mako': 1.3.6
- '@code-inspector/turbopack': 1.3.6
- '@code-inspector/vite': 1.3.6
- '@code-inspector/webpack': 1.3.6
- chalk: 4.1.1
- transitivePeerDependencies:
- - supports-color
-
@@ -11812,8 +11642,6 @@ snapshots:
-
@@ -12203,8 +12031,6 @@ snapshots:
domelementtype: 2.3.0
domhandler: 5.0.3
-
dependencies:
echarts: 5.6.0
@@ -13440,9 +13266,9 @@ snapshots:
optionalDependencies:
- '@babel/core': 7.29.0
+ '@babel/core': 7.28.6
'@babel/template': 7.28.6
'@types/react': 19.2.9
react: 19.2.4
@@ -13541,8 +13367,6 @@ snapshots:
-
dependencies:
'@nodelib/fs.walk': 1.2.8
@@ -13576,11 +13400,6 @@ snapshots:
vscode-languageserver-textdocument: 1.0.12
vscode-uri: 3.0.8
- dependencies:
- chalk: 4.1.2
- dotenv: 16.6.1
-
@@ -14365,7 +14184,7 @@ snapshots:
react: 19.2.4
react-dom: 19.2.4([email protected])
dependencies:
'@next/env': 16.1.5
'@swc/helpers': 0.5.15
@@ -14374,7 +14193,7 @@ snapshots:
postcss: 8.4.31
react: 19.2.4
react-dom: 19.2.4([email protected])
- styled-jsx: 5.1.6(@babel/[email protected])([email protected])
+ styled-jsx: 5.1.6(@babel/[email protected])([email protected])
optionalDependencies:
'@next/swc-darwin-arm64': 16.1.5
'@next/swc-darwin-x64': 16.1.5
@@ -14420,12 +14239,12 @@ snapshots:
dependencies:
boolbase: 1.0.0
dependencies:
'@standard-schema/spec': 1.0.0
react: 19.2.4
optionalDependencies:
@@ -14637,13 +14456,6 @@ snapshots:
path-data-parser: 0.1.0
points-on-curve: 0.2.0
- dependencies:
- async: 3.2.6
- debug: 4.4.3
- transitivePeerDependencies:
- - supports-color
-
dependencies:
postcss: 8.5.6
@@ -14703,7 +14515,8 @@ snapshots:
picocolors: 1.1.1
source-map-js: 1.2.1
+ optional: true
dependencies:
@@ -14731,11 +14544,6 @@ snapshots:
- dependencies:
- kleur: 3.0.3
- sisteransi: 1.0.5
-
dependencies:
loose-envify: 1.4.0
@@ -14918,30 +14726,6 @@ snapshots:
tslib: 2.6.2
- dependencies:
- '@babel/core': 7.29.0
- '@babel/generator': 7.29.1
- '@babel/types': 7.29.0
- '@preact/signals': 1.3.2([email protected])
- '@rollup/pluginutils': 5.3.0([email protected])
- '@types/node': 20.19.30
- bippy: 0.5.30(@types/[email protected])([email protected])
- commander: 14.0.3
- esbuild: 0.27.2
- estree-walker: 3.0.3
- picocolors: 1.1.1
- preact: 10.28.2
- prompts: 2.4.2
- react: 19.2.4
- react-dom: 19.2.4([email protected])
- optionalDependencies:
- unplugin: 2.1.0
- transitivePeerDependencies:
- - '@types/react'
- - rollup
- - supports-color
-
dependencies:
acorn-loose: 8.5.2
@@ -15561,12 +15345,12 @@ snapshots:
dependencies:
inline-style-parser: 0.2.7
dependencies:
client-only: 0.0.1
react: 19.2.4
optionalDependencies:
- '@babel/core': 7.29.0
+ '@babel/core': 7.28.6
@@ -15819,8 +15603,6 @@ snapshots:
-
@@ -15888,12 +15670,6 @@ snapshots:
pathe: 2.0.3
picomatch: 4.0.3
- dependencies:
- acorn: 8.16.0
- webpack-virtual-modules: 0.6.2
- optional: true
-
dependencies:
'@jridgewell/remapping': 2.3.5
@@ -15981,9 +15757,9 @@ snapshots:
'@types/unist': 3.0.3
vfile-message: 4.0.3
dependencies:
'@vercel/og': 0.8.6
magic-string: 0.30.21
@@ -16038,13 +15814,13 @@ snapshots:
transitivePeerDependencies:
- supports-color
dependencies:
'@next/env': 16.0.0
image-size: 2.0.2
magic-string: 0.30.21
module-alias: 2.3.4
ts-dedent: 2.2.0
diff --git a/web/vite.config.ts b/web/vite.config.ts
index 83a35f85586..cbe8eb31c92 100644
--- a/web/vite.config.ts
+++ b/web/vite.config.ts
@@ -1,162 +1,16 @@
-import type { Plugin } from 'vite'
-import fs from 'node:fs'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
import react from '@vitejs/plugin-react'
-import { codeInspectorPlugin } from 'code-inspector-plugin'
import vinext from 'vinext'
import { defineConfig } from 'vite'
import Inspect from 'vite-plugin-inspect'
import tsconfigPaths from 'vite-tsconfig-paths'
+import { customI18nHmrPlugin } from './plugins/vite/custom-i18n-hmr'
+import { reactGrabOpenFilePlugin } from './plugins/vite/react-grab-open-file'
-const __dirname = path.dirname(fileURLToPath(import.meta.url))
+const projectRoot = path.dirname(fileURLToPath(import.meta.url))
const isCI = !!process.env.CI
-const inspectorPort = 5678
-const inspectorInjectTarget = path.resolve(__dirname, 'app/components/browser-initializer.tsx')
-const inspectorRuntimeFile = path.resolve(
- __dirname,
- `node_modules/code-inspector-plugin/dist/append-code-${inspectorPort}.js`,
-)
-
-const getInspectorRuntimeSnippet = (): string => {
- if (!fs.existsSync(inspectorRuntimeFile))
- return ''
-
- const raw = fs.readFileSync(inspectorRuntimeFile, 'utf-8')
- // Remove the helper module default export from append file to avoid duplicate default exports.
- return raw.replace(
- /\s*export default function CodeInspectorEmptyElement\(\)\s*\{[\s\S]*$/,
- '',
- )
-}
-
-const normalizeInspectorModuleId = (id: string): string => {
- const withoutQuery = id.split('?', 1)[0]
-
- // Vite/vinext may pass absolute fs modules as "/@fs/<abs-path>".
- if (withoutQuery.startsWith('/@fs/'))
- return withoutQuery.slice('/@fs'.length)
-
- return withoutQuery
-}
-
-const createCodeInspectorPlugin = (): Plugin => {
- return codeInspectorPlugin({
- bundler: 'vite',
- port: inspectorPort,
- injectTo: inspectorInjectTarget,
- exclude: [/^(?!.*\.(?:js|ts|mjs|mts|jsx|tsx|vue|svelte|html)(?:$|\?)).*/],
- }) as Plugin
-}
-
-const createForceInspectorClientInjectionPlugin = (): Plugin => {
- const clientSnippet = getInspectorRuntimeSnippet()
-
- return {
- name: 'vinext-force-code-inspector-client',
- apply: 'serve',
- enforce: 'pre',
- transform(code, id) {
- if (!clientSnippet)
- return null
-
- const cleanId = normalizeInspectorModuleId(id)
- if (cleanId !== inspectorInjectTarget)
- return null
- if (code.includes('code-inspector-component'))
- return null
-
- return `${clientSnippet}\n${code}`
- },
- }
-}
-
-function customI18nHmrPlugin(): Plugin {
- const injectTarget = inspectorInjectTarget
- const i18nHmrClientMarker = 'custom-i18n-hmr-client'
- const i18nHmrClientSnippet = `/* ${i18nHmrClientMarker} */
-if (import.meta.hot) {
- const getI18nUpdateTarget = (file) => {
- const match = file.match(/[/\\\\]i18n[/\\\\]([^/\\\\]+)[/\\\\]([^/\\\\]+)\\.json$/)
- if (!match)
- return null
- const [, locale, namespaceFile] = match
- return { locale, namespaceFile }
- }
-
- import.meta.hot.on('i18n-update', async ({ file, content }) => {
- const target = getI18nUpdateTarget(file)
- if (!target)
- return
-
- const [{ getI18n }, { camelCase }] = await Promise.all([
- import('react-i18next'),
- import('es-toolkit/string'),
- ])
-
- const i18n = getI18n()
- if (!i18n)
- return
- if (target.locale !== i18n.language)
- return
-
- let resources
- try {
- resources = JSON.parse(content)
- }
- catch {
- return
- }
-
- const namespace = camelCase(target.namespaceFile)
- i18n.addResourceBundle(target.locale, namespace, resources, true, true)
- i18n.emit('languageChanged', i18n.language)
- })
-}
-`
-
- const injectI18nHmrClient = (code: string) => {
- if (code.includes(i18nHmrClientMarker))
- return code
-
- const useClientMatch = code.match(/(['"])use client\1;?\s*\n/)
- if (!useClientMatch)
- return `${i18nHmrClientSnippet}\n${code}`
-
- const insertAt = (useClientMatch.index ?? 0) + useClientMatch[0].length
- return `${code.slice(0, insertAt)}\n${i18nHmrClientSnippet}\n${code.slice(insertAt)}`
- }
-
- return {
- name: 'custom-i18n-hmr',
- apply: 'serve',
- handleHotUpdate({ file, server }) {
- if (file.endsWith('.json') && file.includes('/i18n/')) {
- server.ws.send({
- type: 'custom',
- event: 'i18n-update',
- data: {
- file,
- content: fs.readFileSync(file, 'utf-8'),
- },
- })
-
- // return empty array to prevent the default HMR
- return []
- }
- },
- transform(code, id) {
- const cleanId = normalizeInspectorModuleId(id)
- if (cleanId !== injectTarget)
- return null
-
- const nextCode = injectI18nHmrClient(code)
- if (nextCode === code)
- return null
- return { code: nextCode, map: null }
- },
- }
-}
+const browserInitializerInjectTarget = path.resolve(projectRoot, 'app/components/browser-initializer.tsx')
export default defineConfig(({ mode }) => {
const isTest = mode === 'test'
@@ -176,7 +30,7 @@ export default defineConfig(({ mode }) => {
if (id.endsWith('.mdx'))
return { code: 'export default () => null', map: null }
},
- } as Plugin,
+ },
]
: isStorybook
? [
@@ -185,15 +39,17 @@ export default defineConfig(({ mode }) => {
]
: [
Inspect(),
- createCodeInspectorPlugin(),
- createForceInspectorClientInjectionPlugin(),
react(),
vinext(),
- customI18nHmrPlugin(),
+ customI18nHmrPlugin({ injectTarget: browserInitializerInjectTarget }),
+ reactGrabOpenFilePlugin({
+ injectTarget: browserInitializerInjectTarget,
+ projectRoot,
+ }),
],
resolve: {
alias: {
- '~@': __dirname,
+ '~@': projectRoot,
},
},