@@ -17,6 +17,11 @@ import 'dart:js';
17
17
18
18
import 'package:react/react_client/react_interop.dart' ;
19
19
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
+
20
25
/// Runs a provided callback and returns the logs that occur during the runtime
21
26
/// of that function.
22
27
///
@@ -51,11 +56,13 @@ List<String?> recordConsoleLogs(
51
56
consoleRefs[config] = context['console' ][config];
52
57
context['console' ][config] =
53
58
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
+ }
59
66
});
60
67
}
61
68
@@ -98,11 +105,13 @@ FutureOr<List<String?>> recordConsoleLogsAsync(
98
105
consoleRefs[config] = context['console' ][config];
99
106
context['console' ][config] =
100
107
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
+ }
106
115
});
107
116
}
108
117
0 commit comments