Skip to content

Commit a5f567f

Browse files
Merge pull request #170 from Workiva/react-18-test
FED-3275 React 18 Prep
2 parents 3616053 + 816bc8c commit a5f567f

File tree

2 files changed

+29
-16
lines changed

2 files changed

+29
-16
lines changed

lib/src/over_react_test/common_component_util.dart

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -585,9 +585,11 @@ void testRequiredProps(BuilderOnlyUiFactory factory, dynamic childrenFactory())
585585
final originalConsoleError = context['console']['error'] as JsFunction;
586586
addTearDown(() => context['console']['error'] = originalConsoleError);
587587
context['console']['error'] = JsFunction.withThis((self, [message, arg1, arg2, arg3, arg4, arg5]) {
588-
consoleErrors.add(message);
589-
originalConsoleError.apply([message, arg1, arg2, arg3, arg4, arg5],
590-
thisArg: self);
588+
if(!shouldFilterOutLog(message)) {
589+
consoleErrors.add(message);
590+
originalConsoleError
591+
.apply([message, arg1, arg2, arg3, arg4, arg5], thisArg: self);
592+
}
591593
});
592594

593595
final reactComponentFactory = factory().componentFactory as
@@ -662,9 +664,11 @@ void testRequiredProps(BuilderOnlyUiFactory factory, dynamic childrenFactory())
662664
final originalConsoleError = context['console']['error'] as JsFunction;
663665
addTearDown(() => context['console']['error'] = originalConsoleError);
664666
context['console']['error'] = JsFunction.withThis((self, [message, arg1, arg2, arg3, arg4, arg5]) {
665-
consoleErrors.add(message);
666-
originalConsoleError.apply([message, arg1, arg2, arg3, arg4, arg5],
667-
thisArg: self);
667+
if(!shouldFilterOutLog(message)) {
668+
consoleErrors.add(message);
669+
originalConsoleError
670+
.apply([message, arg1, arg2, arg3, arg4, arg5], thisArg: self);
671+
}
668672
});
669673

670674
final reactComponentFactory = factory().componentFactory as

lib/src/over_react_test/console_log_utils.dart

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ import 'dart:js';
1717

1818
import 'package:react/react_client/react_interop.dart';
1919

20+
/// Intercept console.error calls and silence warnings for each react_dom.render call,
21+
/// until at the very least createRoot is made available in react-dart.
22+
bool shouldFilterOutLog(String log) =>
23+
log.startsWith('Warning: ReactDOM.render is no longer supported in React 18.');
24+
2025
/// Runs a provided callback and returns the logs that occur during the runtime
2126
/// of that function.
2227
///
@@ -51,11 +56,13 @@ List<String?> recordConsoleLogs(
5156
consoleRefs[config] = context['console'][config];
5257
context['console'][config] =
5358
JsFunction.withThis((self, [message, arg1, arg2, arg3, arg4, arg5]) {
54-
// NOTE: Using console.log or print within this function will cause an infinite
55-
// loop when the logType is set to `log`.
56-
consoleLogs.add(message);
57-
consoleRefs[config]!
58-
.apply([message, arg1, arg2, arg3, arg4, arg5], thisArg: self);
59+
if(!shouldFilterOutLog(message)) {
60+
// NOTE: Using console.log or print within this function will cause an infinite
61+
// loop when the logType is set to `log`.
62+
consoleLogs.add(message);
63+
consoleRefs[config]!
64+
.apply([message, arg1, arg2, arg3, arg4, arg5], thisArg: self);
65+
}
5966
});
6067
}
6168

@@ -98,11 +105,13 @@ FutureOr<List<String?>> recordConsoleLogsAsync(
98105
consoleRefs[config] = context['console'][config];
99106
context['console'][config] =
100107
JsFunction.withThis((self, [message, arg1, arg2, arg3, arg4, arg5]) {
101-
// NOTE: Using console.log or print within this function will cause an infinite
102-
// loop when the logType is set to `log`.
103-
consoleLogs.add(message);
104-
consoleRefs[config]!
105-
.apply([message, arg1, arg2, arg3, arg4, arg5], thisArg: self);
108+
if(!shouldFilterOutLog(message)) {
109+
// NOTE: Using console.log or print within this function will cause an infinite
110+
// loop when the logType is set to `log`.
111+
consoleLogs.add(message);
112+
consoleRefs[config]!
113+
.apply([message, arg1, arg2, arg3, arg4, arg5], thisArg: self);
114+
}
106115
});
107116
}
108117

0 commit comments

Comments
 (0)