Fix stale CodeEditor findController listener swap#107
Open
SebTardif wants to merge 2 commits into
Open
Conversation
Remove _updateWidget from the previous findController before assigning the new controller in CodeEditor.didUpdateWidget(). Add a regression test that proves stale controllers no longer trigger rebuilds after a swap. Signed-off-by: Sebastien Tardif <sebtardif@ncf.ca>
Add a regression test for stale findController notifications after the editor is removed. Closes reqable#108 Signed-off-by: Sebastien Tardif <sebtardif@ncf.ca>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
_updateWidgetfrom the previousfindControllerbefore swapping controllers inCodeEditor.didUpdateWidgetProblem
When
CodeEditorswaps to a newfindController,didUpdateWidget()overwrites_findControllerbefore removing_updateWidget. That means the remove call targets the new controller instead of the old one, leaving the old controller able to keep rebuilding the editor after it has been detached.Reproduction
CodeEditorwitholdFindControllernewFindControlleroldFindController.findMode()Before this change, the stale controller still notifies the editor and causes an extra rebuild. If the editor is removed from the tree first, the stale controller can also trigger
setState()after dispose.Fix
Store the previous controller in a local variable, detach
_updateWidgetfrom that instance, then assign and subscribe the new controller.Verification
flutter test test/code_search_controller_test.dartflutter analyze --no-fatal-infos lib/src/code_editor.dart test/code_search_controller_test.dartBug origin
b35627fon 2024-02-05Follow-up improvements in this PR