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 (
- + {shouldInjectRuntimeConfig ? ( + + ) : null} {shouldInjectDevHmrPatch ? ( ) : null} diff --git a/apps/readest-app/src/pages/_document.tsx b/apps/readest-app/src/pages/_document.tsx index ff775cb5..576bc357 100644 --- a/apps/readest-app/src/pages/_document.tsx +++ b/apps/readest-app/src/pages/_document.tsx @@ -1,6 +1,9 @@ import { Html, Head, Main, NextScript } from 'next/document'; import Script from 'next/script'; +// Only the web/Docker build serves `/runtime-config.js`. See app/layout.tsx. +const shouldInjectRuntimeConfig = process.env['NEXT_PUBLIC_APP_PLATFORM'] === 'web'; + export default function Document() { return ( @@ -8,7 +11,9 @@ export default function Document() { {/* beforeInteractive must live in _document (not _app) to guarantee the script runs before any client-side module evaluation. */} - + {shouldInjectRuntimeConfig ? ( + + ) : null}