fix(frontend): chunking debug panel — visible loading + error states, prevent submit

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
   <form> (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
This commit is contained in:
Claude
2026-05-03 11:35:36 +00:00
committed by lyingbug
parent 8388a50c23
commit 2cc0322004
5 changed files with 51 additions and 9 deletions
+1
View File
@@ -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',
+1
View File
@@ -2567,6 +2567,7 @@ export default {
sampleLabel: "샘플 텍스트",
samplePlaceholder: "현재 구성으로 어떻게 청크되는지 보려면 Markdown / 일반 텍스트 스니펫을 붙여넣으세요…",
runButton: "미리보기 실행",
loading: "샘플에 대해 청커 실행 중…",
errorPrefix: "미리보기 실패",
selectedTier: "선택된 전략",
rejected: "거부된 계층",
+1
View File
@@ -2170,6 +2170,7 @@ export default {
sampleLabel: 'Пример текста',
samplePlaceholder: 'Вставьте фрагмент Markdown / простого текста, чтобы увидеть, как его разобьет текущая конфигурация…',
runButton: 'Запустить предпросмотр',
loading: 'Запуск разбиения на примере…',
errorPrefix: 'Ошибка предпросмотра',
selectedTier: 'Выбранная стратегия',
rejected: 'Отклоненные уровни',
+1
View File
@@ -2526,6 +2526,7 @@ export default {
sampleLabel: "示例文本",
samplePlaceholder: "粘贴 Markdown / 纯文本片段以查看当前配置的分块结果…",
runButton: "运行预览",
loading: "正在对示例运行分块器…",
errorPrefix: "预览失败",
selectedTier: "选定策略",
rejected: "被拒绝的层级",
@@ -19,19 +19,29 @@
<span :class="{ warn: sample.length > MAX_CHARS * 0.8 }">
{{ sample.length }} / {{ MAX_CHARS }} {{ $t('knowledgeEditor.chunking.characters') }}
</span>
<!-- type="button" prevents any accidental parent-form submit. -->
<t-button
type="button"
theme="primary"
:loading="loading"
:disabled="!sample || sample.length === 0"
@click="runPreview"
@click.prevent.stop="runPreview"
>
{{ $t('knowledgeEditor.chunking.debug.runButton') }}
</t-button>
</div>
</div>
<div v-if="error" class="debug-error">
{{ error }}
<!-- Loading state — explicit so the user sees something is happening
even if the result block hasn't appeared yet. -->
<div v-if="loading" class="debug-loading">
<t-loading size="small" />
<span>{{ $t('knowledgeEditor.chunking.debug.loading') }}</span>
</div>
<!-- Error block: prominent so it can't be missed when an API call fails. -->
<div v-if="error && !loading" class="debug-error">
<strong>{{ $t('knowledgeEditor.chunking.debug.errorPrefix') }}:</strong> {{ error }}
</div>
<div v-if="result && !loading" class="debug-result">
@@ -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 {