diff --git a/package.json b/package.json index 4f0061f1..55834556 100644 --- a/package.json +++ b/package.json @@ -71,9 +71,9 @@ "rehype-raw": "^7.0.0", "rehype-sanitize": "^6.0.0", "remark-gfm": "^4.0.0", + "remix-island": "^0.2.0", "remix-utils": "^7.6.0", "shiki": "^1.9.1", - "remix-island": "^0.2.0", "unist-util-visit": "^5.0.0" }, "devDependencies": { diff --git a/vite.config.ts b/vite.config.ts index 15cd0357..2bb6891d 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -1,6 +1,6 @@ import { cloudflareDevProxyVitePlugin as remixCloudflareDevProxy, vitePlugin as remixVitePlugin } from '@remix-run/dev'; import UnoCSS from 'unocss/vite'; -import { defineConfig } from 'vite'; +import { defineConfig, type ViteDevServer } from 'vite'; import { nodePolyfills } from 'vite-plugin-node-polyfills'; import { optimizeCssModules } from 'vite-plugin-optimize-css-modules'; import tsconfigPaths from 'vite-tsconfig-paths'; @@ -24,7 +24,35 @@ export default defineConfig((config) => { }), UnoCSS(), tsconfigPaths(), + chrome129IssuePlugin(), config.mode === 'production' && optimizeCssModules({ apply: 'build' }), ], }; }); + +function chrome129IssuePlugin() { + return { + name: 'chrome129IssuePlugin', + configureServer(server: ViteDevServer) { + server.middlewares.use((req, res, next) => { + const raw = req.headers['user-agent']?.match(/Chrom(e|ium)\/([0-9]+)\./); + + if (raw) { + const version = parseInt(raw[2], 10); + + if (version === 129) { + res.setHeader('content-type', 'text/html'); + res.write( + '

Please use Chrome Canary for testing.

Chrome 129 has an issue with JavaScript modules & vite local development, see here for more.

`pnpm run build` and `pnpm run start` will work fine in this browser though.

', + ); + res.end(); + + return; + } + } + + next(); + }); + }, + }; +}