Skip to content

Commit cd8d8ca

Browse files
committed
Ensure Monaco layout() calls defer until cleared content is be unloaded
Previously, unloading an editor full of content could be expensive. My beset guess here is that this was caused by Monaco being unmounted (moving into a world where it was effectively tiny) but not yet updating the content itself, and then relayout this being extremely expensive (imagine calculating line wrapping on a 1px x 1px square). When clearing, we now defer the relayout slightly, which seems to reliably avoid this case and give us an instant relayout instead.
1 parent 990cc2e commit cd8d8ca

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/components/editor/base-editor.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,13 @@ class BaseEditor extends React.Component<EditorProps> {
260260
new this.monaco.Selection(0, 0, 0, 0)
261261
);
262262

263-
this.relayout();
263+
if (!this.props.value) {
264+
// If we've been cleared, make sure that content update fires before we
265+
// attempt to relayout, to ensure we don't bother laying out an empty editor.
266+
requestAnimationFrame(() => this.relayout());
267+
} else {
268+
this.relayout();
269+
}
264270

265271
requestAnimationFrame(() => {
266272
if (this.editor && this.monaco) {

0 commit comments

Comments
 (0)