Skip to content

Commit d65d845

Browse files
Merge 'upstream/master' into 5.3.0-wip
# Conflicts: # lib/react.js.map # lib/react_prod.js # lib/react_prod.js.map # lib/react_with_addons.js.map # lib/react_with_react_dom_prod.js # lib/react_with_react_dom_prod.js.map
2 parents 164d2b7 + 80c592d commit d65d845

21 files changed

+2110
-1908
lines changed

.travis.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,5 @@ before_script:
1616
- pub run dependency_validator -i build_runner,build_test,build_web_compilers
1717

1818
script:
19-
# TODO once production is above 2.4.1 re-check the `fails-on-2.4.1` tagged tests
20-
- pub run build_runner test --release -- -p chrome -x fails-on-241
21-
- pub run build_runner test -- -p chrome -x fails-on-241
19+
- pub run build_runner test --release -- -p chrome
20+
- pub run build_runner test -- -p chrome

CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
## [5.2.1](https://github.com/cleandart/react-dart/compare/5.2.0...5.2.1)
2+
3+
- Temporarily pin react-redux dependency to version `7.1.0` to prevent widespread test failures as a result of
4+
[`Provider` being converted into a function component with hooks](https://github.com/reduxjs/react-redux/pull/1377).
5+
6+
## [5.2.0](https://github.com/cleandart/react-dart/compare/5.1.1...5.2.0)
7+
8+
- [#190] Fix null value handling in `setStateWithUpdater`
9+
- [#235] Fix null value handling in `getDerivedStateFromError` interop
10+
- [#238] Fix js package security vulnerability
11+
- [#236] Expose `componentZone` to allow overriding the zone in which Component2 lifecycle methods are run, for testing
12+
13+
## [5.1.1](https://github.com/cleandart/react-dart/compare/5.1.0...5.1.1)
14+
15+
- Improve the documentation for deprecated `Component2` lifecycle methods.
16+
117
## [5.1.0](https://github.com/cleandart/react-dart/compare/5.0.1...5.1.0)
218

319
__Full ReactJS 16.x Component Lifecycle Support__

js_src/_dart_helpers.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ function _createReactDartComponentClass2(dartInteropStatics, componentStatics, j
127127
dartInteropStatics.handleComponentDidCatch(this.dartComponent, error, info);
128128
}
129129
static getDerivedStateFromError(error) {
130-
return dartInteropStatics.handleGetDerivedStateFromError(componentStatics, error);
130+
let derivedState = dartInteropStatics.handleGetDerivedStateFromError(componentStatics, error);
131+
return typeof derivedState !== 'undefined' ? derivedState : null;
131132
}
132133
render() {
133134
var result = dartInteropStatics.handleRender(this.dartComponent, this.props, this.state, this.context);

lib/react.dart

Lines changed: 135 additions & 73 deletions
Large diffs are not rendered by default.

lib/react.js

Lines changed: 293 additions & 203 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/react_client.dart

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import 'dart:js';
1313
import 'dart:js_util';
1414

1515
import "package:js/js.dart";
16+
import 'package:meta/meta.dart';
1617

1718
import "package:react/react.dart";
1819
import 'package:react/react_client/js_interop_helpers.dart';
@@ -60,6 +61,21 @@ dynamic listifyChildren(dynamic children) {
6061
}
6162
}
6263

64+
/// The zone in which React will call component lifecycle methods.
65+
///
66+
/// This can be used to sync a test's zone and React's component zone, ensuring that component prop callbacks and
67+
/// lifecycle method output all occurs within the same zone as the test.
68+
///
69+
/// __Example:__
70+
///
71+
/// test('zone test', () {
72+
/// componentZone = Zone.current;
73+
///
74+
/// // ... test your component
75+
/// }
76+
@visibleForTesting
77+
Zone componentZone = Zone.root;
78+
6379
/// Use [ReactDartComponentFactoryProxy2] instead.
6480
///
6581
/// Will be removed when [Component] is removed in the `6.0.0` release.
@@ -428,7 +444,8 @@ final ReactDartInteropStatics _dartInteropStatics = (() {
428444
var props = new UnmodifiableMapView(component.props);
429445

430446
component.transactionalSetStateCallbacks.forEach((callback) {
431-
nextState.addAll(callback(nextState, props));
447+
final stateUpdates = callback(nextState, props);
448+
if (stateUpdates != null) nextState.addAll(stateUpdates);
432449
});
433450
component.transactionalSetStateCallbacks.clear();
434451
}
@@ -524,10 +541,6 @@ final ReactDartInteropStatics _dartInteropStatics = (() {
524541
})();
525542

526543
abstract class _ReactDartInteropStatics2 {
527-
// TODO 3.1.0-wip expose for testing?
528-
/// The zone in which all component lifecycle methods are run.
529-
static final componentZone = Zone.root;
530-
531544
static void _updatePropsAndStateWithJs(Component2 component, JsMap props, JsMap state) {
532545
component
533546
..props = new JsBackedMap.backedBy(props)
@@ -634,7 +647,9 @@ abstract class _ReactDartInteropStatics2 {
634647
try {
635648
throwErrorFromJS(error);
636649
} catch (e) {
637-
return jsBackingMapOrJsCopy(componentStatics.instanceForStaticMethods.getDerivedStateFromError(e));
650+
final result = componentStatics.instanceForStaticMethods.getDerivedStateFromError(e);
651+
if (result != null) return jsBackingMapOrJsCopy(result);
652+
return null;
638653
}
639654
});
640655

lib/react_client/bridge.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,12 @@ class Component2BridgeImpl extends Component2Bridge {
9393
@override
9494
void setStateWithUpdater(Component2 component, StateUpdaterCallback stateUpdater, SetStateCallback callback) {
9595
final firstArg = allowInterop((JsMap jsPrevState, JsMap jsProps, [_]) {
96-
return jsBackingMapOrJsCopy(stateUpdater(
96+
final value = stateUpdater(
9797
new JsBackedMap.backedBy(jsPrevState),
9898
new JsBackedMap.backedBy(jsProps),
99-
));
99+
);
100+
if (value == null) return null;
101+
return jsBackingMapOrJsCopy(value);
100102
});
101103

102104
if (callback == null) {

0 commit comments

Comments
 (0)