From 2cc03220041296d09698f10ee3c2b11c4028ae59 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 3 May 2026 11:35:36 +0000 Subject: [PATCH] =?UTF-8?q?fix(frontend):=20chunking=20debug=20panel=20?= =?UTF-8?q?=E2=80=94=20visible=20loading=20+=20error=20states,=20prevent?= =?UTF-8?q?=20submit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit User report: clicking "Run preview" made the debug section appear to disappear. Three independent problems contributed; fix all of them. 1. t-button rendered without explicit type="button". TDesign defaults vary across versions; if the panel ever lives inside a parent
(the editor modal does not currently, but this is defense in depth), the click would submit the form and reload the page. Added type="button" plus @click.prevent.stop on the run button. 2. No loading visual. While the request was in flight, result was set back to null, so the result block disappeared with nothing in its place. The textarea was still on screen but the spacing shifted enough that users could read it as "section gone". Added a loading panel with t-loading spinner + status text. 3. Error display was too quiet. A tiny one-line error block could be missed entirely behind the modal's scrollable content. Made it visually prominent (bold prefix, full-width error background) so it can't be overlooked. Bonus hardening: - Stricter response-shape check (resp.success !== true || !resp.data catches malformed responses, not just non-200s). - console.error with [KBChunkingDebug] prefix so the failure is debuggable from DevTools without enabling verbose logging. - New i18n key chunking.debug.loading across all 4 locales. https://claude.ai/code/session_01XADhx6mtu2ZYW3DE9Lun6k --- frontend/src/i18n/locales/en-US.ts | 1 + frontend/src/i18n/locales/ko-KR.ts | 1 + frontend/src/i18n/locales/ru-RU.ts | 1 + frontend/src/i18n/locales/zh-CN.ts | 1 + .../knowledge/settings/KBChunkingDebug.vue | 56 ++++++++++++++++--- 5 files changed, 51 insertions(+), 9 deletions(-) diff --git a/frontend/src/i18n/locales/en-US.ts b/frontend/src/i18n/locales/en-US.ts index 652d3067..62daa5d7 100755 --- a/frontend/src/i18n/locales/en-US.ts +++ b/frontend/src/i18n/locales/en-US.ts @@ -1958,6 +1958,7 @@ export default { sampleLabel: 'Sample text', samplePlaceholder: 'Paste a Markdown / plain-text snippet to see how the current configuration would chunk it…', runButton: 'Run preview', + loading: 'Running chunker on sample…', errorPrefix: 'Preview failed', selectedTier: 'Selected strategy', rejected: 'Rejected tiers', diff --git a/frontend/src/i18n/locales/ko-KR.ts b/frontend/src/i18n/locales/ko-KR.ts index 3c5369de..4ae99c74 100755 --- a/frontend/src/i18n/locales/ko-KR.ts +++ b/frontend/src/i18n/locales/ko-KR.ts @@ -2567,6 +2567,7 @@ export default { sampleLabel: "샘플 텍스트", samplePlaceholder: "현재 구성으로 어떻게 청크되는지 보려면 Markdown / 일반 텍스트 스니펫을 붙여넣으세요…", runButton: "미리보기 실행", + loading: "샘플에 대해 청커 실행 중…", errorPrefix: "미리보기 실패", selectedTier: "선택된 전략", rejected: "거부된 계층", diff --git a/frontend/src/i18n/locales/ru-RU.ts b/frontend/src/i18n/locales/ru-RU.ts index e7351324..22dbf8ea 100755 --- a/frontend/src/i18n/locales/ru-RU.ts +++ b/frontend/src/i18n/locales/ru-RU.ts @@ -2170,6 +2170,7 @@ export default { sampleLabel: 'Пример текста', samplePlaceholder: 'Вставьте фрагмент Markdown / простого текста, чтобы увидеть, как его разобьет текущая конфигурация…', runButton: 'Запустить предпросмотр', + loading: 'Запуск разбиения на примере…', errorPrefix: 'Ошибка предпросмотра', selectedTier: 'Выбранная стратегия', rejected: 'Отклоненные уровни', diff --git a/frontend/src/i18n/locales/zh-CN.ts b/frontend/src/i18n/locales/zh-CN.ts index 69778435..8de49b90 100755 --- a/frontend/src/i18n/locales/zh-CN.ts +++ b/frontend/src/i18n/locales/zh-CN.ts @@ -2526,6 +2526,7 @@ export default { sampleLabel: "示例文本", samplePlaceholder: "粘贴 Markdown / 纯文本片段以查看当前配置的分块结果…", runButton: "运行预览", + loading: "正在对示例运行分块器…", errorPrefix: "预览失败", selectedTier: "选定策略", rejected: "被拒绝的层级", diff --git a/frontend/src/views/knowledge/settings/KBChunkingDebug.vue b/frontend/src/views/knowledge/settings/KBChunkingDebug.vue index 51ce2c6f..571f7af6 100644 --- a/frontend/src/views/knowledge/settings/KBChunkingDebug.vue +++ b/frontend/src/views/knowledge/settings/KBChunkingDebug.vue @@ -19,19 +19,29 @@ {{ sample.length }} / {{ MAX_CHARS }} {{ $t('knowledgeEditor.chunking.characters') }} + {{ $t('knowledgeEditor.chunking.debug.runButton') }} -
- {{ error }} + +
+ + {{ $t('knowledgeEditor.chunking.debug.loading') }} +
+ + +
+ {{ $t('knowledgeEditor.chunking.debug.errorPrefix') }}: {{ error }}
@@ -196,14 +206,25 @@ const runPreview = async () => { languages: props.config.languages ?? [] } }) - if (!resp.success) { - throw new Error('preview failed') + // The axios interceptor in utils/request.ts already unwraps the + // outer envelope and returns the response body. So resp here is + // { success: true, data: PreviewChunkingResponse } directly. + if (!resp || resp.success !== true || !resp.data) { + throw new Error('unexpected response shape') } result.value = resp.data } catch (e: any) { - const msg = e?.message || e?.toString() || 'unknown error' - error.value = t('knowledgeEditor.chunking.debug.errorPrefix') + ': ' + msg - MessagePlugin.error(error.value) + // Pull a useful message out of the error shapes our request layer + // produces: rejected interceptor sends { status, message, ... }. + const msg = + e?.message || + (typeof e === 'string' ? e : '') || + 'unknown error' + error.value = msg + // Console log so users can debug from DevTools too. + console.error('[KBChunkingDebug] previewChunking failed:', e) + // Toast for visibility. + MessagePlugin.error(t('knowledgeEditor.chunking.debug.errorPrefix') + ': ' + msg) } finally { loading.value = false } @@ -309,14 +330,31 @@ const tierTheme = (tier: StrategyTier) => { } } +.debug-loading { + margin-top: 16px; + display: flex; + align-items: center; + gap: 10px; + padding: 12px 14px; + background: var(--td-bg-color-container-hover); + border-radius: 4px; + font-size: 13px; + color: var(--td-text-color-secondary); +} + .debug-error { margin-top: 12px; - padding: 10px 14px; + padding: 12px 14px; background: var(--td-error-color-light); border-left: 3px solid var(--td-error-color); color: var(--td-error-color); font-size: 13px; border-radius: 0 4px 4px 0; + font-weight: 500; + + strong { + margin-right: 4px; + } } .debug-result {