Skip to content

Commit 3890faf

Browse files
FindHaofacebook-github-bot
authored andcommitted
PR6: Add Monaco editor (#114)
Summary: - Hardens Monaco Diff Editor lifecycle and option synchronization for consistent VSCode-style diffs. - Ensures both sides have word wrap on by default and mitigates disposal errors during navigation. #### Key Changes - `website/src/components/DiffComparisonView.tsx` sets `wordWrap`, `wordWrapOverride1/2`, `diffWordWrap`, `wordWrapMinified`, `wrappingStrategy` and updates options on layout/events. - Adds explicit `editor.dispose()` and `editor.setModel(null)` in unmount cleanup to prevent "TextModel got disposed" errors. - `FileDiffView` optionally unmounts diff (`hideDiff`) before navigation to avoid Monaco race conditions. Pull Request resolved: #114 Reviewed By: sfzhu93 Differential Revision: D82745927 Pulled By: FindHao fbshipit-source-id: 7b7787c77d91556c26951a58ed0250de9ec7d4e7
1 parent 5c4a6ca commit 3890faf

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

website/src/components/DiffComparisonView.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,15 @@ const DiffComparisonView: React.FC<DiffComparisonViewProps> = ({
8787
return () => {
8888
try {
8989
const editor: any = editorRef.current;
90-
if (editor && typeof editor.dispose === 'function') {
91-
editor.dispose();
90+
if (editor) {
91+
try { editor.setModel?.(null); } catch {}
92+
try { editor.getOriginalEditor?.()?.setModel?.(null); } catch {}
93+
try { editor.getModifiedEditor?.()?.setModel?.(null); } catch {}
94+
try { editor.dispose?.(); } catch {}
9295
}
9396
} catch {}
97+
editorRef.current = null as any;
98+
try { (window as any).__DIFF = undefined; } catch {}
9499
};
95100
}, []);
96101

@@ -200,5 +205,3 @@ const DiffComparisonView: React.FC<DiffComparisonViewProps> = ({
200205
};
201206

202207
export default DiffComparisonView;
203-
204-

website/src/pages/FileDiffView.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,10 +186,10 @@ const FileDiffView: React.FC<FileDiffViewProps> = ({ kernelsLeft, selectedLeftIn
186186
if (sessLeftLen === 0 && kernelsLeft.length > 0) {
187187
if (leftLoadedUrl) {
188188
sess.setLeftFromUrl(leftLoadedUrl, kernelsLeft);
189-
189+
190190
} else {
191191
sess.setLeftFromLocal(kernelsLeft);
192-
192+
193193
}
194194
sess.setLeftIdx(Math.max(0, leftIdx));
195195
}
@@ -305,6 +305,7 @@ const FileDiffView: React.FC<FileDiffViewProps> = ({ kernelsLeft, selectedLeftIn
305305
</div>
306306
{!hideDiff && (
307307
<DiffComparisonView
308+
key={`single-${leftIdx}-${rightIdx}-${irType}`}
308309
leftContent={leftContent}
309310
rightContent={rightContent}
310311
height="calc(100vh - 14rem)"
@@ -350,6 +351,7 @@ const FileDiffView: React.FC<FileDiffViewProps> = ({ kernelsLeft, selectedLeftIn
350351
<div className="px-2 pb-2">
351352
{!hideDiff && (
352353
<DiffComparisonView
354+
key={`all-${t}-${leftIdx}-${rightIdx}`}
353355
leftContent={leftContent}
354356
rightContent={rightContent}
355357
height="calc(100vh - 14rem)"
@@ -641,5 +643,3 @@ const FileDiffView: React.FC<FileDiffViewProps> = ({ kernelsLeft, selectedLeftIn
641643
};
642644

643645
export default FileDiffView;
644-
645-

0 commit comments

Comments
 (0)