Skip to content

Commit 12dd9e4

Browse files
authored
Greatly improve file switching performance (codesandbox#4076)
* Greatly improve file switching performance * Don't update callback even if state changes
1 parent 50e9d4f commit 12dd9e4

File tree

1 file changed

+7
-2
lines changed
  • packages/app/src/app/components/CodeEditor/VSCode

1 file changed

+7
-2
lines changed

packages/app/src/app/components/CodeEditor/VSCode/index.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ export const VSCode: React.FunctionComponent = () => {
1717
const { state, actions, effects } = useOvermind();
1818
const containerEl = useRef(null);
1919

20+
const getCurrentModule = React.useCallback(
21+
() => state.editor.currentModule,
22+
[] // eslint-disable-line
23+
);
24+
2025
useEffect(() => {
2126
const rootEl = containerEl.current;
2227
const mainContainer = effects.vscode.getEditorElement(
@@ -36,7 +41,7 @@ export const VSCode: React.FunctionComponent = () => {
3641
actions.editor.codeChanged({ code, moduleShortid })
3742
}
3843
// Copy the object, we don't want mutations in the component
39-
currentModule={json(state.editor.currentModule)}
44+
currentModule={json(getCurrentModule())}
4045
config={config}
4146
sandbox={state.editor.currentSandbox}
4247
{...(extraProps as any)}
@@ -60,9 +65,9 @@ export const VSCode: React.FunctionComponent = () => {
6065
}, [
6166
actions.editor,
6267
effects.vscode,
63-
state.editor.currentModule,
6468
state.editor.currentSandbox,
6569
state.editor.currentSandbox.template,
70+
getCurrentModule,
6671
]);
6772

6873
return (

0 commit comments

Comments
 (0)