Skip to content

FED-3283: React 18 js files #414

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 58 commits into from
Apr 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
582f969
add react 18 rc and other deps
aaronlademann-wf Apr 1, 2022
02068ca
more React 18 [wip]
aaronlademann-wf Apr 1, 2022
468aacd
Fix / reorganize tests, deprecate RTU
aaronlademann-wf Apr 4, 2022
232f67c
[wip] Add suspense
aaronlademann-wf Apr 4, 2022
6adf53a
[wip] Roll back to react-redux 7 for now
aaronlademann-wf Apr 6, 2022
9884640
Fix a few tests
aaronlademann-wf Apr 6, 2022
c774253
Merge remote-tracking branch 'origin/master' into react-18-rc-test
greglittlefield-wf Aug 10, 2023
480c91a
Upgrade to react 18.2.0
greglittlefield-wf Aug 10, 2023
9c513b3
Build JS with React 18.2.0
greglittlefield-wf Aug 10, 2023
d0b876e
Fix duplicate Suspense after merge
greglittlefield-wf Aug 10, 2023
040a2c4
Remove RTL references
greglittlefield-wf Aug 10, 2023
60cb3ae
Fix test template
greglittlefield-wf Aug 10, 2023
0730056
Reset test directory to master
greglittlefield-wf Aug 10, 2023
4a1b67c
Pin to same react-redux as master
greglittlefield-wf Aug 17, 2023
ffd819f
Update compiled assets
greglittlefield-wf Aug 17, 2023
35cff8e
Merge remote-tracking branch 'origin/master' into react-18-2-0
greglittlefield-wf Nov 7, 2023
09d0a68
Fix warnings
greglittlefield-wf Nov 7, 2023
ee3daeb
Merge branch 'master' of github.com:Workiva/react-dart into react-18-2-0
regenvanwalbeek-wf Feb 12, 2024
5a1005d
Logical merge conflict
regenvanwalbeek-wf Feb 12, 2024
664c652
Fix null safety compilation issues
greglittlefield-wf Feb 19, 2024
2119beb
Fix null safety compilation issues in examples
greglittlefield-wf Feb 19, 2024
da5e00c
Merge remote-tracking branch 'origin/master' into react-18-2-0
greglittlefield-wf Oct 18, 2024
74aa3dd
Fix test failures from unrelated react_dom.render deprecation errors
greglittlefield-wf Oct 18, 2024
7c4bed2
Deprecate calculateChangedBits and update tests for React 18
greglittlefield-wf Oct 18, 2024
fc2deca
Make args optional to fix dart2js failures
greglittlefield-wf Oct 18, 2024
954fca9
Format
greglittlefield-wf Oct 18, 2024
52f1a56
Add (failing) test for react_dom.render console.error silencing
greglittlefield-wf Jan 27, 2025
d38e155
Remove tests for pre-Dart-2.14 issue, up SDK constraint
greglittlefield-wf Jan 27, 2025
8674405
Add console.error wrapper to suppress ReactDOM.render errors
greglittlefield-wf Jan 27, 2025
8886413
Recompile JS assets
greglittlefield-wf Jan 27, 2025
0d36059
Remove unused parameter
greglittlefield-wf Jan 27, 2025
74d3a4d
Merge pull request #413 from Workiva/suppress-react-dom-render-warnings
btr-rmconsole-6[bot] Jan 29, 2025
ec60ac1
Merge branch 'master' of github.com:Workiva/react-dart into react-18-2-0
bender-wk Jan 29, 2025
d0ce0e2
reset example and lib directories
kealjones-wk Mar 25, 2025
bf29526
move to pnpm
kealjones-wk Mar 25, 2025
e258085
migrate to vite, pnpm, remove old deps, use esm syntax, remove corejs…
kealjones-wk Mar 25, 2025
621ec08
update readme
kealjones-wk Mar 26, 2025
f3f6a5a
run tests for both react 17 and 18 and move to using test_html_builder
kealjones-wk Mar 26, 2025
f36ed77
revert error throwing
kealjones-wk Mar 26, 2025
b1f3071
update error message for new react 18 filepaths
kealjones-wk Mar 26, 2025
f7d3626
update all the examples and fix all the examples
kealjones-wk Mar 26, 2025
71910f3
use latest test_html_builder compatible with Dart 3
kealjones-wk Mar 26, 2025
62a4cbc
remove debugger statements from tests
kealjones-wk Mar 26, 2025
dbe7de1
try removing the ddc workaround?
kealjones-wk Mar 26, 2025
ec9455c
remove all dart about createRoot
kealjones-wk Mar 26, 2025
467f446
remove act and update some other things
kealjones-wk Mar 27, 2025
0ac4ff3
remove unused config
kealjones-wk Mar 27, 2025
764ef2c
remove more unused stuff
kealjones-wk Mar 27, 2025
03ed71a
roll back to 18.2.0
kealjones-wk Mar 27, 2025
b82a82b
remove unused file
kealjones-wk Mar 27, 2025
c7bac80
minor cleanup and doc comment config
kealjones-wk Mar 27, 2025
88e6155
createRoot from client
kealjones-wk Mar 27, 2025
2d74404
don't modify import object directly
kealjones-wk Mar 27, 2025
a8b3412
update readme to call out React 17 and 18 JS files
kealjones-wk Apr 15, 2025
910c60d
add react 17 and 18 tags and test to verify correct version is being …
kealjones-wk Apr 15, 2025
32ab0fd
add @TestOn('browser')
kealjones-wk Apr 15, 2025
5cb0631
reposition exclude tags arg
kealjones-wk Apr 15, 2025
b9965ca
try using presets instead
kealjones-wk Apr 15, 2025
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
3 changes: 0 additions & 3 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# top-most EditorConfig file
root = true

