Skip to content

Commit 1941e55

Browse files
committed
Fix more of the lints!
1 parent 8040e2f commit 1941e55

File tree

1 file changed

+37
-32
lines changed

1 file changed

+37
-32
lines changed

projects/packages/jetpack-mu-wpcom/src/features/wpcom-blocks/code/block-edit-function/block-edit-function.tsx

Lines changed: 37 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -332,44 +332,49 @@ function EditCodeMirror( props: EditBlockProps ) {
332332
} );
333333
}, [ makeExtensions ] );
334334

335-
React.useEffect( () => {
336-
if ( ! ref.current || viewRef.current ) {
337-
return;
338-
}
339-
340-
viewRef.current = new View.EditorView( {
341-
doc: attributes.code,
342-
extensions: makeExtensions(),
343-
parent: ref.current,
344-
} );
335+
React.useEffect(
336+
() => {
337+
if ( ! ref.current || viewRef.current ) {
338+
return;
339+
}
345340

346-
viewRef.current.contentDOM.addEventListener(
347-
'keydown',
348-
selectAllEventHandlerRef.current.handler
349-
);
350-
351-
if ( attributes.language ) {
352-
languageUtils.getLanguage( attributes.language ).then( ( [ , extension ] ) => {
353-
currentLanguageRef.current = extension;
354-
viewRef.current?.dispatch( {
355-
effects: [
356-
State.StateEffect.appendConfig.of( {
357-
extension,
358-
} ),
359-
],
360-
} );
341+
viewRef.current = new View.EditorView( {
342+
doc: attributes.code,
343+
extensions: makeExtensions(),
344+
parent: ref.current,
361345
} );
362-
}
363346

364-
return () => {
365-
viewRef.current?.contentDOM.removeEventListener(
347+
viewRef.current.contentDOM.addEventListener(
366348
'keydown',
367349
selectAllEventHandlerRef.current.handler
368350
);
369-
viewRef.current?.destroy();
370-
viewRef.current = undefined;
371-
};
372-
}, [] );
351+
352+
if ( attributes.language ) {
353+
languageUtils.getLanguage( attributes.language ).then( ( [ , extension ] ) => {
354+
currentLanguageRef.current = extension;
355+
viewRef.current?.dispatch( {
356+
effects: [
357+
State.StateEffect.appendConfig.of( {
358+
extension,
359+
} ),
360+
],
361+
} );
362+
} );
363+
}
364+
365+
return () => {
366+
viewRef.current?.contentDOM.removeEventListener(
367+
'keydown',
368+
// eslint-disable-next-line react-hooks/exhaustive-deps
369+
selectAllEventHandlerRef.current.handler
370+
);
371+
viewRef.current?.destroy();
372+
viewRef.current = undefined;
373+
};
374+
},
375+
// eslint-disable-next-line react-hooks/exhaustive-deps -- This should only run for initialization.
376+
[]
377+
);
373378

374379
// Update language when changed
375380
React.useEffect( () => {

0 commit comments

Comments
 (0)