From 58873ea606dc50fd5978d8d88be66d5f8d4c06b1 Mon Sep 17 00:00:00 2001 From: Gregory Schier Date: Wed, 4 Jun 2025 10:38:55 -0700 Subject: [PATCH] Fix text streaming breaking scroll --- src-web/components/responseViewers/TextViewer.tsx | 5 ++--- src-web/hooks/useFormatText.ts | 5 +++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src-web/components/responseViewers/TextViewer.tsx b/src-web/components/responseViewers/TextViewer.tsx index 86cdbd16..4a647124 100644 --- a/src-web/components/responseViewers/TextViewer.tsx +++ b/src-web/components/responseViewers/TextViewer.tsx @@ -100,8 +100,7 @@ export function TextViewer({ language, text, responseId, requestId, pretty, clas ]); const formattedBody = useFormatText({ text, language, pretty }); - - if (formattedBody.data == null) { + if (formattedBody == null) { return null; } @@ -113,7 +112,7 @@ export function TextViewer({ language, text, responseId, requestId, pretty, clas body = filteredResponse.data != null ? filteredResponse.data : ''; } } else { - body = formattedBody.data; + body = formattedBody; } // Decode unicode sequences in the text to readable characters diff --git a/src-web/hooks/useFormatText.ts b/src-web/hooks/useFormatText.ts index ed5f6c47..d8d026e3 100644 --- a/src-web/hooks/useFormatText.ts +++ b/src-web/hooks/useFormatText.ts @@ -1,6 +1,6 @@ import { useQuery } from '@tanstack/react-query'; -import { tryFormatJson, tryFormatXml } from '../lib/formatters'; import type { EditorProps } from '../components/core/Editor/Editor'; +import { tryFormatJson, tryFormatXml } from '../lib/formatters'; export function useFormatText({ text, @@ -12,6 +12,7 @@ export function useFormatText({ pretty: boolean; }) { return useQuery({ + placeholderData: (prev) => prev, // Keep previous data on refetch queryKey: [text, language, pretty], queryFn: async () => { if (text === '' || !pretty) { @@ -24,5 +25,5 @@ export function useFormatText({ return text; } }, - }); + }).data; }