mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-04 18:58:26 +00:00
[red-knot] Fix stale syntax errors in playground (#17280)
## Summary React requires that `key`s are unique but the constructed key for diagnostics wasn't guaranteed when two diagnostics had the same name and location. This PR fixes this by using a disambiguator map to disambiguate the key. Fixes #17276 ## Test Plan https://github.com/user-attachments/assets/f3f9d10a-ecc4-4ffe-8676-3633a12e07ce
This commit is contained in:
parent
27ecf350d8
commit
5e0f563ee4
1 changed files with 9 additions and 2 deletions
|
@ -62,9 +62,11 @@ function Items({
|
|||
);
|
||||
}
|
||||
|
||||
const uniqueIds: Map<string, number> = new Map();
|
||||
|
||||
return (
|
||||
<ul className="space-y-0.5 grow overflow-y-scroll">
|
||||
{diagnostics.map((diagnostic, index) => {
|
||||
{diagnostics.map((diagnostic) => {
|
||||
const position = diagnostic.range;
|
||||
const start = position?.start;
|
||||
const id = diagnostic.id;
|
||||
|
@ -72,8 +74,13 @@ function Items({
|
|||
const startLine = start?.line ?? 1;
|
||||
const startColumn = start?.column ?? 1;
|
||||
|
||||
const mostlyUniqueId = `${startLine}:${startColumn}-${id}`;
|
||||
|
||||
const disambiguator = uniqueIds.get(mostlyUniqueId) ?? 0;
|
||||
uniqueIds.set(mostlyUniqueId, disambiguator + 1);
|
||||
|
||||
return (
|
||||
<li key={`${startLine}:${startColumn}-${id ?? index}`}>
|
||||
<li key={`${mostlyUniqueId}-${disambiguator}`}>
|
||||
<button
|
||||
onClick={() => onGoTo(startLine, startColumn)}
|
||||
className="w-full text-start cursor-pointer select-text"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue