Skip to content

Commit 471dccf

Browse files
Merge pull request #973 from Workiva/test-react-18-prep
FED-3274 React 18 Prep
2 parents 5c028ef + 4d54896 commit 471dccf

File tree

6 files changed

+20
-27
lines changed

6 files changed

+20
-27
lines changed

test/over_react/component/context_test.dart

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ void main() {
206206
});
207207
});
208208

209-
group('experimental calculateChangeBits argument functions correctly', () {
209+
group('experimental calculateChangeBits argument does not throw when used (has no effect in React 18)', () {
210210
late Ref<ContextProviderWrapperComponent?> providerRef;
211211
int? consumerEvenValue;
212212
int? consumerOddValue;
@@ -243,15 +243,14 @@ void main() {
243243
});
244244

245245
test('on value updates', () {
246+
// Test common behavior between React 17 (calculateChangedBits working)
247+
// and React 18 (it having no effect).
246248
providerRef.current!.increment();
247249
expect(consumerEvenValue, 2);
248-
expect(consumerOddValue, 1);
249250
providerRef.current!.increment();
250-
expect(consumerEvenValue, 2);
251251
expect(consumerOddValue, 3);
252252
providerRef.current!.increment();
253253
expect(consumerEvenValue, 4);
254-
expect(consumerOddValue, 3);
255254
});
256255
});
257256
});

test/over_react/component/error_boundary/shared_stack_tests.dart

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
import 'dart:html';
16+
1517
import 'package:meta/meta.dart';
1618
import 'package:over_react/over_react.dart' hide ErrorBoundary;
17-
import 'package:react_testing_library/react_testing_library.dart' as rtl;
19+
import 'package:over_react/react_dom.dart' as react_dom;
1820
import 'package:over_react/components.dart';
1921
import 'package:test/test.dart';
2022

@@ -27,17 +29,15 @@ void sharedErrorBoundaryStackTests() {
2729
void expectRenderErrorWithComponentName(ReactElement element,
2830
{required String expectedComponentName}) {
2931
final capturedInfos = <ReactErrorInfo>[];
30-
expect(() {
31-
rtl.render((ErrorBoundary()
32-
..shouldLogErrors = false
33-
..onComponentDidCatch = (error, info) {
34-
capturedInfos.add(info);
35-
})(element));
36-
// Use prints as an easy way to swallow `print` calls and
37-
// prevent RTL from forwarding console errors to the test output,
38-
// since React error boundary logging is pretty noisy.
39-
// TODO instead, disable logging in this rtl.render call once that option is available: FED-1641
40-
}, prints(anything));
32+
final mountNode = DivElement();
33+
// Use react_dom.render instead of RTL to avoid errors on React 18 about
34+
// `act` being used in prod builds.
35+
react_dom.render((ErrorBoundary()
36+
..shouldLogErrors = false
37+
..onComponentDidCatch = (error, info) {
38+
capturedInfos.add(info);
39+
})(element), mountNode);
40+
addTearDown(() => react_dom.unmountComponentAtNode(mountNode));
4141

4242
expect(capturedInfos, hasLength(1),
4343
reason: 'test setup check; should have captured a single component error');

tools/analyzer_plugin/lib/src/diagnostic/exhaustive_deps.dart

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1605,12 +1605,6 @@ Iterable<Union<Identifier, NamedType>> resolvedReferencesWithin(AstNode node) sy
16051605
}
16061606
}
16071607

1608-
extension on NamedType {
1609-
// NamedType.element is added in analyzer 5.11.0; we can't resolve to that version in Dart 2.18,
1610-
// so we'll add it here so we don't have to go back through and change it later.
1611-
Element? get element => name.staticElement;
1612-
}
1613-
16141608
enum HookTypeWithStableMethods { stateHook, reducerHook, transitionHook }
16151609

16161610
abstract class HookConstants {

tools/analyzer_plugin/lib/src/diagnostic/missing_required_prop.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
import 'package:analyzer/dart/analysis/results.dart';
2-
import 'package:analyzer/dart/ast/ast.dart';
32
import 'package:analyzer/dart/element/element.dart';
43
import 'package:over_react_analyzer_plugin/src/diagnostic/analyzer_debug_helper.dart';
54
import 'package:over_react_analyzer_plugin/src/diagnostic_contributor.dart';
65
import 'package:over_react_analyzer_plugin/src/util/ast_util.dart';
76
import 'package:over_react_analyzer_plugin/src/util/pretty_print.dart';
87
import 'package:over_react_analyzer_plugin/src/util/prop_declarations/props_set_by_factory.dart';
98
import 'package:over_react_analyzer_plugin/src/util/prop_forwarding/forwarded_props.dart';
10-
import 'package:over_react_analyzer_plugin/src/util/util.dart';
119
import 'package:over_react_analyzer_plugin/src/util/weak_map.dart';
1210

1311
import '../fluent_interface_util.dart';

tools/analyzer_plugin/pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ publish_to: none
44
description: Dart analyzer plugin for OverReact
55
repository: https://github.com/Workiva/over_react/tree/master/tools/analyzer_plugin
66
environment:
7-
sdk: '>=2.17.0 <3.0.0'
7+
sdk: '>=2.19.0 <3.0.0'
88
dependencies:
9-
analyzer: ^5.1.0
9+
analyzer: ^5.11.0
1010
analyzer_plugin: ^0.11.0
1111
collection: ^1.15.0-nullsafety.4
1212
meta: ^1.16.0

tools/analyzer_plugin/tool/doc_generation_utils/visitor.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ class ContributorVisitor extends RecursiveElementVisitor<void> {
3232
void visitClassElement(ClassElement element) {
3333
for (final config in _configs) {
3434
if (!element.isOrIsSubtypeOfElementFromPackage(
35-
config.typeNameOfContributorClass, config.packageNameContainingContributorClass)) continue;
35+
config.typeNameOfContributorClass, config.packageNameContainingContributorClass)) {
36+
continue;
37+
}
3638

3739
final annotatedFields = element.fields
3840
.where((f) => f.metadata.any((a) => a.element!.thisOrAncestorOfType<ClassElement>()?.name == 'DocsMeta'));

0 commit comments

Comments
 (0)