From 1ebf546b70655e5fd70d823aef0074d63d51a265 Mon Sep 17 00:00:00 2001 From: one Date: Sat, 5 Jul 2025 15:08:02 +0800 Subject: [PATCH] chore: fix vite warning on dynamic imports (#7852) --- src/renderer/src/components/CodeEditor/hook.ts | 14 ++------------ src/renderer/src/hooks/useMinappPopup.ts | 11 +++++------ src/renderer/src/hooks/useTopic.ts | 3 +-- src/renderer/src/services/WebSearchService.ts | 4 +--- 4 files changed, 9 insertions(+), 23 deletions(-) diff --git a/src/renderer/src/components/CodeEditor/hook.ts b/src/renderer/src/components/CodeEditor/hook.ts index c5bbab2d0..7e3bd2832 100644 --- a/src/renderer/src/components/CodeEditor/hook.ts +++ b/src/renderer/src/components/CodeEditor/hook.ts @@ -1,22 +1,12 @@ +import { linter } from '@codemirror/lint' // statically imported by @uiw/codemirror-extensions-basic-setup import { useCodeStyle } from '@renderer/context/CodeStyleProvider' import { Extension } from '@uiw/react-codemirror' import { useEffect, useState } from 'react' -let linterPromise: Promise | null = null -function importLintPackage() { - if (!linterPromise) { - linterPromise = import('@codemirror/lint').then((mod) => mod.linter) - } - return linterPromise -} - // 语言对应的 linter 加载器 const linterLoaders: Record Promise> = { json: async () => { - const [linter, jsonParseLinter] = await Promise.all([ - importLintPackage(), - import('@codemirror/lang-json').then((mod) => mod.jsonParseLinter) - ]) + const jsonParseLinter = await import('@codemirror/lang-json').then((mod) => mod.jsonParseLinter) return linter(jsonParseLinter()) } } diff --git a/src/renderer/src/hooks/useMinappPopup.ts b/src/renderer/src/hooks/useMinappPopup.ts index 578246cc0..010136ae2 100644 --- a/src/renderer/src/hooks/useMinappPopup.ts +++ b/src/renderer/src/hooks/useMinappPopup.ts @@ -1,3 +1,4 @@ +import { DEFAULT_MIN_APPS } from '@renderer/config/minapps' import { useRuntime } from '@renderer/hooks/useRuntime' import { useSettings } from '@renderer/hooks/useSettings' // 使用设置中的值 import { useAppDispatch } from '@renderer/store' @@ -74,12 +75,10 @@ export const useMinappPopup = () => { /** Open a minapp by id (look up the minapp in DEFAULT_MIN_APPS) */ const openMinappById = useCallback( (id: string, keepAlive: boolean = false) => { - import('@renderer/config/minapps').then(({ DEFAULT_MIN_APPS }) => { - const app = DEFAULT_MIN_APPS.find((app) => app?.id === id) - if (app) { - openMinapp(app, keepAlive) - } - }) + const app = DEFAULT_MIN_APPS.find((app) => app?.id === id) + if (app) { + openMinapp(app, keepAlive) + } }, [openMinapp] ) diff --git a/src/renderer/src/hooks/useTopic.ts b/src/renderer/src/hooks/useTopic.ts index c6913bd7e..e6fea6f69 100644 --- a/src/renderer/src/hooks/useTopic.ts +++ b/src/renderer/src/hooks/useTopic.ts @@ -1,5 +1,6 @@ import db from '@renderer/databases' import i18n from '@renderer/i18n' +import { fetchMessagesSummary } from '@renderer/services/ApiService' import { EVENT_NAMES, EventEmitter } from '@renderer/services/EventService' import { deleteMessageFiles } from '@renderer/services/MessagesService' import store from '@renderer/store' @@ -133,8 +134,6 @@ export const autoRenameTopic = async (assistant: Assistant, topicId: string) => if (topic && topic.name === i18n.t('chat.default.topic.name') && topic.messages.length >= 2) { try { startTopicRenaming(topicId) - - const { fetchMessagesSummary } = await import('@renderer/services/ApiService') const summaryText = await fetchMessagesSummary({ messages: topic.messages, assistant }) if (summaryText) { const data = { ...topic, name: summaryText } diff --git a/src/renderer/src/services/WebSearchService.ts b/src/renderer/src/services/WebSearchService.ts index 66157a062..9f6e367dd 100644 --- a/src/renderer/src/services/WebSearchService.ts +++ b/src/renderer/src/services/WebSearchService.ts @@ -22,6 +22,7 @@ import { fetchWebContents } from '@renderer/utils/fetch' import { consolidateReferencesByUrl, selectReferences } from '@renderer/utils/websearch' import dayjs from 'dayjs' import { LRUCache } from 'lru-cache' +import { sliceByTokens } from 'tokenx' import { getKnowledgeBaseParams } from './KnowledgeService' import { getKnowledgeSourceUrl, searchKnowledgeBase } from './KnowledgeService' @@ -384,9 +385,6 @@ class WebSearchService { const perResultLimit = Math.max(1, Math.floor(config.cutoffLimit / rawResults.length)) - // 动态导入 tokenx - const { sliceByTokens } = await import('tokenx') - return rawResults.map((result) => { if (config.cutoffUnit === 'token') { // 使用 token 截断