Skip to content

Commit 07d7417

Browse files
authoredDec 23, 2024
✨ feat: upgrade to next15 and react19 (lobehub#4450)
* ♻️ refactor: upgrade next to 15 * refactor to serverExternalPackages
1 parent 4f6d8fc commit 07d7417

File tree

4 files changed

+37
-16
lines changed

4 files changed

+37
-16
lines changed
 

‎next.config.mjs ‎next.config.ts

+7-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import analyzer from '@next/bundle-analyzer';
22
import { withSentryConfig } from '@sentry/nextjs';
33
import withSerwistInit from '@serwist/next';
4+
import type { NextConfig } from 'next';
45
import ReactComponentName from 'react-scan/react-component-name/webpack';
56

67
const isProd = process.env.NODE_ENV === 'production';
@@ -13,8 +14,7 @@ const API_PROXY_ENDPOINT = process.env.API_PROXY_ENDPOINT || '';
1314

1415
const basePath = process.env.NEXT_PUBLIC_BASE_PATH;
1516

16-
/** @type {import('next').NextConfig} */
17-
const nextConfig = {
17+
const nextConfig: NextConfig = {
1818
basePath,
1919
compress: isProd,
2020
experimental: {
@@ -27,7 +27,6 @@ const nextConfig = {
2727
'gpt-tokenizer',
2828
'chroma-js',
2929
],
30-
serverComponentsExternalPackages: ['@electric-sql/pglite'],
3130
webVitalsAttribution: ['CLS', 'LCP'],
3231
},
3332

@@ -107,7 +106,6 @@ const nextConfig = {
107106
},
108107
];
109108
},
110-
111109
output: buildWithDocker ? 'standalone' : undefined,
112110
reactStrictMode: true,
113111
redirects: async () => [
@@ -169,13 +167,14 @@ const nextConfig = {
169167
source: '/welcome',
170168
},
171169
],
172-
173170
rewrites: async () => [
174171
// due to google api not work correct in some countries
175172
// we need a proxy to bypass the restriction
176173
{ destination: `${API_PROXY_ENDPOINT}/api/chat/google`, source: '/api/chat/google' },
177174
],
178175

176+
serverExternalPackages: ['@electric-sql/pglite'],
177+
179178
webpack(config) {
180179
config.experiments = {
181180
asyncWebAssembly: true,
@@ -206,7 +205,7 @@ const nextConfig = {
206205
},
207206
};
208207

209-
const noWrapper = (config) => config;
208+
const noWrapper = (config: NextConfig) => config;
210209

211210
const withBundleAnalyzer = process.env.ANALYZE === 'true' ? analyzer() : noWrapper;
212211

@@ -221,7 +220,7 @@ const withPWA = isProd
221220
const hasSentry = !!process.env.NEXT_PUBLIC_SENTRY_DSN;
222221
const withSentry =
223222
isProd && hasSentry
224-
? (c) =>
223+
? (c: NextConfig) =>
225224
withSentryConfig(
226225
c,
227226
{
@@ -262,4 +261,4 @@ const withSentry =
262261
)
263262
: noWrapper;
264263

265-
export default withBundleAnalyzer(withPWA(withSentry(nextConfig)));
264+
export default withBundleAnalyzer(withPWA(withSentry(nextConfig) as NextConfig));

‎package.json

+8-8
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"db:push-test": "NODE_ENV=test drizzle-kit push",
4040
"db:studio": "drizzle-kit studio",
4141
"db:z-pull": "drizzle-kit introspect",
42-
"dev": "next dev -p 3010",
42+
"dev": "next dev --turbo -p 3010",
4343
"docs:i18n": "lobe-i18n md && npm run lint:mdx",
4444
"docs:seo": "lobe-seo && npm run lint:mdx",
4545
"i18n": "npm run workflow:i18n && lobe-i18n",
@@ -130,7 +130,7 @@
130130
"@lobehub/tts": "^1.25.1",
131131
"@lobehub/ui": "^1.153.13",
132132
"@neondatabase/serverless": "^0.10.1",
133-
"@next/third-parties": "^14.2.15",
133+
"@next/third-parties": "^15.0.0",
134134
"@react-spring/web": "^9.7.5",
135135
"@sentry/nextjs": "^7.119.2",
136136
"@serwist/next": "^9.0.9",
@@ -145,7 +145,7 @@
145145
"@vercel/speed-insights": "^1.0.12",
146146
"ahooks": "^3.8.1",
147147
"ai": "^3.4.16",
148-
"antd": "^5.21.4",
148+
"antd": "^5.22.6",
149149
"antd-style": "^3.7.1",
150150
"brotli-wasm": "^3.0.1",
151151
"chroma-js": "^2.6.0",
@@ -175,7 +175,7 @@
175175
"mammoth": "^1.8.0",
176176
"modern-screenshot": "^4.4.39",
177177
"nanoid": "^5.0.7",
178-
"next": "14.2.8",
178+
"next": "^15.1.2",
179179
"next-auth": "beta",
180180
"next-mdx-remote": "^4.4.1",
181181
"nextjs-toploader": "^3.7.15",
@@ -195,9 +195,9 @@
195195
"pwa-install-handler": "^2.6.1",
196196
"query-string": "^9.1.1",
197197
"random-words": "^2.0.1",
198-
"react": "^18.3.1",
198+
"react": "^19.0.0",
199199
"react-confetti": "^6.1.0",
200-
"react-dom": "^18.3.1",
200+
"react-dom": "^19.0.0",
201201
"react-fast-marquee": "^1.6.5",
202202
"react-hotkeys-hook": "^4.5.1",
203203
"react-i18next": "14.0.2",
@@ -244,8 +244,8 @@
244244
"@lobehub/i18n-cli": "^1.20.0",
245245
"@lobehub/lint": "^1.24.4",
246246
"@lobehub/seo-cli": "^1.4.2",
247-
"@next/bundle-analyzer": "^14.2.15",
248-
"@next/eslint-plugin-next": "^14.2.15",
247+
"@next/bundle-analyzer": "^15.0.0",
248+
"@next/eslint-plugin-next": "^15.0.0",
249249
"@peculiar/webcrypto": "^1.5.0",
250250
"@semantic-release/exec": "^6.0.3",
251251
"@testing-library/jest-dom": "^6.6.2",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
"use client";
2+
3+
import { useEffect } from "react";
4+
import { unstableSetRender } from "antd";
5+
import { createRoot } from "react-dom/client";
6+
7+
const AntdV5MonkeyPatch = () => {
8+
useEffect(() => {
9+
unstableSetRender((node, container) => {
10+
const root = createRoot(container);
11+
root.render(node);
12+
return async () => {
13+
root.unmount();
14+
};
15+
});
16+
}, []);
17+
return null;
18+
};
19+
20+
export default AntdV5MonkeyPatch;

‎src/layout/GlobalProvider/index.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { ServerConfigStoreProvider } from '@/store/serverConfig';
1717
import { getAntdLocale } from '@/utils/locale';
1818
import { isMobileDevice } from '@/utils/server/responsive';
1919

20+
import AntdV5MonkeyPatch from './AntdV5MonkeyPatch';
2021
import AppTheme from './AppTheme';
2122
import Debug from './Debug';
2223
import Locale from './Locale';
@@ -91,6 +92,7 @@ const GlobalLayout = async ({ children }: PropsWithChildren) => {
9192
<DebugUI />
9293
<Debug />
9394
</AppTheme>
95+
<AntdV5MonkeyPatch />
9496
</Locale>
9597
</StyleRegistry>
9698
);

0 commit comments

Comments
 (0)
Please sign in to comment.