diff --git a/.chronus/changes/fix-playground-crash-no-target-2025-2-28-17-18-31.md b/.chronus/changes/fix-playground-crash-no-target-2025-2-28-17-18-31.md new file mode 100644 index 00000000000..7a1fcd04633 --- /dev/null +++ b/.chronus/changes/fix-playground-crash-no-target-2025-2-28-17-18-31.md @@ -0,0 +1,8 @@ +--- +# Change versionKind to one of: internal, fix, dependencies, feature, deprecation, breaking +changeKind: fix +packages: + - "@typespec/playground" +--- + +Guard against diagnostic reported without a target diff --git a/packages/playground/src/react/diagnostic-list/diagnostic-list.tsx b/packages/playground/src/react/diagnostic-list/diagnostic-list.tsx index 6538acee4d4..2f58bf98482 100644 --- a/packages/playground/src/react/diagnostic-list/diagnostic-list.tsx +++ b/packages/playground/src/react/diagnostic-list/diagnostic-list.tsx @@ -64,10 +64,18 @@ const DiagnosticItem: FunctionComponent = ({ diagnostic, on }; const DiagnosticTargetLink = memo(({ target }: { target: DiagnosticTarget | typeof NoTarget }) => { + if (target === undefined) { + return ( + + No target + + ); + } if (typeof target === "symbol") { return ; } const location = getSourceLocation(target); + const file = location.file.path === "/test/main.tsp" ? "" : `${location.file.path}:`; const { line, character } = location.file.getLineAndCharacterOfPosition(location.pos); return (