Skip to content

CPLAT-9057: Implement StrictMode Component #242

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 1 commit into from
Dec 23, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 7 additions & 0 deletions lib/react.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ typedef ReactDartComponentFactoryProxy2 ComponentRegistrar2(
/// See: <https://reactjs.org/docs/fragments.html>
var Fragment = ReactJsComponentFactoryProxy(React.Fragment);

/// StrictMode is a tool for highlighting potential problems in an application.
///
/// StrictMode does not render any visible UI. It activates additional checks and warnings for its descendants.
///
/// See: <https://reactjs.org/docs/strict-mode.html>
var StrictMode = ReactJsComponentFactoryProxy(React.StrictMode);

/// Top-level ReactJS [Component class](https://facebook.github.io/react/docs/react-component.html)
/// which provides the [ReactJS Component API](https://facebook.github.io/react/docs/react-component.html#reference)
///
Expand Down
6 changes: 3 additions & 3 deletions lib/react_client/react_interop.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ abstract class React {
@Deprecated('6.0.0')
external static ReactClass createClass(ReactClassConfig reactClassConfig);
external static ReactJsComponentFactory createFactory(type);

external static ReactElement createElement(dynamic type, props, [dynamic children]);
external static JsRef createRef();

external static bool isValidElement(dynamic object);
external static ReactClass get Fragment;

external static JsRef createRef();
external static ReactClass get StrictMode;
external static ReactClass get Fragment;
}

/// Creates a [Ref] object that can be attached to a [ReactElement] via the ref prop.
Expand Down
39 changes: 39 additions & 0 deletions test/react_strictmode_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
@TestOn('browser')
@JS()
library react_test_utils_test;

import 'dart:html';

import 'package:js/js.dart';
import 'package:react/react.dart' as react;
import 'package:react/react_dom.dart' as react_dom;
import 'package:test/test.dart';
import 'package:react/react_client.dart';

main() {
setClientConfiguration();

group('StrictMode', () {
test('renders nothing but its children', () {
var wrappingDivRef;

react_dom.render(
react.div({
'ref': (ref) {
wrappingDivRef = ref;
}
}, [
react.StrictMode({}, [
react.div({}),
react.div({}),
react.div({}),
react.div({}),
])
]),
new Element.div(),
);

expect(wrappingDivRef.children, hasLength(4));
});
});
}
13 changes: 13 additions & 0 deletions test/react_strictmode_test.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<script src="packages/react/react_with_addons.js"></script>
<script src="packages/react/react_dom.js"></script>
<link rel="x-dart-test" href="react_strictmode_test.dart">
<script src="packages/test/dart.js"></script>
</head>
<body>
</body>
</html>