Skip to content
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

FED-3274 React 18 Prep #973

Merged
merged 9 commits into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from 8 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: 3 additions & 4 deletions test/over_react/component/context_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ void main() {
});
});

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

test('on value updates', () {
// Test common behavior between React 17 (calculateChangedBits working)
// and React 18 (it having no effect).
providerRef.current!.increment();
expect(consumerEvenValue, 2);
expect(consumerOddValue, 1);
providerRef.current!.increment();
expect(consumerEvenValue, 2);
expect(consumerOddValue, 3);
providerRef.current!.increment();
expect(consumerEvenValue, 4);
expect(consumerOddValue, 3);
});
});
});
Expand Down
24 changes: 12 additions & 12 deletions test/over_react/component/error_boundary/shared_stack_tests.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import 'dart:html';

import 'package:meta/meta.dart';
import 'package:over_react/over_react.dart' hide ErrorBoundary;
import 'package:react_testing_library/react_testing_library.dart' as rtl;
import 'package:over_react/react_dom.dart' as react_dom;
import 'package:over_react/components.dart';
import 'package:test/test.dart';

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

expect(capturedInfos, hasLength(1),
reason: 'test setup check; should have captured a single component error');
Expand Down
6 changes: 0 additions & 6 deletions tools/analyzer_plugin/lib/src/diagnostic/exhaustive_deps.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1605,12 +1605,6 @@ Iterable<Union<Identifier, NamedType>> resolvedReferencesWithin(AstNode node) sy
}
}

extension on NamedType {
aaronlademann-wf marked this conversation as resolved.
Show resolved Hide resolved
// NamedType.element is added in analyzer 5.11.0; we can't resolve to that version in Dart 2.18,
// so we'll add it here so we don't have to go back through and change it later.
Element? get element => name.staticElement;
}

enum HookTypeWithStableMethods { stateHook, reducerHook, transitionHook }

abstract class HookConstants {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import 'package:analyzer/dart/analysis/results.dart';
import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/dart/element/element.dart';
import 'package:over_react_analyzer_plugin/src/diagnostic/analyzer_debug_helper.dart';
import 'package:over_react_analyzer_plugin/src/diagnostic_contributor.dart';
import 'package:over_react_analyzer_plugin/src/util/ast_util.dart';
import 'package:over_react_analyzer_plugin/src/util/pretty_print.dart';
import 'package:over_react_analyzer_plugin/src/util/prop_declarations/props_set_by_factory.dart';
import 'package:over_react_analyzer_plugin/src/util/prop_forwarding/forwarded_props.dart';
import 'package:over_react_analyzer_plugin/src/util/util.dart';
import 'package:over_react_analyzer_plugin/src/util/weak_map.dart';

import '../fluent_interface_util.dart';
Expand Down
2 changes: 1 addition & 1 deletion tools/analyzer_plugin/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ publish_to: none
description: Dart analyzer plugin for OverReact
repository: https://github.com/Workiva/over_react/tree/master/tools/analyzer_plugin
environment:
sdk: '>=2.17.0 <3.0.0'
sdk: '>=2.19.0 <3.0.0'
dependencies:
analyzer: ^5.1.0
sydneyjodon-wk marked this conversation as resolved.
Show resolved Hide resolved
analyzer_plugin: ^0.11.0
Expand Down
4 changes: 3 additions & 1 deletion tools/analyzer_plugin/tool/doc_generation_utils/visitor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ class ContributorVisitor extends RecursiveElementVisitor<void> {
void visitClassElement(ClassElement element) {
for (final config in _configs) {
if (!element.isOrIsSubtypeOfElementFromPackage(
config.typeNameOfContributorClass, config.packageNameContainingContributorClass)) continue;
config.typeNameOfContributorClass, config.packageNameContainingContributorClass)) {
continue;
}

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