Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FED-2812 Catch MouseEvent.dataTransfer null exception #398

Merged
merged 2 commits into from
Jun 7, 2024

Conversation

aaronlademann-wf
Copy link
Collaborator

@aaronlademann-wf aaronlademann-wf commented Jun 7, 2024

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: [NO MERGE] MouseEvent.dataTransfer null exception - test failure example #397)
  2. Verify that the same test is passing in this PR.

Its possible in JS for MouseEvent.dataTransfer to be null - but in Dart SDK’s interop, its non nullable.
@aaronlademann-wf aaronlademann-wf changed the title FED-2812 Catch SyntheticMouseEvent.dataTransfer null exception FED-2812 Catch MouseEvent.dataTransfer null exception Jun 7, 2024
@aviary-wf
Copy link

Security Insights

No security relevant content was detected by automated scans.

Action Items

  • Review PR for security impact; comment "security review required" if needed or unsure
  • Verify aviary.yaml coverage of security relevant code

Questions or Comments? Reach out on Slack: #support-infosec.

Copy link
Contributor

@KealJones KealJones left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

lib/src/react_client/event_helpers.dart Outdated Show resolved Hide resolved
Copy link
Contributor

@KealJones KealJones left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+10

Copy link
Collaborator

@kealjones-wk kealjones-wk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+10

@aaronlademann-wf
Copy link
Collaborator Author

@Workiva/release-management-pp

Copy link

@rmconsole-wf rmconsole-wf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 from RM

@rmconsole6-wk rmconsole6-wk merged commit dcc645b into master Jun 7, 2024
4 checks passed
@rmconsole6-wk rmconsole6-wk deleted the null-safe-dataTransfer branch June 7, 2024 16:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants