diff --git a/.changeset/async-focus-blur-issue.md b/.changeset/async-focus-blur-issue.md new file mode 100644 index 0000000..83c0e98 --- /dev/null +++ b/.changeset/async-focus-blur-issue.md @@ -0,0 +1,5 @@ +--- +"@noriginmedia/norigin-spatial-navigation-core": patch +--- + +Fix for a race condition where `onIntermediateNodeBecameBlurred` and `onIntermediateNodeBecameFocused` functions could throw a _TypeError_ if the component no longer existed once promises resolve. diff --git a/packages/core/src/SpatialNavigation.ts b/packages/core/src/SpatialNavigation.ts index 112a2be..00ca4e1 100644 --- a/packages/core/src/SpatialNavigation.ts +++ b/packages/core/src/SpatialNavigation.ts @@ -1776,7 +1776,7 @@ export class SpatialNavigationService { ) { if (this.isParticipatingFocusableComponent(focusKey)) { this.getNodeLayoutByFocusKey(focusKey).then((layout) => { - this.focusableComponents[focusKey].onFocus(layout, focusDetails); + this.focusableComponents[focusKey]?.onFocus(layout, focusDetails); }); } } @@ -1787,7 +1787,7 @@ export class SpatialNavigationService { ) { if (this.isParticipatingFocusableComponent(focusKey)) { this.getNodeLayoutByFocusKey(focusKey).then((layout) => { - this.focusableComponents[focusKey].onBlur(layout, focusDetails); + this.focusableComponents[focusKey]?.onBlur(layout, focusDetails); }); } }