Skip to content

Commit 60f8eda

Browse files
Merge pull request #285 from Workiva/6.0.0-wip
RM-93030 Release react-dart 6.0.0
2 parents 277cf61 + d4a9e9c commit 60f8eda

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+14055
-13820
lines changed

CHANGELOG.md

+12
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
## [6.0.0](https://github.com/cleandart/react-dart/compare/5.7.1...6.0.0)
2+
3+
This stable, __major__ release of react includes:
4+
5+
### ReactJS 17.x Support
6+
7+
The underlying `.js` files provided by this package are now ReactJS version `17.0.1`.
8+
9+
> __[Full List of Breaking Changes](https://github.com/cleandart/react-dart/pull/285)__
10+
11+
> __[React 17 Release Blog Post](https://reactjs.org/blog/2020/10/20/react-v17.html)__
12+
113
## [5.7.1](https://github.com/cleandart/react-dart/compare/5.7.0...5.7.1)
214

315
- [#289] Update most deprecations that were slated for removal in v6.0.0 to be slated for removal in v7.0.0 instead. To keep the migration to v6.0.0 as easy as possible, only APIs that are known to be completely unused will be removed in v6.0.0. Therefore, most APIs that were marked for removal in v6.0.0 will remain until the v7.0.0 release. This PR updated deprecation annotations to reflect this.

README.md

+27-52
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Dart wrapper for [React JS](https://reactjs.org/)
22

33
[![Pub](https://img.shields.io/pub/v/react.svg)](https://pub.dev/packages/react)
4-
![ReactJS v16.10.1](https://img.shields.io/badge/React_JS-v16.10.1-green.svg)
4+
![ReactJS v17.0.1](https://img.shields.io/badge/React_JS-v17.0.1-green.svg)
55
[![Dart CI](https://github.com/Workiva/react-dart/workflows/Dart%20CI/badge.svg?branch=master)](https://github.com/Workiva/react-dart/actions?query=workflow%3A%22Dart+CI%22+branch%3Amaster)
66
[![React Dart API Docs](https://img.shields.io/badge/api_docs-react-blue.svg)](https://pub.dev/documentation/react/latest/)
77

@@ -11,7 +11,7 @@ _Thanks to the folks at [Vacuumlabs](https://www.vacuumlabs.com/) for creating t
1111

1212
### Installation
1313

14-
If you are not familiar with the ReactJS library, read this [react tutorial](http://facebook.github.io/react/docs/getting-started.html) first.
14+
If you are not familiar with the ReactJS library, read this [react tutorial](https://reactjs.org/docs/getting-started.html) first.
1515

1616
1. Install the Dart SDK
1717

@@ -25,9 +25,9 @@ If you are not familiar with the ReactJS library, read this [react tutorial](htt
2525
name: your_package_name
2626
version: 1.0.0
2727
environment:
28-
sdk: ^2.0.0
28+
sdk: ^2.7.0
2929
dependencies:
30-
react: ^5.0.0
30+
react: ^6.0.0
3131
```
3232

3333
3. Install the dependencies using pub:
@@ -123,10 +123,10 @@ var aButton = button({"onClick": (SyntheticMouseEvent event) => print(event)});
123123
2. Then register the class so ReactJS can recognize it.
124124
125125
```dart
126-
var CoolWidget = registerComponent(() => new CoolWidgetComponent());
126+
var CoolWidget = registerComponent2(() => CoolWidgetComponent());
127127
```
128128
129-
> __Warning:__ `registerComponent` should be called only once per component and lifetime of application.
129+
> __Warning:__ `registerComponent2` should be called only once per component and lifetime of application.
130130
131131
3. Then you can use the registered component similarly as native elements.
132132
@@ -159,7 +159,7 @@ class CoolWidgetComponent extends Component2 {
159159
}
160160
}
161161
162-
var CoolWidget = registerComponent(() => new CoolWidgetComponent());
162+
var CoolWidget = registerComponent2(() => CoolWidgetComponent());
163163
```
164164
165165
```dart
@@ -181,14 +181,14 @@ main() {
181181
182182
> __Note:__ The typed interface capabilities of this library are fairly limited, and can result in
183183
extremely verbose implementations. We strongly recommend using the
184-
[OverReact](https://pub.dartlang.org/packages/over_react) package - which
184+
[OverReact](https://pub.dev/packages/over_react) package - which
185185
makes creating statically-typed React UI components using Dart easy.
186186
187187
```dart
188188
// cool_widget.dart
189189
typedef CoolWidgetType({String headline, String text, int counter});
190190
191-
var _CoolWidget = registerComponent(() => new CoolWidgetComponent());
191+
var _CoolWidget = registerComponent2(() => CoolWidgetComponent());
192192
193193
CoolWidgetType CoolWidget({String headline, String text, int counter}) {
194194
return _CoolWidget({'headline':headline, 'text':text});
@@ -286,7 +286,7 @@ If you want to work with DOM nodes of dart or JS components instead,
286286
you can call top level `findDOMNode` on anything the ref returns.
287287
288288
```dart
289-
var DartComponent = registerComponent(() => new _DartComponent());
289+
var DartComponent = registerComponent2(() => _DartComponent());
290290
class _DartComponent extends Component2 {
291291
@override
292292
render() => div({});
@@ -296,16 +296,16 @@ class _DartComponent extends Component2 {
296296
}
297297
}
298298
299-
var ParentComponent = registerComponent(() => new _ParentComponent());
299+
var ParentComponent = registerComponent2(() => _ParentComponent());
300300
class _ParentComponent extends Component2 {
301-
InputElement inputRef; // Returns the DOM node.
302-
_DartComponent dartComponentRef; // Returns instance of _DartComponent
301+
final inputRef = createRef<InputElement>(); // inputRef.current is the DOM node.
302+
final dartComponentRef = createRef<_DartComponent>(); // dartComponentRef.current is the instance of _DartComponent
303303
304304
@override
305305
void componentDidMount() {
306-
print(inputRef.value); // Prints "hello" to the console.
306+
print(inputRef.current.value); // Prints "hello" to the console.
307307
308-
dartComponentRef.someInstanceMethod(5); // Calls the method defined in _DartComponent
308+
dartComponentRef.current.someInstanceMethod(5); // Calls the method defined in _DartComponent
309309
react_dom.findDOMNode(dartComponentRef); // Returns div element rendered from _DartComponent
310310
311311
react_dom.findDOMNode(this); // Returns root dom element rendered from this component
@@ -314,26 +314,26 @@ class _ParentComponent extends Component2 {
314314
@override
315315
render() {
316316
return div({},
317-
input({"ref": (ref){ inputRef = ref; }, "defaultValue": "hello"}),
318-
DartComponent({"ref": (ref) { dartComponentRef = ref; }}),
317+
input({"ref": inputRef, "defaultValue": "hello"}),
318+
DartComponent({"ref": dartComponentRef}),
319319
);
320320
}
321321
}
322322
```
323323
324324
### Example Application
325325
326-
For more robust examples take a look at our [examples](https://github.com/cleandart/react-dart/tree/master/example).
326+
For more robust examples take a look at our [examples](https://github.com/Workiva/react-dart/tree/master/example).
327327
328328
329329
330330
## Unit Testing Utilities
331331
332-
[lib/react_test_utils.dart](https://github.com/cleandart/react-dart/blob/master/lib/react_test_utils.dart) is a
332+
[lib/react_test_utils.dart](https://github.com/Workiva/react-dart/blob/master/lib/react_test_utils.dart) is a
333333
Dart wrapper for the [ReactJS TestUtils](https://reactjs.org/docs/test-utils.html) library allowing for unit tests
334334
to be made for React components in Dart.
335335
336-
Here is an example of how to use React React.addons.TestUtils. within a Dart test.
336+
Here is an example of how to use `package:react/react_test_utils.dart` within a Dart test.
337337
338338
```dart
339339
import 'package:test/test.dart';
@@ -354,7 +354,7 @@ class MyTestComponent extends react.Component2 {
354354
}
355355
}
356356
357-
var myTestComponent = react.registerComponent(() => new MyTestComponent());
357+
var myTestComponent = react.registerComponent2(() => new MyTestComponent());
358358
359359
void main() {
360360
test('should click button and set span text to "success"', () {
@@ -391,61 +391,36 @@ Format using
391391
dartfmt -l 120 -w .
392392
```
393393
394-
While we'd like to adhere to the recommended line length of 80, it's too too short for much of the code
394+
While we'd like to adhere to the recommended line length of 80, it's too short for much of the code
395395
repo written before a formatter was use, causing excessive wrapping and code that's hard to read.
396396
397-
So, we us a line length of 120 instead.
397+
So, we use a line length of 120 instead.
398398
399399
### Running Tests
400400
401-
#### Dart 2: dart2js
401+
#### dart2js
402402
403403
```bash
404404
pub run test -p chrome
405405
```
406406
_Or any other browser, e.g. `-p firefox`._
407407
408-
#### Dart 2: Dart Dev Compiler ("DDC")
408+
#### Dart Dev Compiler ("DDC")
409409
410410
```bash
411411
pub run build_runner test -- -p chrome
412412
```
413413
_DDC only works in chrome._
414414
415-
#### Dart 1: Dart VM
416-
417-
```bash
418-
pub run test -p content-shell
419-
```
420-
421-
#### Dart 1: dart2js
422-
423-
```bash
424-
pub run test -p chrome
425-
```
426-
_Or any other browser platform, e.g. `-p firefox`._
427-
428-
#### Dart 1: Dart Dev Compiler ("DDC")
429-
430-
1. In one terminal, serve the test directory using the dev compiler:
431-
```bash
432-
pub serve test --port=8090 --web-compiler=dartdevc
433-
```
434-
2. In another terminal, run the tests, referencing the port the dev compiler is using to serve the test directory:
435-
```bash
436-
pub run test -p chrome --pub-serve=8090
437-
```
438-
_DDC only works in chrome._
439-
440415
### Building React JS Source Files
441416
442417
Make sure the packages you need are dependencies in `package.json` then run:
443418
```bash
444-
npm install
419+
yarn install
445420
```
446421
447422
After modifying files any files in ./js_src/, run:
448423
449424
```bash
450-
npm run build
425+
yarn run build
451426
```

aviary.yaml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
version: 1
2+
3+
exclude:
4+
- ^example/
5+
- ^test/
6+
- ^tool/
7+
- # Ignore compiled JS files and source maps
8+
- ^lib/react\w*\.js(\.map)?$

js_src/_dart_helpers.js

+8-3
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,14 @@ function _createReactDartComponentClass2(dartInteropStatics, componentStatics, j
109109
}
110110

111111
static getDerivedStateFromProps(nextProps, prevState) {
112+
// Must call checkPropTypes manually because React moved away from using the `prop-types` package.
113+
// See: https://github.com/facebook/react/pull/18127
114+
// React now uses its own internal cache of errors for PropTypes which broke `PropTypes.resetWarningCache()`.
115+
// Solution was to use `PropTypes.checkPropTypes` directly which makes `PropTypes.resetWarningCache()` work.
116+
// Solution from: https://github.com/facebook/react/issues/18251#issuecomment-609024557
117+
if (process.env.NODE_ENV !== 'production') {
118+
React.PropTypes.checkPropTypes(jsConfig.propTypes, nextProps, 'prop', ReactDartComponent2.displayName);
119+
}
112120
let derivedState = dartInteropStatics.handleGetDerivedStateFromProps(componentStatics, nextProps, prevState);
113121
return typeof derivedState !== 'undefined' ? derivedState : null;
114122
}
@@ -153,9 +161,6 @@ function _createReactDartComponentClass2(dartInteropStatics, componentStatics, j
153161
if (jsConfig.defaultProps) {
154162
ReactDartComponent2.defaultProps = jsConfig.defaultProps;
155163
}
156-
if (jsConfig.propTypes) {
157-
ReactDartComponent2.propTypes = jsConfig.propTypes;
158-
}
159164
}
160165

161166
return ReactDartComponent2;

js_src/dart_env_dev.js

+20
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,23 @@ if (typeof window.MemoryInfo == "undefined") {
66
window.MemoryInfo.prototype = window.performance.memory.__proto__;
77
}
88
}
9+
10+
// Intercept console.warn calls and prevent excessive warnings in DDC-compiled code
11+
// when type-checking event handlers (function types that include SyntheticEvent classes).
12+
//
13+
// These warnings are a result of a workaround to https://github.com/dart-lang/sdk/issues/43939
14+
const oldConsoleWarn = console.warn;
15+
let hasWarned = false;
16+
console.warn = function() {
17+
const firstArg = arguments[0];
18+
// Use startsWith instead of indexOf as a small optimization for when large strings are logged.
19+
if (typeof firstArg === 'string' && firstArg.startsWith('Cannot find native JavaScript type (Synthetic')) {
20+
if (!hasWarned) {
21+
hasWarned = true;
22+
oldConsoleWarn.apply(console, arguments);
23+
oldConsoleWarn('The above warning is expected and is the result of a workaround to https://github.com/dart-lang/sdk/issues/43939');
24+
}
25+
} else {
26+
oldConsoleWarn.apply(console, arguments);
27+
}
28+
}

js_src/react.js

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import 'core-js/es/set';
66
import 'core-js/stable/reflect/delete-property';
77
import 'core-js/stable/object/assign';
88

9+
// Used by dart_env_dev.js
10+
import 'core-js/stable/string/starts-with';
11+
912
// Additional polyfills are included by core-js based on 'usage' and browser requirements
1013

1114
// Custom dart side methods

0 commit comments

Comments
 (0)