Skip to content

Commit

Permalink
docs(withLiveEdit): do not fail when prettier fails to format
Browse files Browse the repository at this point in the history
prettier fails because the parsing method at withLiveEdit is currently not generic enough
  • Loading branch information
YossiSaadi committed Apr 1, 2024
1 parent ad9e946 commit 1777869
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ export function formatCode(code: string): string {
try {
return format(code, options).replace(/;\s*$/, "");
} catch (e) {
throw new Error(`[Playground Error]: Error formatting code: ${e}`);
throw new Error(`[LiveEdit Error]: Error formatting code: ${e}`);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,14 @@ const withLiveEdit: Decorator = (Story, { id, parameters, viewMode }: Parameters
};

useEffect(() => {
setCode(code => formatCode(code));
setCode(code => {
try {
return formatCode(code);
} catch (e) {
console.error(e);
return originalCode.current;
}
});
}, []);

const shouldAllowLiveEdit = viewMode === "docs" && parameters.docs?.liveEdit?.enableLiveEdit;
Expand Down

0 comments on commit 1777869

Please sign in to comment.