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

AF-232 Expose render and unmountComponentAtNode #154

Merged

Conversation

aaronlademann-wf
Copy link
Contributor

Ultimate problem:

We currently expose most of the commonly consumed methods from the react package, but not anything from its react_dom.dart. This forces consumers to import package:react/react_dom.dart, and therefore declare react as a dependency for their application.

However, this library is designed to act as an improved consumption experience for react consumers, which should include insulation from internal breaking changes without having to change the upper bound of a dependency.

How it was fixed:

  1. Proxy the react_dom.render and react_dom.unmountComponentAtNode methods from package:react/react_dom.dart, with improved function / return signatures.
  2. Update all internal consumption, and consumption documentation.
  3. Write tests.

For consumers, this should be the extent of the changes necessary to stop depending directly on react:

- import 'package:react/react_dom.dart' as react_dom;
+ import 'package:over_react/react_dom.dart' as react_dom;

Testing suggestions:

  • Passing CI build

Potential areas of regression:

None expected


FYA: @greglittlefield-wf @clairesarsam-wf @sebastianmalysa-wf @dustinlessard-wf

@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 HipChat: InfoSec Forum.

@aaronlademann-wf aaronlademann-wf force-pushed the AF-232_export-react-dom branch from ddc6ac3 to 11f23bb Compare May 4, 2018 23:19
@codecov-io
Copy link

codecov-io commented May 4, 2018

Codecov Report

Merging #154 into master will increase coverage by 0.01%.
The diff coverage is 100%.

@@            Coverage Diff             @@
##           master     #154      +/-   ##
==========================================
+ Coverage   94.51%   94.52%   +0.01%     
==========================================
  Files          33       34       +1     
  Lines        1601     1603       +2     
==========================================
+ Hits         1513     1515       +2     
  Misses         88       88

Copy link
Contributor

@greglittlefield-wf greglittlefield-wf left a comment

Choose a reason for hiding this comment

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

A couple small things, otherwise looks great!

/// Renders the provided [vDomComponent] into the DOM in the provided [mountNode]
/// and returns a reference to it based on its type:
///
/// 1. Returns an [Element] if [vDomComponent] is a [Dom] component _(e.g. [Dom.div])_.
Copy link
Contributor

Choose a reason for hiding this comment

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

#nit I think we can just say DOM component, since it doesn't necessarily have to come from [Dom].

/// > Use [unmountComponentAtNode] to unmount the instance.
///
/// > Proxies [react_dom.render].
dynamic render(ReactElement vDomComponent, Element mountNode) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it vDomComponent should be renamed to element to be consistent with our other naming conventions (or nextElement, which is what they call the variable in the React JS code).

///
/// > Proxies [react_dom.render].
dynamic render(ReactElement vDomComponent, Element mountNode) {
if (vDomComponent == null) return null;
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't need this check, since React handles this case. Plus, this would prevent the behavior of effectively unmounting a component by rendering null. Could you add a test for that case?

Copy link
Contributor Author

@aaronlademann-wf aaronlademann-wf May 8, 2018

Choose a reason for hiding this comment

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

@greglittlefield-wf it appears that the doc comment is not accurate.

If passed null, ReactDom.render throws an InvariantViolation:

'Invariant Violation: ReactDOM.render(): Invalid component element.'

I've added a test to verify that... but as far as I can tell - we don't have a way to create stateless components (or at least not one in which the return value would be ReactElement), so I've removed that bit from the doc comment.

Copy link
Contributor

Choose a reason for hiding this comment

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

We don't have a way to create those, but that could change in the future, and you could also potentially get one from a JS library, so I think we should have retained that information. Not a big deal, though.

+ This would cause the component to be unmounted, so we should just let the proxied render method do its thing when either of the args are null.
@aaronlademann-wf
Copy link
Contributor Author

@greglittlefield-wf all feedback addressed.

@sebastianmalysa-wf
Copy link
Contributor

QA +1

  • Testing instruction
  • Dev +1's
  • Dev/QA +10 with detail of what was tested
    • CI passes
    • pulled down the branch locally - all tests pass
  • Unit tests created/updated
  • All unit tests pass

@Workiva/release-management-pp

@sebastianmalysa-wf sebastianmalysa-wf merged commit 89b0672 into Workiva:master May 8, 2018
@aaronlademann-wf aaronlademann-wf deleted the AF-232_export-react-dom branch September 7, 2018 23:27
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