[*.dart]
max_line_length = 120

Expand Down
12 changes: 9 additions & 3 deletions .github/workflows/dart_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ jobs:
strategy:
fail-fast: false
matrix:
react: [17, 18]
sdk: [2.19.6, stable]
steps:
- uses: actions/checkout@v2
Expand All @@ -49,6 +50,11 @@ jobs:
if [[ "$DART_VERSION" =~ ^3 ]]; then
./tool/delete_dart_2_only_files.sh
fi
- name: Switch to React 17 Test HTML
if: ${{ matrix.react == 17 }}
run: |
mv test/templates/html_template.html test/templates/html_template-old.html
mv test/templates/html_template-react17.html test/templates/html_template.html

- id: install
name: Install dependencies
Expand All @@ -68,12 +74,12 @@ jobs:

- name: Run tests (DDC)
run: |
dart run build_runner test --delete-conflicting-outputs -- --preset dartdevc
dart run build_runner test --delete-conflicting-outputs -- --preset dartdevc --preset=react${{ matrix.react }}
if: always() && steps.install.outcome == 'success'
timeout-minutes: 8

- name: Run tests (dart2js)
run: |
dart run build_runner test --delete-conflicting-outputs --release -- --preset dart2js
dart run build_runner test --delete-conflicting-outputs --release -- --preset dart2js --preset=react${{ matrix.react }}
if: always() && steps.install.outcome == 'success'
timeout-minutes: 8
timeout-minutes: 8
38 changes: 27 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Dart wrapper for [React JS](https://reactjs.org/)

[![Pub](https://img.shields.io/pub/v/react.svg)](https://pub.dev/packages/react)
![ReactJS v17.0.1](https://img.shields.io/badge/React_JS-v17.0.1-green.svg)
![ReactJS v18.2.0](https://img.shields.io/badge/React_JS-18.2.0-green.svg)
[![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)
[![React Dart API Docs](https://img.shields.io/badge/api_docs-react-blue.svg)](https://pub.dev/documentation/react/latest/)

Expand Down Expand Up @@ -40,12 +40,29 @@ If you are not familiar with the ReactJS library, read this [react tutorial](htt

#### HTML

In a `.html` file, include the native javascript `react` and `react_dom` libraries
In a `.html` file, include the javascript libraries
_(provided with this library for compatibility reasons)_ within your `.html` file,
and also add an element with an `id` to mount your React component.

Lastly, add the `.js` file that Dart will generate. The file will be the name of the `.dart` file that
contains your `main` entrypoint, with `.js` at the end.
This library is in the process of migrating to React 18, but while this is happening it will continue to support both React 17 and React 18. The React 17 js files are deprecated but available to ease migration and will be removed at some point in a future major version.

##### React 18
| Mode | Library | JS File Name |
|-------------|------------------|---------------------------------------------|
| Development | React & ReactDOM | packages/react/js/react.dev.js |
| Production | React & ReactDOM | packages/react/js/react.min.js |

##### React 17 (Deprecated)
| Mode | Library | JS File Name |
|-------------|------------------|---------------------------------------------|
| Development | React | packages/react/react.js |
| Development | ReactDOM | packages/react/react_dom.js |
| Production | React & ReactDOM | packages/react/react_with_react_dom_prod.js |
| Production | React | packages/react/react_prod.js |
| Production | ReactDOM | packages/react/react_dom_prod.js |

Lastly, add the `.js` file that Dart will generate. The file will be the name of the `.dart` file that contains your `main` entrypoint, with `.js` at the end.


```html
<html>
Expand All @@ -55,15 +72,14 @@ contains your `main` entrypoint, with `.js` at the end.
<body>
<div id="react_mount_point">Here will be react content</div>

<script src="packages/react/react.js"></script>
<script src="packages/react/react_dom.js"></script>
<script src="packages/react/js/react.dev.js"></script>
<script defer src="your_dart_file_name.dart.js"></script>
</body>
</html>
```

> __Note:__ When serving your application in production, use `packages/react/react_with_react_dom_prod.js`
file instead of the un-minified `react.js` / `react_dom.js` files shown in the example above.
> __Note:__ When serving your application in production, use `packages/react/js/react.min.js`
file instead of the un-minified `react.dev.js` shown in the example above.

#### Dart App

Expand Down Expand Up @@ -386,15 +402,15 @@ void main() {

## Contributing

Format using
Format using
```bash
dart format -l 120 .
```

While we'd like to adhere to the recommended line length of 80, it's too short for much of the code
While we'd like to adhere to the recommended line length of 80, it's too short for much of the code
repo written before a formatter was use, causing excessive wrapping and code that's hard to read.

So, we use a line length of 120 instead.
So, we use a line length of 120 instead.

### Running Tests

Expand Down
9 changes: 5 additions & 4 deletions build.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
targets:
$default:
builders:
mockito:mockBuilder:
# Scope only to files declaring mocks, for performance.
generate_for:
- test/mockito.dart
Comment on lines -4 to -7
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't use mockito? and it was throwing build warnings that its unused

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this got left behind from when we switched to mocktail; thanks for cleaning this up!

test_html_builder:
options:
templates:
"test/templates/html_template.html":
- "test/**_test.dart"
Comment on lines +4 to +8
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to using test_html_builder to make it easier to swap js files that were being used for testing with react 17 and 18 in ci

build_web_compilers|entrypoint:
# These are globs for the entrypoints you want to compile.
generate_for:
Expand Down
15 changes: 8 additions & 7 deletions dart_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,21 @@ platforms:
concurrency: 1

presets:
dart2js-legacy:
dart2js:
exclude_tags: no-dart2js

dartdevc-legacy:
dartdevc:
exclude_tags: no-dartdevc

dart2js:
exclude_tags: "no-dart2js || no-sdk-2-14-plus"
react18:
exclude_tags: react-17

dartdevc:
exclude_tags: "no-dartdevc || no-sdk-2-14-plus"
react17:
exclude_tags: react-18

tags:
# Variadic children tests of >5 children that fail in Dart 2.7 for an unknown reason, seemingly an SDK bug.
# These tests pass in later Dart SDKs, so we ignore them when running in 2.7.
"dart-2-7-dart2js-variadic-issues":

"react-17":
"react-18":
5 changes: 2 additions & 3 deletions example/geocodes/geocodes.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@
<div class="container" id="content"></div>

<!-- Load React, your application code and Dart -->
<script src="packages/react/react.js"></script>
<script src="packages/react/react_dom.js"></script>
<script src="packages/react/js/react.dev.js"></script>
<script defer src="geocodes.dart.js"></script>

</body>
</html>
3 changes: 1 addition & 2 deletions example/js_components/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@

<div id="content"></div>

<script src="packages/react/react.js"></script>
<script src="packages/react/react_dom.js"></script>
<script src="packages/react/js/react.dev.js"></script>
<script src="https://unpkg.com/@material-ui/core/umd/material-ui.development.js" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500" />
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
Expand Down
3 changes: 1 addition & 2 deletions example/suspense/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@

<div id="content"></div>

<script src="packages/react/react.js"></script>
<script src="packages/react/react_dom.js"></script>
<script src="packages/react/js/react.dev.js"></script>

<!-- Where the JS React components are declared. -->
<script defer src="suspense.dart.js"></script>
Expand Down
5 changes: 2 additions & 3 deletions example/test/call_and_nosuchmethod_test.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@
<body>
<div id="content" class="container"></div>

<script src="packages/react/react.js"></script>
<script src="packages/react/react_dom.js"></script>
<script src="packages/react/js/react.dev.js"></script>
<script defer src="call_and_nosuchmethod_test.dart.js"></script>
<!-- for this next line to work, your pubspec.yaml file must have a dependency on 'browser' -->

</body>
</html>
3 changes: 1 addition & 2 deletions example/test/context_test.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
</head>
<body>
<div id="content" class="container"></div>
<script src="packages/react/react.js"></script>
<script src="packages/react/react_dom.js"></script>
<script src="packages/react/js/react.dev.js"></script>
<script src="context_test.dart.js"></script>
</body>
</html>
3 changes: 1 addition & 2 deletions example/test/error_boundary_test.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
</head>
<body>
<div id="content" class="container"></div>
<script src="packages/react/react.js"></script>
<script src="packages/react/react_dom.js"></script>
<script src="packages/react/js/react.dev.js"></script>
<script src="error_boundary_test.dart.js"></script>
</body>
</html>
3 changes: 1 addition & 2 deletions example/test/false_and_null_test.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
</head>
<body>
<div id="content" class="container"></div>
<script src="packages/react/react.js"></script>
<script src="packages/react/react_dom.js"></script>
<script src="packages/react/js/react.dev.js"></script>
<script type="application/dart" src="false_and_null_test.dart"></script>
<script src="packages/browser/dart.js"></script>
</body>
Expand Down
3 changes: 1 addition & 2 deletions example/test/function_component_test.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
</head>
<body>
<div id="content" class="container"></div>
<script src="packages/react/react.js"></script>
<script src="packages/react/react_dom.js"></script>
<script src="packages/react/js/react.dev.js"></script>
<script src="function_component_test.dart.js"></script>
</body>
</html>
5 changes: 2 additions & 3 deletions example/test/get_dom_node_test.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@
<body>
<div id="content" class="container"></div>

<script src="packages/react/react.js"></script>
<script src="packages/react/react_dom.js"></script>
<script src="packages/react/js/react.dev.js"></script>
<script defer src="get_dom_node_test.dart.js"></script>
<!-- for this next line to work, your pubspec.yaml file must have a dependency on 'browser' -->

</body>
</html>
5 changes: 2 additions & 3 deletions example/test/order_test.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@
<body>
<div id="content" class="container"></div>

<script src="packages/react/react.js"></script>
<script src="packages/react/react_dom.js"></script>
<script src="packages/react/js/react.dev.js"></script>
<script defer src="order_test.dart.js"></script>
<!-- for this next line to work, your pubspec.yaml file must have a dependency on 'browser' -->

</body>
</html>
5 changes: 2 additions & 3 deletions example/test/react_test.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@
<body>
<!-- Generated by react_server_test.dart to check if react "infect" DOM by it's own syntetic DOM. -->
<div id="content" class="container"><div data-reactid=".r[1xv2o]" data-react-checksum="-1756372316"><div data-reactid=".r[1xv2o].0"><input value="World" data-reactid=".r[1xv2o].0.0"><span data-reactid=".r[1xv2o].0.1"><span data-reactid=".r[1xv2o].0.1.0">Hello World!</span></span></div><div data-reactid=".r[1xv2o].1"><button data-reactid=".r[1xv2o].1.0">addItem</button><ul data-reactid=".r[1xv2o].1.1"><li data-reactid=".r[1xv2o].1.1.$0">0</li><li data-reactid=".r[1xv2o].1.1.$1">1</li><li data-reactid=".r[1xv2o].1.1.$2">2</li><li data-reactid=".r[1xv2o].1.1.$3">3</li></ul></div><div data-reactid=".r[1xv2o].2"><label class="not-striked" data-reactid=".r[1xv2o].2.0">do the dishes</label><input type="checkbox" value="false" data-reactid=".r[1xv2o].2.1"></div></div>
</div>
</div>

<script src="packages/react/react.js"></script>
<script src="packages/react/react_dom.js"></script>
<script src="packages/react/js/react.dev.js"></script>
<script defer src="react_test.dart.js"></script>
<!-- for this next line to work, your pubspec.yaml file must have a dependency on 'browser' -->

Expand Down
8 changes: 4 additions & 4 deletions example/test/react_test_components.dart
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,8 @@ class _NewContextProviderComponent extends react.Component2 {

final newContextRefComponentProps = {
'key': 'ref2',
'ref': (ref) {
componentRef = ref as _NewContextRefComponent;
'ref': (_NewContextRefComponent? ref) {
componentRef = ref;
}
};

Expand Down Expand Up @@ -442,9 +442,9 @@ class _Component2TestComponent extends react.Component2 with react.TypedSnapshot
@override
getSnapshotBeforeUpdate(nextProps, prevState) {
if ((prevState['items'] as List).length > (state['items'] as List).length) {
return 'removed ' + (prevState['items'].last as List).toString();
return 'removed ' + prevState['items'].last.toString();
} else {
return 'added ' + (state['items'].last as List).toString();
return 'added ' + state['items'].last.toString();
}
}

Expand Down
5 changes: 2 additions & 3 deletions example/test/ref_test.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@
<body>
<div id="content" class="container"></div>

<script src="packages/react/react.js"></script>
<script src="packages/react/react_dom.js"></script>
<script src="packages/react/js/react.dev.js"></script>
<script defer src="ref_test.dart.js"></script>
<!-- for this next line to work, your pubspec.yaml file must have a dependency on 'browser' -->

</body>
</html>
5 changes: 2 additions & 3 deletions example/test/speed_test.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@
<body>
<div id="content" class="container"></div>

<script src="packages/react/react.js"></script>
<script src="packages/react/react_dom.js"></script>
<script src="packages/react/js/react.dev.js"></script>
<script defer src="speed_test.dart.js"></script>
<!-- for this next line to work, your pubspec.yaml file must have a dependency on 'browser' -->

</body>
</html>
5 changes: 2 additions & 3 deletions example/test/unmount_test.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@
<div id="content"></div>
</div>

<script src="packages/react/react.js"></script>
<script src="packages/react/react_dom.js"></script>
<script src="packages/react/js/react.dev.js"></script>
<script defer src="unmount_test.dart.js"></script>
<!-- for this next line to work, your pubspec.yaml file must have a dependency on 'browser' -->

</body>
</html>
28 changes: 0 additions & 28 deletions js_src/dart_env_dev.js

This file was deleted.

12 changes: 12 additions & 0 deletions js_src/dart_env_dev.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Intercept console.error calls and silence warnings for each react_dom.render call,
// until at the very least createRoot is made available in react-dart and RTL.
const oldConsoleError = console.error;
console.error = function() {
const firstArg = arguments[0];
// Use startsWith instead of indexOf as a small optimization for when large strings are logged.
if (typeof firstArg === 'string' && firstArg.startsWith('Warning: ReactDOM.render is no longer supported in React 18.')) {
// Suppress the error.
} else {
oldConsoleError.apply(console, arguments);
}
}
1 change: 0 additions & 1 deletion js_src/dart_env_prod.js

This file was deleted.

Loading