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

CPLAT-13185 Fix JsBackedMap for Dart 2.12 #305

Merged
merged 3 commits into from
Feb 17, 2021

Conversation

sydneyjodon-wk
Copy link
Collaborator

@sydneyjodon-wk sydneyjodon-wk commented Feb 16, 2021

Motivation

Dart 2.12 includes changes to setProperty that disallow passing in Dart functions, since they are not callable by JS code. dart-lang/sdk@d683f33

This breaks passing function props to Dart components, since JsBackedMap stores those values using setProperty under the hood.

  Assertion failed: org-dartlang-sdk:///lib/_internal/js_dev_runtime/private/ddc_runtime/types.dart:166:7
  _isJsObject(f) ||
            !JS<bool>('bool', '# instanceof #.Function', f, global_)
  "Dart function requires `allowInterop` to be passed to JavaScript."
  dart:sdk_internal                                        setProperty
  package:react/react_client/js_backed_map.dart 66:5       _set
  dart:sdk_internal                                        addAll
  package:react/react_client/js_backed_map.dart 96:13      addAll
  package:react/react_client/js_backed_map.dart 34:61      <fn>
  package:react/react_client/js_backed_map.dart 34:73      from
  package:react/src/react_client/factory_util.dart 167:34  generateJsProps
  package:react/react_client/component_factory.dart 86:7   generateExtendedJsProps

This is the reason that react-dart dev builds are currently failing.

We can work around this issue by wrapping Dart functions in an object, which can be passed through without issue.

  • This shouldn't affect behavior
    • On the JS side, since JS code should already be treating Dart functions as non-callable, and any functions meant to be called by the JS are properly converted first
    • On the Dart side, since nothing accesses the raw JS values in the first place

Changes

  • Added workaround based on Greg's Partial implementaion: 371f5f7
    • Applied the same workaround from JsBackedMap to ContextHelpers
  • Tests already cover both allowInterop-wrapped and non-allowInterop-wrapped functions in JsBackedMap and context tests
  • Ensure Dart dev channel builds are passing
  • Perform consumer testing in over_react, WSD, and major Wdesk repos (DPC, graph_app, home)
    • Since these change affects such a core part of React interop, we want to make sure we're confident it won't cause regressions

QA Steps

@aviary3-wk
Copy link

aviary3-wk commented Feb 16, 2021

Security Insights

The items listed below may not capture all security relevant changes. Before providing a security review, be sure to review the entire PR for security impact.

(1) Security relevant changes were detected
  • Watched file lib/src/react_client/private_utils.dart modified
  • Action Items

    • Obtain a security review; reviewer should pay special attention to insights listed above
    • Verify aviary.yaml coverage of security relevant code

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

    @semveraudit-wf
    Copy link

    semveraudit-wf commented Feb 16, 2021

    Public API Changes

    No changes to the public API found for commit 32b58a7

    Showing results for 32b58a7

    Powered by semver-audit-service. Please report any problems by filing an issue.
    Reported by the dart semver audit client 2.2.0
    Browse public API.

    Last edited UTC Feb 17 at 19:59:18

    Copy link
    Collaborator

    @corwinsheahan-wf corwinsheahan-wf left a comment

    Choose a reason for hiding this comment

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

    Just one comment!


    /// A wrapper around a value that can't be stored in its raw form
    /// within a JS object (e.g., a Dart function).
    class _ContextValue {
    Copy link
    Collaborator

    Choose a reason for hiding this comment

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

    Is this functionally any different than _JsBackedMapValue? Could just combine them into a common utility if they're not different

    Copy link
    Collaborator Author

    Choose a reason for hiding this comment

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

    You're right, I was keeping them separate because I wasn't sure if they should be private. But it probably just makes more sense to add it to the utilities file. Updated in 32b58a7

    Copy link
    Collaborator

    @aaronlademann-wf aaronlademann-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

    @evanweible-wf
    Copy link
    Collaborator

    +1 security

    Copy link
    Collaborator

    @aaronlademann-wf aaronlademann-wf left a comment

    Choose a reason for hiding this comment

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

    QA +1

    @Workiva/release-management-pp

    @rmconsole5-wk rmconsole5-wk merged commit f4add59 into master Feb 17, 2021
    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

    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.

    9 participants