Workiva / react-dart

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

FED-2812 Catch MouseEvent.dataTransfer null exception #398

Closed aaronlademann-wf closed 5 months ago

aaronlademann-wf commented 5 months ago

The Problem

In Dart SDK versions with null-safety enabled, the interop for MouseEvent.dataTransfer is non-nullable despite the JS spec for dataTransfer clearly indicating that it can be null.

This can cause the SDK to throw when a MouseEvent is manually constructed _(e.g. in a test utility)_, and the dataTransfer getter is then accessed when running with sound_null_safety enabled:

Unexpected null value encountered in Dart web platform libraries.

More info about these native non-null assertions can be found here if you're really curious

The Solution

While we cannot fix the native MouseEvent.dataTransfer issue directly, we can monkey patch this flawed non-null assertion for the SyntheticMouseEvent.dataTransfer property that all of our consumer's UI / tests will be accessing as they migrate to null safety.

This PR adds an extension method that catches the Dart SDK's exception in a new safeDataTransfer getter, and updates the wrapNativeMouseEvent implementation to make SyntheticMouseEvent.dataTransfer access the new safeDataTransfer getter instead of the native MouseEvent.dataTransfer directly.

QA

  1. [ ] Verify that the test added in this PR fails without the new extension method (See failing tests here: https://github.com/Workiva/react-dart/pull/397)
  2. [ ] Verify that the same test is passing in this PR.
aviary-wf commented 5 months ago

Security Insights

No security relevant content was detected by automated scans.

Action Items

aaronlademann-wf commented 5 months ago

@Workiva/release-management-pp