Skip to content

CPLAT-12469 Update to React 17 #277

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

Merged
merged 14 commits into from
Nov 4, 2020
Merged

Conversation

joebingham-wk
Copy link
Collaborator

@joebingham-wk joebingham-wk commented Sep 4, 2020

  • Updated to React 17
  • Removed deprecated APIs that are no longer in use:
    • setReactConfiguration - sourcegraph
    • setReactDOMConfiguration - sourcegraph
    • ReactDartComponentFactoryProxy.reactComponentFactory and ReactDartComponentFactoryProxy2.reactComponentFactory - sourcegraph
    • ReactJsContextComponentFactoryProxy.factory, ReactJsComponentFactoryProxy.factory, and ReactDomComponentFactoryProxy.factory - sourcegraph

QA Instructions

  • verify CI passes
  • verify that over_react CI is passing
  • verify examples work as expected

Please review: @joebingham-wk @aaronlademann-wf @greglittlefield-wf

@joebingham-wk joebingham-wk requested review from kealjones-wk and removed request for kealjones-wk September 4, 2020 21:40
@joebingham-wk
Copy link
Collaborator Author

@kealjones-wk

joebingham-wk and others added 3 commits September 8, 2020 09:27
* master: (46 commits)
  react 5.6.0
  Add missing stuff to 5.5.1 changelog entry
  Don't check dartfmt when using the dev build of Dart
  Remove print statement
  Fix forwardRef2/useImperativeHandle typing, update tests to use forwardRef2 and test all ref types
  Rename test utility
  react 5.5.1
  Add regression test for passing forwardRef2 into memo2
  Reinstate tests for memo and forwardRef
  Address CR feedback related to comments
  useImperativeHandle should not throw if ref is null
  Run npm audit fix, build JS sources
  Remove unused ref un-conversion logic
  Improve doc comment
  Cleanup / comments
  Format
  Fix lints
  Clean up test case objects
  Improve forwardRef and base ref tests, fix chaining of converted refs
  Relocate similar event handler unconversion logic
  ...
Comment on lines 134 to 148
// Must call checkPropTypes manually because React moved away from using the `prop-types` package.
// See: https://github.com/facebook/react/pull/18127
// React now uses its own internal cache of errors for PropTypes which broke `PropTypes.resetWarningCache()`.
// Solution was to use `PropTypes.checkPropTypes` directly which makes `PropTypes.resetWarningCache()` work.
// Solution from: https://github.com/facebook/react/issues/18251#issuecomment-609024557
// TODO: figure out how to get the `displayName` here...
React.PropTypes.checkPropTypes(jsConfig.propTypes, this.props, 'prop', this._getDisplayName());
var result = dartInteropStatics.handleRender(this.dartComponent, this.props, this.state, this.context);
if (typeof result === 'undefined') result = null;
return result;
}
// Hacky workaround to get the displayName for `checkPropTypes` call.
_getDisplayName() {
return ReactDartComponent2.displayName;
}
Copy link
Collaborator

@kealjones-wk kealjones-wk Sep 10, 2020

Choose a reason for hiding this comment

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

It should be noted that I opted for this route to prevent breakages in the PropTypes api, specifically the resetWarningCache() react has opted to build in their own "prop-types" rather than using the external package. Currently react does not provide a way to reset the warning cache of itself, which we use quite a bit in tests, so i opted to use the external package. It is also unclear what the future holds for prop-types in general so the external package is a safer bet for long term support as the React team feels that Typescript on its own provides most of the prop type checks statically, unfortunately dart types do not support things such as Literal Types, Tuples, Unions, Optional/Required fields (i mean they kinda do but not as nicely), etc...

@sydneyjodon-wk sydneyjodon-wk changed the base branch from master to 6.0.0-wip October 15, 2020 22:13
@sydneyjodon-wk sydneyjodon-wk changed the title Test React 17 RC CPLAT-12469 Update to React 17 Oct 21, 2020
@sydneyjodon-wk
Copy link
Collaborator

Dart stable is failing from master, but 2.9.2 is passing.

@sydneyjodon-wk sydneyjodon-wk marked this pull request as ready for review October 21, 2020 23:04
// React now uses its own internal cache of errors for PropTypes which broke `PropTypes.resetWarningCache()`.
// Solution was to use `PropTypes.checkPropTypes` directly which makes `PropTypes.resetWarningCache()` work.
// Solution from: https://github.com/facebook/react/issues/18251#issuecomment-609024557
React.PropTypes.checkPropTypes(jsConfig.propTypes, this.props, 'prop', ReactDartComponent2.displayName);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Two things:

  1. can we wrap this in a compile-time check so that this call isn't present in the dev bundle?
Suggested change
React.PropTypes.checkPropTypes(jsConfig.propTypes, this.props, 'prop', ReactDartComponent2.displayName);
if (process.env.NODE_ENV !== 'production') {
React.PropTypes.checkPropTypes(jsConfig.propTypes, this.props, 'prop', ReactDartComponent2.displayName);
}
  1. Can we update the propTypes tests to verify that the correct displayName is being passed? RIght now we capture all of the information passed into prop validators but only test some of it

Copy link
Collaborator

Choose a reason for hiding this comment

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

It seems like the displayName is being tested here? Do you want me to add that check in both places?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh good catch! It looks like that test would pass if the name is ReactDartComponent2, though, and we wouldn't be able to tell if the wrong name is being passed in.

Now that it's wrapped in that assertsEnabled() check, though (which wasn't present when the original test was written), I think that case shouldn't happen, and we could update it like so:

-'componentName': anyOf('PropTypesTestComponent', 'ReactDartComponent2'),
+'componentName': 'PropTypesTestComponent',

and then we'd know for sure that the test name is being passed through.

Would you mind updating that test so that we get full coverage on this code?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Updated in 2978197!

Copy link
Collaborator

@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.

+10

@greglittlefield-wf greglittlefield-wf merged commit f20d343 into 6.0.0-wip Nov 4, 2020
@joebingham-wk joebingham-wk added this to the 6.0.0 milestone Nov 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants