Commit c3360ac
authored
[two_dimensional_scrollables] Fix mouse event loop when calling setState in TableSpan.onEnter (#11606)
This PR addresses a bug in TableView where calling setState (or any action that triggers a delegate rebuild) inside a TableSpan.onEnter callback would cause an infinite loop of onExit and onEnter events.
The RenderTableViewport was clearing its cached _columnMetrics and _rowMetrics (_Span objects) on every delegate rebuild. Since _Span implements MouseTrackerAnnotation, and the MouseTracker identifies regions by object identity, re-creating these objects every frame caused the MouseTracker to:
1. Trigger onExit for the old _Span object.
2. Trigger onEnter for the new _Span object.
If onEnter contained a setState call, this cycle would repeat indefinitely.
Fixes flutter/flutter#147614
Fix:
- Refactored _updateRowMetrics and _updateColumnMetrics to reuse existing _Span objects when
available.
- Updated _Span.update to only refresh the internal configuration and layout metrics while
maintaining the same object instance.
- Modified layoutChildSequence to avoid clearing the metrics maps, instead allowing the update
methods to handle stale entries.
- Added logic to properly dispose and remove spans when the row or column count is reduced.
## Pre-Review Checklist
**Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.
[^1]: Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling.1 parent 3b8c4cb commit c3360ac
4 files changed
Lines changed: 107 additions & 13 deletions
File tree
- packages/two_dimensional_scrollables
- lib/src/table_view
- test/table_view
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
1 | 5 | | |
2 | 6 | | |
3 | 7 | | |
| |||
Lines changed: 36 additions & 12 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
687 | 687 | | |
688 | 688 | | |
689 | 689 | | |
690 | | - | |
691 | | - | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
692 | 693 | | |
693 | 694 | | |
694 | 695 | | |
695 | 696 | | |
696 | 697 | | |
697 | 698 | | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
698 | 704 | | |
699 | 705 | | |
700 | 706 | | |
701 | 707 | | |
| 708 | + | |
702 | 709 | | |
703 | 710 | | |
704 | 711 | | |
| |||
732 | 739 | | |
733 | 740 | | |
734 | 741 | | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
735 | 746 | | |
736 | 747 | | |
737 | 748 | | |
| |||
804 | 815 | | |
805 | 816 | | |
806 | 817 | | |
807 | | - | |
808 | | - | |
| 818 | + | |
| 819 | + | |
| 820 | + | |
809 | 821 | | |
810 | 822 | | |
811 | 823 | | |
812 | 824 | | |
813 | 825 | | |
814 | 826 | | |
815 | 827 | | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
816 | 833 | | |
817 | 834 | | |
818 | 835 | | |
819 | 836 | | |
| 837 | + | |
820 | 838 | | |
821 | 839 | | |
822 | 840 | | |
| |||
850 | 868 | | |
851 | 869 | | |
852 | 870 | | |
| 871 | + | |
| 872 | + | |
| 873 | + | |
| 874 | + | |
853 | 875 | | |
854 | 876 | | |
855 | 877 | | |
| |||
872 | 894 | | |
873 | 895 | | |
874 | 896 | | |
| 897 | + | |
| 898 | + | |
| 899 | + | |
| 900 | + | |
| 901 | + | |
| 902 | + | |
| 903 | + | |
| 904 | + | |
| 905 | + | |
| 906 | + | |
875 | 907 | | |
876 | 908 | | |
877 | 909 | | |
| |||
1041 | 1073 | | |
1042 | 1074 | | |
1043 | 1075 | | |
1044 | | - | |
1045 | | - | |
1046 | | - | |
1047 | | - | |
1048 | | - | |
1049 | | - | |
1050 | | - | |
1051 | | - | |
1052 | 1076 | | |
1053 | 1077 | | |
1054 | 1078 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| |||
Lines changed: 66 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3630 | 3630 | | |
3631 | 3631 | | |
3632 | 3632 | | |
| 3633 | + | |
3633 | 3634 | | |
3634 | 3635 | | |
| 3636 | + | |
| 3637 | + | |
| 3638 | + | |
| 3639 | + | |
| 3640 | + | |
| 3641 | + | |
| 3642 | + | |
| 3643 | + | |
| 3644 | + | |
| 3645 | + | |
| 3646 | + | |
| 3647 | + | |
| 3648 | + | |
| 3649 | + | |
| 3650 | + | |
| 3651 | + | |
| 3652 | + | |
| 3653 | + | |
| 3654 | + | |
| 3655 | + | |
| 3656 | + | |
| 3657 | + | |
| 3658 | + | |
| 3659 | + | |
| 3660 | + | |
| 3661 | + | |
| 3662 | + | |
| 3663 | + | |
| 3664 | + | |
| 3665 | + | |
| 3666 | + | |
| 3667 | + | |
| 3668 | + | |
| 3669 | + | |
| 3670 | + | |
| 3671 | + | |
| 3672 | + | |
| 3673 | + | |
| 3674 | + | |
| 3675 | + | |
| 3676 | + | |
| 3677 | + | |
| 3678 | + | |
| 3679 | + | |
| 3680 | + | |
| 3681 | + | |
| 3682 | + | |
| 3683 | + | |
| 3684 | + | |
| 3685 | + | |
| 3686 | + | |
| 3687 | + | |
| 3688 | + | |
| 3689 | + | |
| 3690 | + | |
| 3691 | + | |
| 3692 | + | |
| 3693 | + | |
| 3694 | + | |
| 3695 | + | |
| 3696 | + | |
| 3697 | + | |
| 3698 | + | |
| 3699 | + | |
| 3700 | + | |
3635 | 3701 | | |
3636 | 3702 | | |
3637 | 3703 | | |
| |||
0 commit comments