mirror of
https://github.com/usebruno/bruno.git
synced 2026-06-11 09:51:30 +00:00
fix: response format auto-switch on content type change (#6773)
This commit is contained in:
@@ -49,11 +49,11 @@ export const useInitialResponseFormat = (dataBuffer, headers) => {
|
||||
|
||||
// Wait until both content types are available
|
||||
if (detectedContentType === null || contentType === undefined) {
|
||||
return { initialFormat: null, initialTab: null };
|
||||
return { initialFormat: null, initialTab: null, contentType: contentType };
|
||||
}
|
||||
|
||||
const initial = getDefaultResponseFormat(contentType);
|
||||
return { initialFormat: initial.format, initialTab: initial.tab };
|
||||
return { initialFormat: initial.format, initialTab: initial.tab, contentType: contentType };
|
||||
}, [dataBuffer, headers]);
|
||||
};
|
||||
|
||||
|
||||
@@ -42,9 +42,12 @@ const ResponsePane = ({ item, collection }) => {
|
||||
const focusedTab = find(tabs, (t) => t.uid === activeTabUid);
|
||||
|
||||
// Initialize format and tab only once when data loads.
|
||||
const { initialFormat, initialTab } = useInitialResponseFormat(response?.dataBuffer, response?.headers);
|
||||
const { initialFormat, initialTab, contentType } = useInitialResponseFormat(response?.dataBuffer, response?.headers);
|
||||
const previewFormatOptions = useResponsePreviewFormatOptions(response?.dataBuffer, response?.headers);
|
||||
|
||||
// Track previous response headers to detect when content-type changes
|
||||
const previousContentRef = useRef(contentType);
|
||||
|
||||
const persistedFormat = focusedTab?.responseFormat;
|
||||
const persistedViewTab = focusedTab?.responseViewTab;
|
||||
|
||||
@@ -56,13 +59,19 @@ const ResponsePane = ({ item, collection }) => {
|
||||
if (!focusedTab || initialFormat === null || initialTab === null) {
|
||||
return;
|
||||
}
|
||||
if (persistedFormat === null) {
|
||||
|
||||
// Check if response headers (content-type) changed using deep comparison
|
||||
const contentTypeChanged = contentType !== previousContentRef.current;
|
||||
if (contentTypeChanged) {
|
||||
previousContentRef.current = contentType;
|
||||
}
|
||||
if (contentTypeChanged || persistedFormat === null) {
|
||||
dispatch(updateResponseFormat({ uid: item.uid, responseFormat: initialFormat }));
|
||||
}
|
||||
if (persistedViewTab === null) {
|
||||
if (contentTypeChanged || persistedViewTab === null) {
|
||||
dispatch(updateResponseViewTab({ uid: item.uid, responseViewTab: initialTab }));
|
||||
}
|
||||
}, [initialFormat, initialTab, persistedFormat, persistedViewTab, focusedTab, item.uid, dispatch]);
|
||||
}, [contentType, initialFormat, initialTab, persistedFormat, persistedViewTab, focusedTab, item.uid, dispatch]);
|
||||
|
||||
const handleFormatChange = useCallback((newFormat) => {
|
||||
dispatch(updateResponseFormat({ uid: item.uid, responseFormat: newFormat }));
|
||||
|
||||
Reference in New Issue
Block a user