From 02c8f6c2dda6332f19dddc74256cc01fda429d33 Mon Sep 17 00:00:00 2001 From: ChandanBalajiBP <104058110+ChandanBalajiBP@users.noreply.github.com> Date: Fri, 30 Sep 2022 20:51:04 +0530 Subject: [PATCH] fix: Slow rendering of JSON and RAW response (#16971) * fix:Slow rendering of JSON and RAW response * added debouncing for editor refresh --- .../editorComponents/ApiResponseView.tsx | 2 ++ .../editorComponents/CodeEditor/index.tsx | 18 ++++++++++++++++-- .../editorComponents/ReadOnlyEditor.tsx | 2 ++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/app/client/src/components/editorComponents/ApiResponseView.tsx b/app/client/src/components/editorComponents/ApiResponseView.tsx index 2bd1930b58..a505869944 100644 --- a/app/client/src/components/editorComponents/ApiResponseView.tsx +++ b/app/client/src/components/editorComponents/ApiResponseView.tsx @@ -265,6 +265,7 @@ export const responseTabComponent = ( return { [API_RESPONSE_TYPE_OPTIONS.JSON]: ( { return true; } + //Debounce editor refresh request as container resizing triggers many change events. + debounceEditorRefresh = _.debounce(async () => { + this.editor.refresh(); + }, 100); + componentDidUpdate(prevProps: Props): void { + if ( + prevProps.containerHeight && + this.props.containerHeight && + prevProps.containerHeight < this.props.containerHeight + ) { + //Refresh editor when the container height is increased. + this.debounceEditorRefresh(); + } this.editor.operation(() => { if (this.state.isFocused) return; // const currentMode = this.editor.getOption("mode"); @@ -359,7 +373,7 @@ class CodeEditor extends Component { const previousInputValue = getInputValue(prevProps.input.value); if (!!inputValue || inputValue === "") { - if (inputValue !== editorValue && isString(inputValue)) { + if (inputValue !== editorValue && _.isString(inputValue)) { this.editor.setValue(inputValue); this.editor.clearHistory(); // when input gets updated on focus out clear undo/redo from codeMirror History } else if (prevProps.isEditorHidden && !this.props.isEditorHidden) { diff --git a/app/client/src/components/editorComponents/ReadOnlyEditor.tsx b/app/client/src/components/editorComponents/ReadOnlyEditor.tsx index 2cfc2e67ee..cb562d9261 100644 --- a/app/client/src/components/editorComponents/ReadOnlyEditor.tsx +++ b/app/client/src/components/editorComponents/ReadOnlyEditor.tsx @@ -19,6 +19,7 @@ interface Props { showLineNumbers?: boolean; isReadOnly?: boolean; isRawView?: boolean; + containerHeight?: number; } function ReadOnlyEditor(props: Props) { @@ -39,6 +40,7 @@ function ReadOnlyEditor(props: Props) { folding: props.folding, isReadOnly: props.isReadOnly, isRawView: props.isRawView, + containerHeight: props.containerHeight, }; return ; }