[ Widget Preview ] Fix null assertion when trying to add @Preview() to invalid nodes#173979
Conversation
… to invalid nodes Fixes #173959
|
This pull request was opened from and to a release candidate branch. This should only be done as part of the official Flutter release process. If you are attempting to make a regular contribution to the Flutter project, please close this PR and follow the instructions at Tree Hygiene for detailed instructions on contributing to Flutter. Reviewers: Use caution before merging pull requests to release branches. Ensure the proper procedure has been followed. |
There was a problem hiding this comment.
Code Review
This pull request addresses a null assertion crash that occurs when @Preview() is applied to invalid code elements. The fix involves adding validation checks to ensure that previews are only generated for valid targets (e.g., functions without required parameters and with appropriate return types). A crucial null check is also added before attempting to register a preview, which resolves the crash. The changes are supported by a new utility method and a comprehensive new test suite that covers various invalid usage scenarios. The implementation is solid and effectively solves the reported issue. I have one minor suggestion to improve code conciseness.
packages/flutter_tools/lib/src/widget_preview/dependency_graph.dart
Outdated
Show resolved
Hide resolved
…ications Applying `@Preview()` to an invalid AST node shouldn't cause the preview environment to throw an exception due to invalid generated code. This change adds some additional checks to ensure that invalid `@Preview()` applications are ignored. Related issue: #173959 Related stable hotfix: #173979
…ications (#173984) Applying `@Preview()` to an invalid AST node shouldn't cause the preview environment to throw an exception due to invalid generated code. This change adds some additional checks to ensure that invalid `@Preview()` applications are ignored. Related issue: #173959 Related stable hotfix: #173979
…ications (flutter#173984) Applying `@Preview()` to an invalid AST node shouldn't cause the preview environment to throw an exception due to invalid generated code. This change adds some additional checks to ensure that invalid `@Preview()` applications are ignored. Related issue: flutter#173959 Related stable hotfix: flutter#173979
…ications (flutter#173984) Applying `@Preview()` to an invalid AST node shouldn't cause the preview environment to throw an exception due to invalid generated code. This change adds some additional checks to ensure that invalid `@Preview()` applications are ignored. Related issue: flutter#173959 Related stable hotfix: flutter#173979
…ications (flutter#173984) Applying `@Preview()` to an invalid AST node shouldn't cause the preview environment to throw an exception due to invalid generated code. This change adds some additional checks to ensure that invalid `@Preview()` applications are ignored. Related issue: flutter#173959 Related stable hotfix: flutter#173979
…eview()` to invalid nodes (flutter/flutter#173979)
…ications (flutter#173984) Applying `@Preview()` to an invalid AST node shouldn't cause the preview environment to throw an exception due to invalid generated code. This change adds some additional checks to ensure that invalid `@Preview()` applications are ignored. Related issue: flutter#173959 Related stable hotfix: flutter#173979
…ications (flutter#173984) Applying `@Preview()` to an invalid AST node shouldn't cause the preview environment to throw an exception due to invalid generated code. This change adds some additional checks to ensure that invalid `@Preview()` applications are ignored. Related issue: flutter#173959 Related stable hotfix: flutter#173979
…ications (flutter#173984) Applying `@Preview()` to an invalid AST node shouldn't cause the preview environment to throw an exception due to invalid generated code. This change adds some additional checks to ensure that invalid `@Preview()` applications are ignored. Related issue: flutter#173959 Related stable hotfix: flutter#173979
…ications (flutter#173984) Applying `@Preview()` to an invalid AST node shouldn't cause the preview environment to throw an exception due to invalid generated code. This change adds some additional checks to ensure that invalid `@Preview()` applications are ignored. Related issue: flutter#173959 Related stable hotfix: flutter#173979
Fixes #173959
This is a top-10 crasher on
3.35.{0,1}, but the underlying preview detection logic has been completely rewritten since the stable branch cut.