-
Notifications
You must be signed in to change notification settings - Fork 1.8k
feat: enhance BulkEditor with local state management for editor text #5374
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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'; | ||
|
@@ -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 | ||
const [editorText, setEditorText] = useState(itemsText); | ||
|
||
useEffect(() => { | ||
if (serializeBulkKeyValue(parseBulkKeyValue(editorText || '')) !== itemsText) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 ( | ||
|
@@ -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} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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} | ||
|
There was a problem hiding this comment.
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?