Skip to content

Commit ee75472

Browse files
authored
[Beta] Fix editor re-renders on lint error (#4699)
1 parent c209465 commit ee75472

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

beta/src/components/MDX/Sandpack/Preview.tsx

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,23 @@ export function Preview({
6161
rawError = null;
6262
}
6363

64-
if (lintErrors.length > 0) {
65-
if (rawError == null || rawError.title === 'Runtime Exception') {
66-
// When there's a lint error, show it -- even over a runtime error.
67-
// (However, when there's a build error, we keep showing the build one.)
64+
// Memoized because it's fed to debouncing.
65+
const firstLintError = React.useMemo(() => {
66+
if (lintErrors.length === 0) {
67+
return null;
68+
} else {
6869
const {line, column, message} = lintErrors[0];
69-
rawError = {
70+
return {
7071
title: 'Lint Error',
7172
message: `${line}:${column} - ${message}`,
7273
};
7374
}
75+
}, [lintErrors]);
76+
77+
if (rawError == null || rawError.title === 'Runtime Exception') {
78+
if (firstLintError !== null) {
79+
rawError = firstLintError;
80+
}
7481
}
7582

7683
// It changes too fast, causing flicker.

0 commit comments

Comments
 (0)