react-spectrum
ef881eb4 - Fixup null reference access in Breadcrumbs `computeVisibleItems`. (#2146)

Commit
4 years ago
Fixup null reference access in Breadcrumbs `computeVisibleItems`. (#2146) * Fixup null reference access in Breadcrumbs `computeVisibleItems`. TL;DR the `current` field on a ref is `T | null` not `T` and we must guard against invalid access by first interrogating `current`. Since refs are initialized as null and can become null at runtime, blind access to `current` can lead `TypeError`s (as cited in #1979). In practice it seems this _can happen reliably_ in situations where a `Breadcrumb` component is being unmounted as part of a larger component tree. Unfortunately, I have not been able to reduce this error case to a small reproduction, therefore I have not been able to add a test explicitly to signal regressions. Still, and this is quite troubling, the Typescript compiler should be flagging invalid access such as this. I'm not sure if something has been disarmed in the tsconfig to assume `T | null` is `T` in this case, but a similar access in a [TS playground](https://www.typescriptlang.org/play?ts=3.8.3#code/JYWwDg9gTgLgBAJQKYEMDG8BmUIjgcilQ3wG4AoczAVwDsNgJbElMBJWzJI+pACgCUcAN7k4cMXDRMAzvCKY4AXhboYAOmoykyTAB4AEgBUAsgBkAqmeByAogBskIJLRgA+PrWr37AiuMkAekCWTBkpFGYAIyQ4Lx84FHk6GFAkdUlpWjkpAAtgewATHmU4BXU0aigeDTR8op4KSSIYKuZ4+woAX3IgA) is flagged as an error. This aims to fix #1979. * Rephrase comment about why we're coercing the type inference.
Author
Parents
Loading