From 381eed21ccd580a680d058629f1c95f634d1452d Mon Sep 17 00:00:00 2001 From: Huang Xin Date: Thu, 28 May 2026 10:14:47 +0800 Subject: [PATCH] fix(tauri): skip runtime-config.js injection in static export (#4332) The Tauri build uses `output: 'export'`, so the dynamic `/runtime-config.js` route handler is never emitted. Requesting it returns the SPA fallback HTML and crashes with `Unexpected token '<'`. Gate the script tag on `NEXT_PUBLIC_APP_PLATFORM === 'web'`; Tauri consumers already fall back to the `NEXT_PUBLIC_*` envs baked in at build time. Co-authored-by: Claude Opus 4.7 (1M context) --- apps/readest-app/src/app/layout.tsx | 11 ++++++++++- apps/readest-app/src/pages/_document.tsx | 7 ++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/apps/readest-app/src/app/layout.tsx b/apps/readest-app/src/app/layout.tsx index 59d769fb..4fce12dc 100644 --- a/apps/readest-app/src/app/layout.tsx +++ b/apps/readest-app/src/app/layout.tsx @@ -123,6 +123,13 @@ const devHmrPatchScript = `(${patchTauriHmrWebSocket.toString()})(${JSON.stringi process.env['TAURI_DEV_HOST'], )});`; +// `/runtime-config.js` is a dynamic route handler that only exists in the +// web/Docker build. The Tauri build is statically exported (`output: +// 'export'`), so the file isn't emitted — the request would return the SPA +// fallback HTML and crash with `Unexpected token '<'`. All runtime-config +// consumers fall back to `NEXT_PUBLIC_*` envs baked at build time on Tauri. +const shouldInjectRuntimeConfig = process.env['NEXT_PUBLIC_APP_PLATFORM'] === 'web'; + export default function RootLayout({ children }: { children: React.ReactNode }) { return ( -