Skip to content

Commit

Permalink
[Beta] Fix editor re-renders on lint error (#4699)
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon authored May 26, 2022
1 parent c209465 commit ee75472
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions beta/src/components/MDX/Sandpack/Preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,23 @@ export function Preview({
rawError = null;
}

if (lintErrors.length > 0) {
if (rawError == null || rawError.title === 'Runtime Exception') {
// When there's a lint error, show it -- even over a runtime error.
// (However, when there's a build error, we keep showing the build one.)
// Memoized because it's fed to debouncing.
const firstLintError = React.useMemo(() => {
if (lintErrors.length === 0) {
return null;
} else {
const {line, column, message} = lintErrors[0];
rawError = {
return {
title: 'Lint Error',
message: `${line}:${column} - ${message}`,
};
}
}, [lintErrors]);

if (rawError == null || rawError.title === 'Runtime Exception') {
if (firstLintError !== null) {
rawError = firstLintError;
}
}

// It changes too fast, causing flicker.
Expand Down

0 comments on commit ee75472

Please sign in to comment.