Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

🐛 fix(vite): keep antd component locales in the ui-runtime chunk (#20405)

Arvin Xu6a3eba96b010
diff --git a/plugins/vite/sharedRendererConfig.test.ts b/plugins/vite/sharedRendererConfig.test.ts
index 2551afb25e8..c203fb1b197 100644
--- a/plugins/vite/sharedRendererConfig.test.ts
+++ b/plugins/vite/sharedRendererConfig.test.ts
@@ -129,6 +129,32 @@ describe('sharedManualChunks', () => {
);
});
+ it('keeps the whole antd locale graph in the ui-runtime chunk so it cannot form a cycle', () => {
+ const pnpm = '/repo/node_modules/.pnpm/[email protected]/node_modules';
+ for (const id of [
+ `${pnpm}/antd/locale/zh_CN.js`,
+ `${pnpm}/antd/es/calendar/locale/zh_CN.js`,
+ `${pnpm}/antd/es/date-picker/locale/zh_CN.js`,
+ `${pnpm}/antd/es/time-picker/locale/zh_CN.js`,
+ '/repo/node_modules/@rc-component/pagination/es/locale/zh_CN.js',
+ '/repo/node_modules/@rc-component/picker/es/locale/zh_CN.js',
+ ]) {
+ expect(__testing.sharedManualChunks(id)).toBe('i18n-zh-CN-ui-runtime');
+ }
+ expect(
+ __testing.sharedManualChunks('/repo/node_modules/@rc-component/picker/es/locale/ar_EG.js'),
+ ).toBe('i18n-ar-ui-runtime');
+ });
+
+ it('leaves antd default en_US component locales with the antd vendor graph', () => {
+ expect(
+ __testing.sharedManualChunks('/repo/node_modules/antd/es/date-picker/locale/en_US.js'),
+ ).toBe(undefined);
+ expect(
+ __testing.sharedManualChunks('/repo/node_modules/@rc-component/picker/es/locale/common.js'),
+ ).toBe(undefined);
+ });
+
it('keeps locale runtime helpers out of the default locale chunk', () => {
expect(__testing.sharedManualChunks('/repo/packages/locales/src/resources.ts')).toBe(undefined);
expect(__testing.sharedManualChunks('/repo/packages/locales/src/create.ts')).toBe(undefined);
diff --git a/plugins/vite/sharedRendererConfig.ts b/plugins/vite/sharedRendererConfig.ts
index c1280a3b716..e203c2becaf 100644
--- a/plugins/vite/sharedRendererConfig.ts
+++ b/plugins/vite/sharedRendererConfig.ts
@@ -176,6 +176,22 @@ function sharedManualChunks(id: string): string | undefined {
if (locale) return `i18n-${locale}-ui-runtime`;
}
+ // The antd locale above imports per-component locales (calendar, date-picker,
+ // time-picker, rc pagination/picker) and is itself re-exported by the
+ // `antd/locale/*` entry. Lazy groups capture only matched modules, so left
+ // unmatched these land in an entry-set chunk that imports the ui-runtime chunk
+ // while ui-runtime imports it back. That cycle breaks rolldown's lazy init
+ // ("r is not a function") and every non-English locale silently falls back to
+ // English. en_US stays out: antd components import it statically as their
+ // default locale, so it belongs with the antd vendor graph.
+ const antdPartMatch = id.match(
+ /[\\/](?:antd|@rc-component[\\/][^\\/]+)[\\/](?:[^\\/]+[\\/])*locale[\\/]([A-Za-z]{2}_[A-Z]{2})\.js$/,
+ );
+ if (antdPartMatch && antdPartMatch[1] !== 'en_US') {
+ const locale = ANTD_LOCALE[antdPartMatch[1]];
+ if (locale) return `i18n-${locale}-ui-runtime`;
+ }
+
const dayjsMatch = id.match(/dayjs\/locale\/([^/.]+)\.js/);
if (dayjsMatch) {
const locale = DAYJS_LOCALE[dayjsMatch[1]];