Skip to content

Commit 4a2b185

Browse files
committed
Merge branch 'master' of github.com:Workiva/over_react into fedx_3476
2 parents cef894e + 1268153 commit 4a2b185

File tree

11 files changed

+91
-42
lines changed

11 files changed

+91
-42
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# OverReact Changelog
22

3+
## 5.4.3
4+
- [#966] Revert #964 (an attempt to fix `manageAndReturnTypedDisposable` typing)
5+
- [#969] Use a `dart_dependency_validator.yaml` config file
6+
- [#973] React 18 Prep
7+
- Bumps the minimum Dart SDK from `2.17.0` to `2.19.0`
8+
- [#974] Fix fragment type check assert
9+
310
## 5.4.2
411
- [#964] Fix bad override of `manageAndReturnTypedDisposable` caused by w_common 3.3.0
512

lib/src/component_declaration/component_type_checking.dart

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,6 @@ bool isTypeAlias(dynamic type) {
172172
/// Returns the [ComponentTypeMeta] associated with the component type [type] in [setComponentTypeMeta],
173173
/// or `const ComponentTypeMeta.none()` if there is no associated meta.
174174
ComponentTypeMeta getComponentTypeMeta(Object type) {
175-
assert(isPotentiallyValidComponentType(type),
176-
'`type` should be a valid component type (and not null or a type alias).');
177-
178175
if (type is! String) {
179176
return getProperty(type, _componentTypeMetaKey) as ComponentTypeMeta? ??
180177
const ComponentTypeMeta.none();
@@ -307,7 +304,16 @@ Object? getComponentTypeFromAlias(Object? typeAlias) {
307304
/// * [Function] factory (Dart components)
308305
/// * [ReactClass] component type (JS composite component classes, JS function component functions, Dart component JS classes)
309306
bool isPotentiallyValidComponentType(dynamic type) {
310-
return type is Function || type is ReactClass || type is String;
307+
return type is Function ||
308+
// In DDC, `type is ReactClass` is true for JS symbols (such as for Fragment ReactElements),
309+
// but in dart2js it is false.
310+
// Since isPotentiallyValidComponentType is only used in aliasing code now, this isn't a big deal since
311+
// people aren't likely aliasing Fragment, but we should make this behavior consistent.
312+
// TODO handle that case in dart2js once our Dart SDK constraint is >=3.0.0, with the following code:
313+
// typeofEquals(type, 'symbol') ||
314+
// TODO also add a test (see TODO in component_type_checking_test.dart)
315+
type is ReactClass ||
316+
type is String;
311317
}
312318

313319
/// Returns an [Iterable] of all component types that are ancestors of [type].

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: over_react
2-
version: 5.4.2
2+
version: 5.4.3
33
description: A library for building statically-typed React UI components using Dart.
44
homepage: https://github.com/Workiva/over_react/
55
environment:

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');

test/over_react/component_declaration/component_type_checking_test.dart

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,53 @@ main() {
318318
}, tags: 'ddc');
319319
});
320320
});
321+
322+
// Note: due to current behavioral differences of isPotentiallyValidComponentType between dart2js and DDC,
323+
// these regression tests only fail in dart2js with --enable-asserts, which we don't want to run our tests with.
324+
group('type checking and related utilities work as expected, without throwing, for', () {
325+
group('types of built-in and DOM components', () {
326+
final componentsByDescription = <String, ReactElement Function()>{
327+
// Edge-case: the `type` of Fragment is a JS Symbol
328+
'Fragment': () => Fragment()(''),
329+
'StrictMode': () => StrictMode()(),
330+
'div': () => Dom.div()(),
331+
};
332+
333+
componentsByDescription.forEach((description, factory) {
334+
group('- $description -', () {
335+
late ReactElement element;
336+
late Object type;
337+
338+
setUp(() {
339+
element = factory();
340+
final maybeType = element.type as Object?;
341+
expect(maybeType, isNotNull, reason: 'test setup check; element should have a type');
342+
type = maybeType!;
343+
});
344+
345+
// TODO uncomment once isPotentiallyValidComponentType is fixed for JS Symbols (see TODO in isPotentiallyValidComponentType), and update "Note:" comment above
346+
// test('isPotentiallyValidComponentType', () {
347+
// expect(isPotentiallyValidComponentType(type), isTrue);
348+
// });
349+
350+
test('getComponentTypeMeta', () {
351+
expect(getComponentTypeMeta(type), isA<ComponentTypeMeta>()
352+
.having((m) => m.isWrapper, 'isWrapper', false)
353+
.having((m) => m.isHoc, 'isHoc', false)
354+
.having((m) => m.parentType, 'parentType', isNull));
355+
});
356+
357+
test('getProps()', () {
358+
expect(getProps(element), isA<Map>());
359+
});
360+
361+
test('getProps(traverseWrappers: true)', () {
362+
expect(getProps(element, traverseWrappers: true), isA<Map>());
363+
});
364+
});
365+
});
366+
});
367+
});
321368
}
322369

323370
testComponentTypeChecking({
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
ignore:
2+
# Ignore the over_react pin
3+
- over_react
4+
exclude:
5+
- playground/**

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: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ 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
1313
# Upon release, this should be pinned to the over_react version from ../../pubspec.yaml
1414
# so that it always resolves to the same version of over_react that the user has pulled in,
1515
# and thus has the same boilerplate parsing code that's running in the builder.
16-
over_react: 5.4.2
16+
over_react: 5.4.3
1717
path: ^1.5.1
1818
source_span: ^1.7.0
1919
yaml: ^3.0.0
@@ -34,18 +34,9 @@ dev_dependencies:
3434
test_reflective_loader: ^0.2.0
3535
uuid: '>3.0.0 <5.0.0'
3636
workiva_analysis_options: ^1.1.0
37-
38-
dependency_validator:
39-
ignore:
40-
# Ignore the over_react pin
41-
- over_react
42-
exclude:
43-
- playground/**
44-
4537
workiva:
4638
core_checks:
4739
react_boilerplate: disabled
48-
4940
# If you're developing on changes in over_react that the analyzer plugin needs to consume,
5041
# point to the local copy of over_react. This must be an absolute path.
5142
#

0 commit comments

Comments
 (0)