Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions packages/bruno-app/src/components/BulkEditor/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useMemo } from 'react';
import React, { useEffect, useMemo, useState } from 'react';
import CodeEditor from 'components/CodeEditor';
import { useTheme } from 'providers/Theme';
import { useSelector } from 'react-redux';
Expand All @@ -8,11 +8,23 @@ const BulkEditor = ({ params, onChange, onToggle, onSave, onRun }) => {
const preferences = useSelector((state) => state.app.preferences);
const { displayedTheme } = useTheme();

const parsedParams = useMemo(() => serializeBulkKeyValue(params), [params]);
const itemsText = useMemo(() => serializeBulkKeyValue(params), [params]);
// Editor local state
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sanjaikumar-bruno i distinctly remember we introduced parsedParams useMemo inorder to avoid two sources of truth and the inconsistencies that get introduced with it. I remember the usage useState was causing inconsistencies within the editor behaviour, This change may cause a regression in editor behaviour. will you be able to test the behaviour throughly?

const [editorText, setEditorText] = useState(itemsText);

useEffect(() => {
if (serializeBulkKeyValue(parseBulkKeyValue(editorText || '')) !== itemsText) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are changing a state that is also a dependency of the useEffect, which will cause infinite loops and can crash the application. This might not be ideal. @sanjaikumar-bruno

We introduced useMemo to avoid this behaviour. earlier!

setEditorText(itemsText);
}
}, [editorText, itemsText]);

const handleEdit = (value) => {
const parsed = parseBulkKeyValue(value);
onChange(parsed);
if (value === editorText) {
return;
}

setEditorText(value);
onChange(parseBulkKeyValue(value || ''));
};

return (
Expand All @@ -22,7 +34,7 @@ const BulkEditor = ({ params, onChange, onToggle, onSave, onRun }) => {
mode="text/plain"
theme={displayedTheme}
font={preferences.codeFont || 'default'}
value={parsedParams}
value={editorText}
onEdit={handleEdit}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe, we will haven't found root cause of this issue.

onSave={onSave}
onRun={onRun}
Expand Down
Loading