Skip to content

Commit 64927ba

Browse files
authored
fix(5886): FluxEditor submit should not use memoized version of script (#5897)
1 parent 5d1f6e4 commit 64927ba

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

src/dataExplorer/components/ResultsPane.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Libraries
2-
import React, {FC, lazy, Suspense, useContext} from 'react'
2+
import React, {FC, lazy, Suspense, useContext, useCallback} from 'react'
33
import {
44
DraggableResizer,
55
Orientation,
@@ -121,7 +121,7 @@ const ResultsPane: FC = () => {
121121
})
122122
}
123123

124-
const submit = () => {
124+
const submit = useCallback(() => {
125125
setStatus(RemoteDataState.Loading)
126126
query(text, {
127127
vars: rangeToParam(range),
@@ -142,7 +142,7 @@ const ResultsPane: FC = () => {
142142
event('resultReceived', {status: 'error'})
143143
setStatus(RemoteDataState.Error)
144144
})
145-
}
145+
}, [text])
146146

147147
const timeVars = [
148148
getRangeVariable(TIME_RANGE_START, range),

src/shared/components/FluxMonacoEditor.tsx

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ const FluxEditorMonaco: FC<Props> = ({
6262
variables,
6363
}) => {
6464
const connection = useRef<ConnectionManager>(null)
65-
const {setEditor} = useContext(EditorContext)
65+
const {editor, setEditor} = useContext(EditorContext)
6666
const isFluxQueryBuilder = useSelector(fluxQueryBuilder)
6767
const sessionStore = useContext(PersistanceContext)
6868
const {path} = useRouteMatch()
@@ -94,6 +94,17 @@ const FluxEditorMonaco: FC<Props> = ({
9494
sessionStore?.setSelection,
9595
])
9696

97+
useEffect(() => {
98+
if (!editor) {
99+
return
100+
}
101+
submit(editor, () => {
102+
if (onSubmitScript) {
103+
onSubmitScript()
104+
}
105+
})
106+
}, [editor, onSubmitScript])
107+
97108
const editorDidMount = (editor: EditorType) => {
98109
connection.current = setupForReactMonacoEditor(editor)
99110
connection.current.updatePreludeModel(variables)
@@ -104,11 +115,6 @@ const FluxEditorMonaco: FC<Props> = ({
104115
}
105116

106117
comments(editor)
107-
submit(editor, () => {
108-
if (onSubmitScript) {
109-
onSubmitScript()
110-
}
111-
})
112118

113119
if (autogrow) {
114120
registerAutogrow(editor)

0 commit comments

Comments
 (0)