Skip to content

Commit b5e84cc

Browse files
committed
Fix error loading later on in the editor
1 parent 3b49571 commit b5e84cc

File tree

5 files changed

+29
-12
lines changed

5 files changed

+29
-12
lines changed

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -504,13 +504,15 @@ class MonacoEditor extends React.Component<Props> implements Editor {
504504
this.currentTitle = newModule.title;
505505
this.currentDirectoryShortid = newModule.directoryShortid;
506506

507-
if (errors) {
508-
this.setErrors(errors);
509-
}
510-
511-
if (corrections) {
512-
this.setCorrections(corrections);
513-
}
507+
// Let the model load first
508+
setTimeout(() => {
509+
if (errors) {
510+
this.setErrors(errors);
511+
}
512+
if (corrections) {
513+
this.setCorrections(corrections);
514+
}
515+
}, 100);
514516

515517
if (this.props.onCodeReceived) {
516518
// Whenever the user changes a module we set up a state that defines

packages/app/src/app/store/modules/editor/actions.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,16 @@ export function addCorrectionFromPreview({ state, props }) {
276276
state.push('editor.corrections', correction);
277277
}
278278

279+
export function clearErrors({ state, props }) {
280+
const currentErrors = state.get('editor.errors');
281+
282+
const newErrors = clearCorrectionsFromAction(currentErrors, props.action);
283+
284+
if (newErrors.length !== currentErrors.length) {
285+
state.set('editor.errors', newErrors);
286+
}
287+
}
288+
279289
export function clearCorrections({ state, props }) {
280290
const currentCorrections = state.get('editor.corrections');
281291

packages/app/src/app/store/modules/editor/sequences.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ export const handlePreviewAction = [
297297
),
298298
'show-error': actions.addErrorFromPreview,
299299
'show-correction': actions.addCorrectionFromPreview,
300+
'clear-errors': actions.clearErrors,
300301
'clear-corrections': actions.clearCorrections,
301302
'source.module.rename': [
302303
actions.consumeRenameModuleFromPreview,

packages/app/src/app/utils/corrections.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
import { ModuleCorrection } from '@codesandbox/common/lib/types';
1+
import { ModuleCorrection, ModuleError } from '@codesandbox/common/lib/types';
22
import { CorrectionClearAction } from 'codesandbox-api/dist/types/actions/correction';
3+
import { ErrorClearAction } from 'codesandbox-api/dist/types/actions/error';
34

4-
export function clearCorrectionsFromAction(
5-
currentCorrections: ModuleCorrection[],
6-
action: CorrectionClearAction
7-
) {
5+
export function clearCorrectionsFromAction<
6+
T extends ModuleCorrection | ModuleError
7+
>(
8+
currentCorrections: T[],
9+
action: CorrectionClearAction | ErrorClearAction
10+
): T[] {
811
if (action.path === '*') {
912
return currentCorrections.filter(cor => cor.source !== action.source);
1013
}

packages/common/src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export type ModuleError = {
1010
severity: 'error' | 'warning';
1111
type: 'compile' | 'dependency-not-found' | 'no-dom-change';
1212
payload: Object;
13+
source: string | undefined;
1314
};
1415

1516
export type ModuleCorrection = {

0 commit comments

Comments
 (0)