Skip to content

Commit

Permalink
FIX: JS error in @axe-core/react caused by stale reference to heading
Browse files Browse the repository at this point in the history
Noticed a small bug when testing out a newer version of @axe-core/react (we were on a pretty old version of react-axe), we have a case where a heading gets removed during an animation and it seems that heading-order-after is called with a stale result such that when trying to find it's index in the heading order it can't be found and we see a error in the console like `TypeError: Cannot read property 'level' of undefined`. This is a simple naive fix to not use the index if it is -1, but I'm happy to try a different strategy if somebody with more context has a better one!
  • Loading branch information
agreene-coursera authored and straker committed Jun 3, 2021
1 parent b260e4e commit 3afda4e
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/checks/navigation/heading-order-after.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,12 @@ function headingOrderAfter(results) {
return heading.ancestry === path;
});
const index = headingOrder.indexOf(heading);
headingOrder.splice(index, 1, {
level: headingOrder[index].level,
result
});
if (index > -1) {
headingOrder.splice(index, 1, {
level: headingOrder[index].level,
result
});
}
});

// remove any iframes that aren't in context (level == -1)
Expand Down

0 comments on commit 3afda4e

Please sign in to comment.