Skip to content

Formerly KrillinAI, VideoTranslation and Dubbing Tool for 120+ Languages. Open-source AI workspace for creators, powered by Codex. Video downloader, video translation, create videos, images, audios, and edits with Agents in one place. For your Social Media like YouTube, TikTok, Instagram, etc.

fix(web): lazy-load AI service settings to meet asset budgets

Mijaelxb318fed39724
diff --git a/apps/web/src/features/settings/OpenCreatorSettingsView.test.tsx b/apps/web/src/features/settings/OpenCreatorSettingsView.test.tsx
index 81300bfd..6ee5a419 100644
--- a/apps/web/src/features/settings/OpenCreatorSettingsView.test.tsx
+++ b/apps/web/src/features/settings/OpenCreatorSettingsView.test.tsx
@@ -67,6 +67,35 @@ describe('OpenCreatorSettingsView', () => {
window.localStorage.removeItem(languagePreferenceStorageKey);
});
+ it('opens AI services on demand and can return to general settings', async () => {
+ render(<OpenCreatorSettingsView runtimeStatus={runtimeStatus} onBack={vi.fn()} />);
+
+ expect(screen.queryByRole('heading', { name: 'AI 服务' })).not.toBeInTheDocument();
+ fireEvent.click(screen.getByRole('button', { name: 'AI 服务 必需' }));
+ expect(await screen.findByRole('heading', { name: 'AI 服务' })).toBeInTheDocument();
+ expect(screen.getByRole('tab', { name: '模型服务' })).toHaveAttribute('aria-selected', 'true');
+
+ fireEvent.click(screen.getByRole('button', { name: '常规' }));
+ expect(screen.getByRole('combobox', { name: '默认权限' })).toBeInTheDocument();
+ expect(screen.queryByRole('heading', { name: 'AI 服务' })).not.toBeInTheDocument();
+ });
+
+ it('preserves the requested AI service section when opened directly', async () => {
+ render(
+ <OpenCreatorSettingsView
+ runtimeStatus={runtimeStatus}
+ initialTab="ai-services"
+ initialSection="transcription"
+ onBack={vi.fn()}
+ />
+ );
+
+ expect(await screen.findByRole('tab', { name: '语音识别' }))
+ .toHaveAttribute('aria-selected', 'true');
+ expect(screen.getByRole('button', { name: 'AI 服务 必需' }))
+ .toHaveAttribute('aria-current', 'page');
+ });
+
it('notifies when the global default permission changes', async () => {
const user = userEvent.setup();
const onDefaultPermissionChange = vi.fn();
diff --git a/apps/web/src/features/settings/OpenCreatorSettingsView.tsx b/apps/web/src/features/settings/OpenCreatorSettingsView.tsx
index 81ba3c92..a616920c 100644
--- a/apps/web/src/features/settings/OpenCreatorSettingsView.tsx
+++ b/apps/web/src/features/settings/OpenCreatorSettingsView.tsx
@@ -1,4 +1,4 @@
-import { useEffect, useRef, useState, type CSSProperties } from 'react';
+import { lazy, Suspense, useEffect, useRef, useState, type CSSProperties } from 'react';
import { Check, Moon, Sun } from 'lucide-react';
import type {
CodexProfileListResponse,
@@ -7,6 +7,7 @@ import type {
import { useConfirmDialog } from '../../components/dialogs/ConfirmDialogProvider.js';
import type { ColorMode } from '../../styles/color-mode.js';
import { useAppLanguage } from '../../i18n/LanguageProvider.js';
+import { useLocalizedCopy } from '../../i18n/useLocalizedCopy.js';
import type { AppLanguagePreference } from '../../i18n/language.js';
import {
defaultAccentColor,
@@ -18,10 +19,7 @@ import type { ProjectPermission } from '../projects/project-model.js';
import { ProfileSettingsView, type ProfileSettingsService } from './ProfileSettingsView.js';
import { CleanupSettingsView, type CleanupSettingsService } from './CleanupSettingsView.js';
import { DiagnosticsSettingsView } from './DiagnosticsSettingsView.js';
-import {
- CreatorServicesSettingsView,
- type CreatorServicesSection
-} from './CreatorServicesSettingsView.js';
+import type { CreatorServicesSection } from './CreatorServicesSettingsView.js';
import type { CreatorServicesSettingsService } from '../../services/creator-services-service.js';
import type { CodexRuntimeSettingsService } from './CodexRuntimeSettingsView.js';
import {
@@ -33,6 +31,11 @@ import type { RuntimeDependenciesController } from '../../app/use-runtime-depend
import { RuntimeComponentsSettingsView } from './RuntimeComponentsSettingsView.js';
import './settings-management.css';
+const CreatorServicesSettingsView = lazy(async () => {
+ const module = await import('./CreatorServicesSettingsView.js');
+ return { default: module.CreatorServicesSettingsView };
+});
+
export type RuntimeStatus = {
connected: boolean;
runtimeVersion?: string;
@@ -89,6 +92,7 @@ type SettingsTab =
export function OpenCreatorSettingsView(props: OpenCreatorSettingsViewProps) {
const [activeTab, setActiveTab] = useState<SettingsTab>(() => props.initialTab ?? 'general');
const { t } = useAppLanguage();
+ const l = useLocalizedCopy();
const tabs: Array<{ id: SettingsTab; label: string }> = [
{ id: 'general', label: t('settings.tab.general') },
{ id: 'ai-services', label: t('settings.tab.aiServices') },
@@ -155,12 +159,16 @@ export function OpenCreatorSettingsView(props: OpenCreatorSettingsViewProps) {
/>
) : null}
{activeTab === 'ai-services' ? (
- <CreatorServicesSettingsView
- connected={props.runtimeStatus.connected}
- service={props.creatorServicesService ?? null}
- modelService={props.codexRuntimeService ?? null}
- initialSection={props.initialSection}
- />
+ <Suspense fallback={
+ <p role="status">{l('正在加载 AI 服务设置…', 'Loading AI service settings…')}</p>
+ }>
+ <CreatorServicesSettingsView
+ connected={props.runtimeStatus.connected}
+ service={props.creatorServicesService ?? null}
+ modelService={props.codexRuntimeService ?? null}
+ initialSection={props.initialSection}
+ />
+ </Suspense>
) : null}
{activeTab === 'local-components' && props.runtimeDependencies !== undefined ? (
<RuntimeComponentsSettingsView
diff --git a/scripts/check-performance-baseline.mjs b/scripts/check-performance-baseline.mjs
index 18a16036..3c2ca4a5 100644
--- a/scripts/check-performance-baseline.mjs
+++ b/scripts/check-performance-baseline.mjs
@@ -57,6 +57,12 @@ function measureAssets() {
maxBytes: 90_000,
maxGzipBytes: 24_000
},
+ {
+ label: 'AI services settings JavaScript',
+ pattern: /^CreatorServicesSettingsView-[^.]+\.js$/,
+ maxBytes: 45_000,
+ maxGzipBytes: 14_000
+ },
{
label: 'Web 主样式',
pattern: /^index-[^.]+\.css$/,