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
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions js_src/_dart_helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,21 @@ function _createReactDartComponentClass2(dartInteropStatics, componentStatics, j
return typeof derivedState !== 'undefined' ? derivedState : null;
}
render() {
// 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...

}

if (jsConfig) {
Expand All @@ -153,9 +164,6 @@ function _createReactDartComponentClass2(dartInteropStatics, componentStatics, j
if (jsConfig.defaultProps) {
ReactDartComponent2.defaultProps = jsConfig.defaultProps;
}
if (jsConfig.propTypes) {
ReactDartComponent2.propTypes = jsConfig.propTypes;
}
}

return ReactDartComponent2;
Expand Down
Loading