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.
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.
The Problem
In Dart SDK versions with null-safety enabled, the interop for
MouseEvent.dataTransfer
is non-nullable despite the JS spec fordataTransfer
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 thedataTransfer
getter is then accessed when running withsound_null_safety
enabled:The Solution
While we cannot fix the native
MouseEvent.dataTransfer
issue directly, we can monkey patch this flawed non-null assertion for theSyntheticMouseEvent.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 thewrapNativeMouseEvent
implementation to makeSyntheticMouseEvent.dataTransfer
access the newsafeDataTransfer
getter instead of the nativeMouseEvent.dataTransfer
directly.QA