Skip to content

React 18 testing #417

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

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
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
38,078 changes: 27,786 additions & 10,292 deletions lib/react.js

Large diffs are not rendered by default.

11,601 changes: 0 additions & 11,601 deletions lib/react_dom.js

Large diffs are not rendered by default.

38 changes: 0 additions & 38 deletions lib/react_dom_prod.js

Large diffs are not rendered by default.

13,946 changes: 0 additions & 13,946 deletions lib/react_dom_server.js

Large diffs are not rendered by default.

20 changes: 0 additions & 20 deletions lib/react_dom_server_prod.js

Large diffs are not rendered by default.

44 changes: 38 additions & 6 deletions lib/react_prod.js

Large diffs are not rendered by default.

38,078 changes: 27,786 additions & 10,292 deletions lib/react_with_addons.js

Large diffs are not rendered by default.

46 changes: 21 additions & 25 deletions lib/react_with_react_dom_prod.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions lib/src/react_client/create_root.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import 'package:react/src/react_client/private_utils.dart' show validateJsApiThe
///
/// `createRoot` also accepts [CreateRootOptions] as the second argument.
ReactRoot createRoot(/*Element|DocumentFragment*/ Node container, [CreateRootOptions? options]) {
final jsFn = validateJsApiThenReturn(() => ReactDOMClient.createRoot);
final jsFn = validateJsApiThenReturn(() => ReactDOM.createRoot);

if (options == null) {
return jsFn(container);
Expand All @@ -32,7 +32,7 @@ ReactRoot createRoot(/*Element|DocumentFragment*/ Node container, [CreateRootOpt
return jsFn(container, options.toJs());
}

/// The shape of the object returned by [ReactDOMClient.createRoot].
/// The shape of the object returned by [ReactDOM.createRoot].
@JS()
@anonymous
abstract class ReactRoot {
Expand Down Expand Up @@ -63,7 +63,7 @@ abstract class ReactRoot {
external void unmount();
}

/// The options for the second optional arg of [ReactDOMClient.createRoot].
/// The options for the second optional arg of [ReactDOM.createRoot].
class CreateRootOptions {
/// Optional prefix React uses for ids generated by the `useId` hook. Useful to avoid conflicts when using multiple roots on the same page. Must be the same prefix used on the server.
final String? identifierPrefix;
Expand Down
2 changes: 1 addition & 1 deletion lib/src/react_client/js_interop/react_dom_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ import 'package:js/js.dart';
import '../create_root.dart' show JsCreateRootOptions, ReactRoot;

@JS()
abstract class ReactDOMClient {
abstract class ReactDOM {
external static ReactRoot createRoot(/*Element|DocumentFragment*/ Node container, [JsCreateRootOptions? options]);
}
12 changes: 7 additions & 5 deletions lib/src/react_client/private_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import 'package:react/react_client/react_interop.dart';
import 'package:react/src/js_interop_util.dart';
import 'package:react/src/react_client/component_registration.dart' show registerComponent2;
import 'package:react/src/react_client/internal_react_interop.dart';
import 'package:react/src/react_client/js_interop/react_dom_client.dart' show ReactDOMClient;
import 'package:react/src/react_client/js_interop/react_dom_client.dart' show ReactDOM;

/// A flag used to cache whether React is accessible.
///
Expand Down Expand Up @@ -56,15 +56,17 @@ void validateJsApi() {
React.isValidElement(null);
// ignore: deprecated_member_use_from_same_package
ReactDom.findDOMNode(null);
ReactDOMClient.createRoot(document.createElement('div'));
// This indirectly calls createReactDartComponentClass2
registerComponent2(() => _DummyComponent2());
_isJsApiValid = true;
} on NoSuchMethodError catch (_) {
throw Exception('react.js and react_dom.js must be loaded.');
} catch (_) {
throw Exception('Loaded react.js must include react-dart JS interop helpers.');
}
try {
ReactDOM.createRoot(document.createElement('div'));
} on NoSuchMethodError catch (_) {
throw Exception('React 17 was unexpectedly loaded instead of React 18. Make sure the correct, React 18 JS files are being used.');
}
_isJsApiValid = true;
}

class _DummyComponent2 extends Component2 {
Expand Down