Skip to content

Commit fd88186

Browse files
authored
enh(replay): continue processing if encountering InheritedWidget (#3200)
* Update * Update CHANGELOG * Add test * Add test * Update Changelog
1 parent 4acbd17 commit fd88186

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66

77
- Recursion in `openDatabase` when using `SentrySqfliteDatabaseFactory` ([#3231](https://github.com/getsentry/sentry-dart/pull/3231))
88

9+
### Enhancements
10+
11+
- Replay: continue processing if encountering `InheritedWidget` ([#3200](https://github.com/getsentry/sentry-dart/pull/3200))
12+
- Prevents false debug warnings when using [provider](https://pub.dev/packages/provider) for example which extensively uses `InheritedWidget`
13+
914
## 9.7.0-beta.2
1015

1116
### Features

packages/flutter/lib/src/sentry_privacy_options.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ class SentryPrivacyOptions {
8383

8484
rules.add(SentryMaskingCustomRule<Widget>(
8585
callback: (Element element, Widget widget) {
86+
if (widget is InheritedWidget) {
87+
return SentryMaskingDecision.continueProcessing;
88+
}
8689
final type = widget.runtimeType.toString();
8790
if (regexp.hasMatch(type)) {
8891
logger(

packages/flutter/test/screenshot/masking_config_test.dart

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,26 @@ void main() async {
298298
});
299299
});
300300
});
301+
302+
testWidgets('ignores InheritedWidget and does not log', (tester) async {
303+
final logger = MockLogger();
304+
final options = SentryPrivacyOptions();
305+
final config =
306+
options.buildMaskingConfig(logger.call, MockRuntimeChecker());
307+
308+
final rootElement = await pumpTestElement(tester, children: const [
309+
_PasswordInherited(child: Text('child')),
310+
]);
311+
312+
final element = rootElement.findFirstOfType<_PasswordInherited>();
313+
expect(config.shouldMask(element, element.widget),
314+
SentryMaskingDecision.continueProcessing);
315+
316+
// The debug rule contains a RegExp that matches 'password'. Our widget
317+
// name contains it but because it's an InheritedWidget it should be
318+
// ignored and thus no warning is logged.
319+
expect(logger.items.where((i) => i.level == SentryLevel.warning), isEmpty);
320+
});
301321
}
302322

303323
extension on Element {
@@ -327,3 +347,10 @@ extension on Element {
327347
return result;
328348
}
329349
}
350+
351+
class _PasswordInherited extends InheritedWidget {
352+
const _PasswordInherited({required super.child});
353+
354+
@override
355+
bool updateShouldNotify(covariant _PasswordInherited oldWidget) => false;
356+
}

0 commit comments

Comments
 (0)