Workiva / react-dart

Dart Bindings for React JS
BSD 2-Clause "Simplified" License
412 stars 67 forks source link

Add null handling to synthetic event duck type checking #294

Closed aaronlademann-wf closed 3 years ago

aaronlademann-wf commented 3 years ago

Problem

When we updated the synthetic event system to use duck typing instead of Dart is type checking, we created a possible null exception that presents as seen below when the event is null:

Error: Cannot use 'in' operator to search for 'key' in null

This is a regression since before we made the switch, a check like this would have simply returned false:

final someSyntheticEvent = null;
final isSyntheticMouseEvent = someSyntheticEvent is SyntheticMouseEvent; // false

but now, it throws the exception when the logic is updated to:

final someSyntheticEvent = null;
final isSyntheticMouseEvent = someSyntheticEvent.isMouseEvent; // throws RTE

Solution

  1. Add null checks before calling hasProperty and _checkEventType.
  2. Add tests