Skip to content
This repository was archived by the owner on Jul 30, 2025. It is now read-only.

Commit 56e3053

Browse files
myan9starpit
authored andcommitted
fix: LeftNavSidecar fails silently for MMR with plain text mode
Also improved error handling of Editor Fixes #3823
1 parent 4418e04 commit 56e3053

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

plugins/plugin-editor/src/view/components/Editor.tsx

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ interface State {
4545
wrapper: HTMLDivElement
4646
subscription?: IDisposable
4747
toolbarText?: ToolbarText
48+
catastrophicError: Error
4849
}
4950

5051
export default class Editor extends React.PureComponent<Props, State> {
@@ -54,10 +55,19 @@ export default class Editor extends React.PureComponent<Props, State> {
5455
// created below in render() via ref={...} -> initMonaco()
5556
this.state = {
5657
editor: undefined,
57-
wrapper: undefined
58+
wrapper: undefined,
59+
catastrophicError: undefined
5860
}
5961
}
6062

63+
public static getDerivedStateFromError(error: Error) {
64+
return { catastrophicError: error }
65+
}
66+
67+
public componentDidCatch(error: Error, errorInfo: React.ErrorInfo) {
68+
console.error('catastrophic error in Editor', error, errorInfo)
69+
}
70+
6171
/**
6272
* ToolbarText for a clean editor, i.e. no changes have been made
6373
* since last save.
@@ -190,16 +200,21 @@ export default class Editor extends React.PureComponent<Props, State> {
190200
subscription: Editor.subscribeToChanges(props, editor)
191201
}
192202
} catch (err) {
193-
console.error(err)
203+
console.error('Error initing Monaco: ', err)
204+
state.catastrophicError = err
194205
return state
195206
}
196207
}
197208

198209
public render() {
199-
return (
200-
<div className="code-highlighting">
201-
<div className="monaco-editor-wrapper" ref={wrapper => this.setState({ wrapper })}></div>
202-
</div>
203-
)
210+
if (this.state.catastrophicError) {
211+
return <div className="oops"> {this.state.catastrophicError.toString()}</div>
212+
} else {
213+
return (
214+
<div className="code-highlighting">
215+
<div className="monaco-editor-wrapper" ref={wrapper => this.setState({ wrapper })}></div>
216+
</div>
217+
)
218+
}
204219
}
205220
}

plugins/plugin-sidecar/src/view/components/LeftNavSidecar.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ export default class LeftNavSidecar extends BaseSidecar<NavResponse, State> {
175175
<KuiContent
176176
tab={this.state.tab}
177177
mode={this.state.allNavs[navIdx].tabs[tabIdx]}
178-
response={this.state.response[navIdx]}
178+
response={Object.values(this.state.response)[navIdx]}
179179
/>
180180
</React.Suspense>
181181
)

0 commit comments

Comments
 (0)