-
Notifications
You must be signed in to change notification settings - Fork 58
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
HY-4957 Alert devs about batchedRedraw race condition, and log if it happens in prod. ⚠️ #72
Changes from 5 commits
a5d1b90
05bbe8c
7afb657
6a4041b
cad8b21
1c5f5a2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
library over_react.component_declaration.flux_component; | ||
|
||
import 'dart:async'; | ||
import 'package:logging/logging.dart'; | ||
import 'package:w_flux/w_flux.dart'; | ||
import './annotations.dart' as annotations; | ||
import './transformer_helpers.dart'; | ||
|
@@ -82,6 +83,7 @@ abstract class FluxUiStatefulComponent<TProps extends FluxUiProps, TState extend | |
/// | ||
/// Private so it will only get used in this file, since having lifecycle methods in a mixin is risky. | ||
abstract class _FluxComponentMixin<TProps extends FluxUiProps> implements BatchedRedraws { | ||
final Logger _logger = new Logger('_FluxComponentMixin'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's not clear guidance that I can find, but I think we should clearListeners on the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mm, good idea; we don't want this potentially leaking for every FluxComponent instance. @tomconnell-wf What about making this instance static / top-level instead? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or cleaning it up in componentWillUnmount (shrug) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure |
||
TProps get props; | ||
|
||
/// List of store subscriptions created when the component mounts. | ||
|
@@ -101,6 +103,14 @@ abstract class _FluxComponentMixin<TProps extends FluxUiProps> implements Batche | |
value: (_) => (_) => redraw())..addAll(getStoreHandlers()); | ||
|
||
handlers.forEach((store, handler) { | ||
String message = 'Cannot listen to a disposed/disposing Store.'; | ||
assert(!store.isDisposedOrDisposing, '$message This can be caused by BatchedRedraws ' | ||
'mounting the component asynchronously after the store has been disposed. If you are ' | ||
'in a test environment, try adding an `await window.animationFrame;` before disposing your ' | ||
'store.'); | ||
|
||
if (store.isDisposedOrDisposing) _logger.warning(message); | ||
|
||
StreamSubscription subscription = store.listen(handler); | ||
_subscriptions.add(subscription); | ||
}); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please add
logging
topubspec.yaml
?