Files
forumlify/next.config.js
T
lezi-fun 024b678ad3 fix: hydration mismatch (loading spinner restart) + cache strategy
Root cause of loading spinner restarting / name appearing twice:
React hydration mismatch → whole tree regenerated. Fixed all sources:
- AppProvider: remove typeof window in useState init (SSR/client diff);
  read cached forum name in useEffect instead
- ToastProvider: remove createPortal(document.body) (SSR absent →
  mismatch)
- LoadingScreen: name container uses dangerouslySetInnerHTML('') so
  React never manages/clobbers the inline-script-filled text
- layout.js: inline script moved to body first child (React official
  anti-FOUC pattern)

Cache: dynamic pages/API no-cache + ETag (304 on revalidate); static
/_next/static assets immutable 1y. Verified: 304 + immutable headers.
2026-08-11 10:52:33 +08:00

34 lines
1.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/** @type {import('next').NextConfig} */
const nextConfig = {
// Docker 部署用 standalone 输出;serverless(Vercel/CF Pages)不需要
...(process.env.DOCKER ? { output: 'standalone' } : {}),
// /uploads/* 由 API 路由提供(上传文件运行时新增,不进 public 构建快照)
async rewrites() {
return [
{ source: '/uploads/:name', destination: '/api/uploads/:name' },
];
},
// 缓存策略:动态页面/API no-cache(浏览器每次验证 → 304);
// 静态资源(_next/static)immutable 长缓存(Next.js 默认,但需在 no-cache 之后覆盖)
async headers() {
return [
{
source: '/:path*',
headers: [
{ key: 'Cache-Control', value: 'no-cache, must-revalidate' },
],
},
{
source: '/_next/static/:path*',
headers: [
{ key: 'Cache-Control', value: 'public, max-age=31536000, immutable' },
],
},
];
},
};
module.exports = nextConfig;
import('@opennextjs/cloudflare').then(m => m.initOpenNextCloudflareForDev());