diff --git a/CHANGELOG.md b/CHANGELOG.md index c606af3377..3029f50414 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,11 @@ - Recursion in `openDatabase` when using `SentrySqfliteDatabaseFactory` ([#3231](https://github.com/getsentry/sentry-dart/pull/3231)) +### Enhancements + +- Replay: continue processing if encountering `InheritedWidget` ([#3200](https://github.com/getsentry/sentry-dart/pull/3200)) + - Prevents false debug warnings when using [provider](https://pub.dev/packages/provider) for example which extensively uses `InheritedWidget` + ## 9.7.0-beta.2 ### Features diff --git a/packages/flutter/lib/src/sentry_privacy_options.dart b/packages/flutter/lib/src/sentry_privacy_options.dart index cbef72d951..348990c2c7 100644 --- a/packages/flutter/lib/src/sentry_privacy_options.dart +++ b/packages/flutter/lib/src/sentry_privacy_options.dart @@ -83,6 +83,9 @@ class SentryPrivacyOptions { rules.add(SentryMaskingCustomRule( callback: (Element element, Widget widget) { + if (widget is InheritedWidget) { + return SentryMaskingDecision.continueProcessing; + } final type = widget.runtimeType.toString(); if (regexp.hasMatch(type)) { logger( diff --git a/packages/flutter/test/screenshot/masking_config_test.dart b/packages/flutter/test/screenshot/masking_config_test.dart index 992ef67cc3..4c49210726 100644 --- a/packages/flutter/test/screenshot/masking_config_test.dart +++ b/packages/flutter/test/screenshot/masking_config_test.dart @@ -298,6 +298,26 @@ void main() async { }); }); }); + + testWidgets('ignores InheritedWidget and does not log', (tester) async { + final logger = MockLogger(); + final options = SentryPrivacyOptions(); + final config = + options.buildMaskingConfig(logger.call, MockRuntimeChecker()); + + final rootElement = await pumpTestElement(tester, children: const [ + _PasswordInherited(child: Text('child')), + ]); + + final element = rootElement.findFirstOfType<_PasswordInherited>(); + expect(config.shouldMask(element, element.widget), + SentryMaskingDecision.continueProcessing); + + // The debug rule contains a RegExp that matches 'password'. Our widget + // name contains it but because it's an InheritedWidget it should be + // ignored and thus no warning is logged. + expect(logger.items.where((i) => i.level == SentryLevel.warning), isEmpty); + }); } extension on Element { @@ -327,3 +347,10 @@ extension on Element { return result; } } + +class _PasswordInherited extends InheritedWidget { + const _PasswordInherited({required super.child}); + + @override + bool updateShouldNotify(covariant _PasswordInherited oldWidget) => false; +}