Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

fix(web): stop double-encoding workflow outputs in text-generation result tab (#45450)

Lazizbek Ergashev3f94362b2462
diff --git a/web/app/components/app/text-generate/item/__tests__/result-tab.spec.tsx b/web/app/components/app/text-generate/item/__tests__/result-tab.spec.tsx
index 4e24d8bb896..25aaeacc3aa 100644
--- a/web/app/components/app/text-generate/item/__tests__/result-tab.spec.tsx
+++ b/web/app/components/app/text-generate/item/__tests__/result-tab.spec.tsx
@@ -5,8 +5,7 @@ import { WorkflowRunningStatus } from '@/app/components/workflow/types'
import { TransferMethod } from '@/types/app'
import ResultTab from '../result-tab'
-// TODO: ResultTab stringifies already serialized content again; parse once must recover the output object.
-it.fails('switches between readable workflow output with attachments and read-only raw output', async () => {
+it('switches between readable workflow output with attachments and read-only raw output', async () => {
const file: FileEntity = {
id: 'file-1',
name: 'report.txt',
diff --git a/web/app/components/app/text-generate/item/result-tab.tsx b/web/app/components/app/text-generate/item/result-tab.tsx
index 8cf200453fd..8b261c216a2 100644
--- a/web/app/components/app/text-generate/item/result-tab.tsx
+++ b/web/app/components/app/text-generate/item/result-tab.tsx
@@ -5,6 +5,15 @@ import { Markdown } from '@/app/components/base/markdown'
import CodeEditor from '@/app/components/workflow/nodes/_base/components/editor/code-editor'
import { CodeLanguage } from '@/app/components/workflow/nodes/code/types'
+const parseContent = (content: string | object) => {
+ if (typeof content !== 'string') return content
+ try {
+ return JSON.parse(content)
+ } catch {
+ return content
+ }
+}
+
const ResultTab = ({
data,
content,
@@ -42,7 +51,7 @@ const ResultTab = ({
readOnly
title={<div>JSON OUTPUT</div>}
language={CodeLanguage.json}
- value={content}
+ value={parseContent(content)}
isJSONStringifyBeauty
/>
</div>