-
Notifications
You must be signed in to change notification settings - Fork 26.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[web] fix: do not call onSubmitted of TextField when switching browser tabs on mobile web #134870
[web] fix: do not call onSubmitted of TextField when switching browser tabs on mobile web #134870
Conversation
Thanks for going down the rabbit hole. It makes sense to me that we shouldn't invoke the But I'll need to verify this doesn't break the current behavior: when the user hits the submit/done key on the software keyboard the and it does seem that chrome maps I'll try this out on device tomorrow. |
That is indeed a good idea to verify that the input actions will still work as intended. So maybe this helps to verify that the current behaviour is not changed: The minimal example provided above has been updated to include the typical cases for input actions (none, next, send). At least on my devices (ios/android) and browsers (safari/chrome/firefox) it seems to work as intended. But this is of course also only a limited test. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. The test website was super handy, thank you! The software keyboard action button works on mobile chrome/firefox/safari.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Looks like some merge conflicts caused google testing to fail. @tauu could you rebase this to |
cbd72f6
to
46621ce
Compare
The rebase to master has been done. Apparently the test is now stuck at a windows build test, though I don't really see how that could actually be related to the changes in the PR. :-/ |
…ing browser tabs on mobile web (flutter/flutter#134870)
…ing browser tabs on mobile web (flutter/flutter#134870)
…ing browser tabs on mobile web (flutter/flutter#134870)
…ing browser tabs on mobile web (flutter/flutter#134870)
…ing browser tabs on mobile web (flutter/flutter#134870)
Roll Flutter from ff4a0f676f41 to 57b5c3cda000 (47 revisions) flutter/flutter@ff4a0f6...57b5c3c 2023-09-29 [email protected] Roll Packages from c070b0a to d0e9a0e (5 revisions) (flutter/flutter#135753) 2023-09-29 [email protected] Roll Flutter Engine from db4d3b5b3f59 to c52251a8b2d0 (1 revision) (flutter/flutter#135748) 2023-09-29 [email protected] Roll Flutter Engine from 8b4e633c65eb to db4d3b5b3f59 (2 revisions) (flutter/flutter#135745) 2023-09-29 [email protected] Roll Flutter Engine from 09130bf5be97 to 8b4e633c65eb (1 revision) (flutter/flutter#135744) 2023-09-29 [email protected] Roll Flutter Engine from ccb30585d3f3 to 09130bf5be97 (1 revision) (flutter/flutter#135741) 2023-09-29 [email protected] Roll Flutter Engine from 2052515c44f3 to ccb30585d3f3 (1 revision) (flutter/flutter#135737) 2023-09-29 [email protected] Update localizations. (flutter/flutter#135691) 2023-09-29 [email protected] Roll Flutter Engine from 485543c6765a to 2052515c44f3 (4 revisions) (flutter/flutter#135732) 2023-09-29 54558023 [email protected] Add arch property for windows_arm64 platform (flutter/flutter#135725) 2023-09-29 [email protected] [flutter_tools] remove VmService screenshot for native devices. (flutter/flutter#135462) 2023-09-29 [email protected] Pin leak_tracker before publishing breaking change. (flutter/flutter#135720) 2023-09-28 [email protected] Roll Flutter Engine from cc7c3c1f0f41 to 485543c6765a (8 revisions) (flutter/flutter#135717) 2023-09-28 [email protected] Remove assertions on getOffsetToReveal (flutter/flutter#135634) 2023-09-28 [email protected] Marks Linux_android flutter_gallery__start_up_delayed to be unflaky (flutter/flutter#135565) 2023-09-28 [email protected] Roll Flutter Engine from dbb60932a6ab to cc7c3c1f0f41 (2 revisions) (flutter/flutter#135701) 2023-09-28 [email protected] [tool] fallback to sigkill when closing Chromium (flutter/flutter#135521) 2023-09-28 137456488 [email protected] Roll pub packages (flutter/flutter#135455) 2023-09-28 [email protected] Roll Flutter Engine from 9789dbc2ec3f to dbb60932a6ab (2 revisions) (flutter/flutter#135694) 2023-09-28 [email protected] Fix TabBarView.viewportFraction change is ignored (flutter/flutter#135590) 2023-09-28 [email protected] Roll Flutter Engine from d9eaebd05851 to 9789dbc2ec3f (2 revisions) (flutter/flutter#135688) 2023-09-28 [email protected] Added option to disable [NavigationDestination]s ([NavigationBar] destination widget) (flutter/flutter#132361) 2023-09-28 98614782 auto-submit[bot]@users.noreply.github.com Reverts "Marks Windows module_custom_host_app_name_test to be unflaky" (flutter/flutter#135692) 2023-09-28 [email protected] � Add more fields to `RefreshProgressIndicator` (flutter/flutter#135207) 2023-09-28 [email protected] Roll Flutter Engine from 82b69dadc07a to d9eaebd05851 (1 revision) (flutter/flutter#135679) 2023-09-28 [email protected] Add API to read flavor from framework at run time (flutter/flutter#134179) 2023-09-28 [email protected] Marks Windows module_custom_host_app_name_test to be unflaky (flutter/flutter#135567) 2023-09-28 [email protected] [web] fix: do not call onSubmitted of TextField when switching browser tabs on mobile web (flutter/flutter#134870) 2023-09-28 [email protected] Roll Packages from 21c2ebb to c070b0a (3 revisions) (flutter/flutter#135676) 2023-09-28 [email protected] Fix `RangeSlider` throws an exception in a `ListView` (flutter/flutter#135667) 2023-09-28 [email protected] Roll Flutter Engine from d09c2dbe2292 to 82b69dadc07a (2 revisions) (flutter/flutter#135675) 2023-09-28 [email protected] Roll Flutter Engine from 495955a3b5de to d09c2dbe2292 (1 revision) (flutter/flutter#135669) 2023-09-28 [email protected] Revert "Upload generated frame-request-pending stats" (flutter/flutter#135672) 2023-09-28 [email protected] Upload generated frame-request-pending stats (flutter/flutter#135645) 2023-09-28 [email protected] Roll Flutter Engine from 937bf0432214 to 495955a3b5de (1 revision) (flutter/flutter#135665) 2023-09-28 [email protected] Roll Flutter Engine from d2540d87fd96 to 937bf0432214 (1 revision) (flutter/flutter#135660) 2023-09-28 [email protected] Roll Flutter Engine from c47faed53afe to d2540d87fd96 (2 revisions) (flutter/flutter#135652) 2023-09-28 [email protected] Update `TextField.style` documentation for Material 3 (flutter/flutter#135556) 2023-09-28 [email protected] Roll Flutter Engine from 44aef2e61718 to c47faed53afe (1 revision) (flutter/flutter#135647) 2023-09-28 [email protected] Manual roll Flutter Engine from be32dcc9117a to 44aef2e61718 (4 revisions) (flutter/flutter#135646) 2023-09-28 [email protected] Manual roll Flutter Engine from f70f65f7a622 to be32dcc9117a (31 revisions) (flutter/flutter#135637) 2023-09-28 [email protected] Implement SelectionArea single click/tap gestures (flutter/flutter#132682) 2023-09-27 [email protected] Support ensureVisible/showOnScreen/showInViewport for 2D Scrolling (flutter/flutter#135182) 2023-09-27 [email protected] made top level if checks gaurd clauses (flutter/flutter#135070) 2023-09-27 [email protected] Fix `SearchAnchor`'s search view isn't updated when the theme changes & widgets inside the search view do not inherit local themes (flutter/flutter#132749) 2023-09-27 [email protected] Config changes for linux coverage. (flutter/flutter#135604) 2023-09-27 [email protected] Roll Packages from 619af75 to 21c2ebb (6 revisions) (flutter/flutter#135602) ...
…r tabs on mobile web (flutter#134870) This PR fixes flutter#134846. As discussed in the issue, the onSubmitted callback of a TextField is called when the browser switches tabs or is sent to the background if the flutter app is running in any mobile browser (desktop browsers are not affected). Furthermore there is no straight forward way to distinguish between onSubmitted being called because the user pressed the enter key and it being called because the user switched tabs. For example in a chat app this would cause a message to be sent when the user submits the text by pressing "send" on the virtual keyboard as well as when the user switches to another tab. The later action is likely not so much intended. The next section explains what causes the bug and explains the proposed fix. ## Bug Analysis The root cause for this behaviour is line 3494 in editable_text.dart: https://github.com/flutter/flutter/blob/0b540a87f1be9a5bb7e550c777dfe5221c53a112/packages/flutter/lib/src/widgets/editable_text.dart#L3487-L3499 Only if the app is running on the web `_finalizeEditing` is called and this will then trigger the onSubmitted callback. If flutter is running on the web, there are only exactly 3 cases, in which the function is called. The following call trace analysis will describe why. - `connectionClosed()` is only called by in one location, `_handleTextInputInvocation` of the TextInput service. https://github.com/flutter/flutter/blob/367203b3011fc1752cfa1f51adf9751d090c94e6/packages/flutter/lib/src/services/text_input.dart#L1896C12-L1899 - In particular it is only called if the TextInput service receives a 'TextInputClient.onConnectionClosed' message from the engine. - The only location where the web part of the engine send this message is the `onConnectionClosed` function of the TextEditingChannel. https://github.com/flutter/engine/blob/cbda68a720904137ee9dfdf840db323afcf52705/lib/web_ui/lib/src/engine/text_editing/text_editing.dart#L2242-L2254 - `onConnectionClosed` in turn is only called by the `sendTextConnectionClosedToFrameworkIfAny` function of `HybridTextEditing`. https://github.com/flutter/engine/blob/cbda68a720904137ee9dfdf840db323afcf52705/lib/web_ui/lib/src/engine/text_editing/text_editing.dart#L2340-L2345 The function `sendTextConnectionClosedToFrameworkIfAny` is only called at 3 distinct locations of the web engine. ### 1. IOSTextEditingStrategy As described in the comment `sendTextConnectionClosedToFrameworkIfAny` is called if the browser is sent to the background or the tab is changed. https://github.com/flutter/engine/blob/cbda68a720904137ee9dfdf840db323afcf52705/lib/web_ui/lib/src/engine/text_editing/text_editing.dart#L1632-L1656 ### 2. AndroidTextEditingStrategy Same situation as for iOS. `sendTextConnectionClosedToFrameworkIfAny` is also called if `windowHasFocus` is false, which is the case if the browser is sent to background or the tab is changed. https://github.com/flutter/engine/blob/cbda68a720904137ee9dfdf840db323afcf52705/lib/web_ui/lib/src/engine/text_editing/text_editing.dart#L1773-L1785 ### 3. TextInputFinishAutofillContext This call seems to always happen when `finishAutofillContext` is triggered by the framework. https://github.com/flutter/engine/blob/cbda68a720904137ee9dfdf840db323afcf52705/lib/web_ui/lib/src/engine/text_editing/text_editing.dart#L2075-L2083 ## Proposed Fix The fixed proposed and implemented by this PR is to simply delete the call to`_finalizeEditing` in the `connectionClosed` function of editable_text.dart. https://github.com/flutter/flutter/blob/0b540a87f1be9a5bb7e550c777dfe5221c53a112/packages/flutter/lib/src/widgets/editable_text.dart#L3487-L3499 The reasoning for this being: * `_finalizeEditing` is only called in `connectionClosed` for the web engine. * As explained by the trace analysis above, the web engine only triggers this `_finalizeEditing` call in 3 cases. * In the 2 cases for IOSTextEditingStrategy and AndroidTextEditingStrategy the web engine triggering the call only causes the undesired behaviour reported in the issue. * In the third case for TextInputFinishAutofillContext, I can't see a good reason why this would require calling `_finalizeEditing` as it only instructs the platform to save the current values. Other platforms also don't have anything that would trigger onSubmitted being called, so it seems safe to remove it. * For other platforms the onConnectionClosed function was recently incorporated to only unfocus the TextField. So removing the call `_finalizeEditing` unifies the platform behaviour. See also flutter#123929 flutter/engine#41500 *List which issues are fixed by this PR. You must list at least one issue.* flutter#134846 To simplify the evaluation, here are two versions of the minimal example given in the issue, build with the current master and with this PR applied: current master: https://tauu.github.io/flutter-onsubmit-test/build/web-master/ current master PR applied: https://tauu.github.io/flutter-onsubmit-test/build/web/
…ing browser tabs on mobile web (flutter/flutter#134870)
…r#5036) Roll Flutter from ff4a0f676f41 to 57b5c3cda000 (47 revisions) flutter/flutter@ff4a0f6...57b5c3c 2023-09-29 [email protected] Roll Packages from c070b0a to d0e9a0e (5 revisions) (flutter/flutter#135753) 2023-09-29 [email protected] Roll Flutter Engine from db4d3b5b3f59 to c52251a8b2d0 (1 revision) (flutter/flutter#135748) 2023-09-29 [email protected] Roll Flutter Engine from 8b4e633c65eb to db4d3b5b3f59 (2 revisions) (flutter/flutter#135745) 2023-09-29 [email protected] Roll Flutter Engine from 09130bf5be97 to 8b4e633c65eb (1 revision) (flutter/flutter#135744) 2023-09-29 [email protected] Roll Flutter Engine from ccb30585d3f3 to 09130bf5be97 (1 revision) (flutter/flutter#135741) 2023-09-29 [email protected] Roll Flutter Engine from 2052515c44f3 to ccb30585d3f3 (1 revision) (flutter/flutter#135737) 2023-09-29 [email protected] Update localizations. (flutter/flutter#135691) 2023-09-29 [email protected] Roll Flutter Engine from 485543c6765a to 2052515c44f3 (4 revisions) (flutter/flutter#135732) 2023-09-29 54558023 [email protected] Add arch property for windows_arm64 platform (flutter/flutter#135725) 2023-09-29 [email protected] [flutter_tools] remove VmService screenshot for native devices. (flutter/flutter#135462) 2023-09-29 [email protected] Pin leak_tracker before publishing breaking change. (flutter/flutter#135720) 2023-09-28 [email protected] Roll Flutter Engine from cc7c3c1f0f41 to 485543c6765a (8 revisions) (flutter/flutter#135717) 2023-09-28 [email protected] Remove assertions on getOffsetToReveal (flutter/flutter#135634) 2023-09-28 [email protected] Marks Linux_android flutter_gallery__start_up_delayed to be unflaky (flutter/flutter#135565) 2023-09-28 [email protected] Roll Flutter Engine from dbb60932a6ab to cc7c3c1f0f41 (2 revisions) (flutter/flutter#135701) 2023-09-28 [email protected] [tool] fallback to sigkill when closing Chromium (flutter/flutter#135521) 2023-09-28 137456488 [email protected] Roll pub packages (flutter/flutter#135455) 2023-09-28 [email protected] Roll Flutter Engine from 9789dbc2ec3f to dbb60932a6ab (2 revisions) (flutter/flutter#135694) 2023-09-28 [email protected] Fix TabBarView.viewportFraction change is ignored (flutter/flutter#135590) 2023-09-28 [email protected] Roll Flutter Engine from d9eaebd05851 to 9789dbc2ec3f (2 revisions) (flutter/flutter#135688) 2023-09-28 [email protected] Added option to disable [NavigationDestination]s ([NavigationBar] destination widget) (flutter/flutter#132361) 2023-09-28 98614782 auto-submit[bot]@users.noreply.github.com Reverts "Marks Windows module_custom_host_app_name_test to be unflaky" (flutter/flutter#135692) 2023-09-28 [email protected] ð��� Add more fields to `RefreshProgressIndicator` (flutter/flutter#135207) 2023-09-28 [email protected] Roll Flutter Engine from 82b69dadc07a to d9eaebd05851 (1 revision) (flutter/flutter#135679) 2023-09-28 [email protected] Add API to read flavor from framework at run time (flutter/flutter#134179) 2023-09-28 [email protected] Marks Windows module_custom_host_app_name_test to be unflaky (flutter/flutter#135567) 2023-09-28 [email protected] [web] fix: do not call onSubmitted of TextField when switching browser tabs on mobile web (flutter/flutter#134870) 2023-09-28 [email protected] Roll Packages from 21c2ebb to c070b0a (3 revisions) (flutter/flutter#135676) 2023-09-28 [email protected] Fix `RangeSlider` throws an exception in a `ListView` (flutter/flutter#135667) 2023-09-28 [email protected] Roll Flutter Engine from d09c2dbe2292 to 82b69dadc07a (2 revisions) (flutter/flutter#135675) 2023-09-28 [email protected] Roll Flutter Engine from 495955a3b5de to d09c2dbe2292 (1 revision) (flutter/flutter#135669) 2023-09-28 [email protected] Revert "Upload generated frame-request-pending stats" (flutter/flutter#135672) 2023-09-28 [email protected] Upload generated frame-request-pending stats (flutter/flutter#135645) 2023-09-28 [email protected] Roll Flutter Engine from 937bf0432214 to 495955a3b5de (1 revision) (flutter/flutter#135665) 2023-09-28 [email protected] Roll Flutter Engine from d2540d87fd96 to 937bf0432214 (1 revision) (flutter/flutter#135660) 2023-09-28 [email protected] Roll Flutter Engine from c47faed53afe to d2540d87fd96 (2 revisions) (flutter/flutter#135652) 2023-09-28 [email protected] Update `TextField.style` documentation for Material 3 (flutter/flutter#135556) 2023-09-28 [email protected] Roll Flutter Engine from 44aef2e61718 to c47faed53afe (1 revision) (flutter/flutter#135647) 2023-09-28 [email protected] Manual roll Flutter Engine from be32dcc9117a to 44aef2e61718 (4 revisions) (flutter/flutter#135646) 2023-09-28 [email protected] Manual roll Flutter Engine from f70f65f7a622 to be32dcc9117a (31 revisions) (flutter/flutter#135637) 2023-09-28 [email protected] Implement SelectionArea single click/tap gestures (flutter/flutter#132682) 2023-09-27 [email protected] Support ensureVisible/showOnScreen/showInViewport for 2D Scrolling (flutter/flutter#135182) 2023-09-27 [email protected] made top level if checks gaurd clauses (flutter/flutter#135070) 2023-09-27 [email protected] Fix `SearchAnchor`'s search view isn't updated when the theme changes & widgets inside the search view do not inherit local themes (flutter/flutter#132749) 2023-09-27 [email protected] Config changes for linux coverage. (flutter/flutter#135604) 2023-09-27 [email protected] Roll Packages from 619af75 to 21c2ebb (6 revisions) (flutter/flutter#135602) ...
This PR fixes #134846. As discussed in the issue, the onSubmitted callback of a TextField is called when the browser switches tabs or is sent to the background if the flutter app is running in any mobile browser (desktop browsers are not affected). Furthermore there is no straight forward way to distinguish between onSubmitted being called because the user pressed the enter key and it being called because the user switched tabs. For example in a chat app this would cause a message to be sent when the user submits the text by pressing "send" on the virtual keyboard as well as when the user switches to another tab. The later action is likely not so much intended.
The next section explains what causes the bug and explains the proposed fix.
Bug Analysis
The root cause for this behaviour is line 3494 in editable_text.dart:
flutter/packages/flutter/lib/src/widgets/editable_text.dart
Lines 3487 to 3499 in 0b540a8
Only if the app is running on the web
_finalizeEditing
is called and this will then trigger the onSubmitted callback. If flutter is running on the web, there are only exactly 3 cases, in which the function is called. The following call trace analysis will describe why.connectionClosed()
is only called by in one location,_handleTextInputInvocation
of the TextInput service.https://github.com/flutter/flutter/blob/367203b3011fc1752cfa1f51adf9751d090c94e6/packages/flutter/lib/src/services/text_input.dart#L1896C12-L1899
onConnectionClosed
function of the TextEditingChannel.https://github.com/flutter/engine/blob/cbda68a720904137ee9dfdf840db323afcf52705/lib/web_ui/lib/src/engine/text_editing/text_editing.dart#L2242-L2254
onConnectionClosed
in turn is only called by thesendTextConnectionClosedToFrameworkIfAny
function ofHybridTextEditing
.https://github.com/flutter/engine/blob/cbda68a720904137ee9dfdf840db323afcf52705/lib/web_ui/lib/src/engine/text_editing/text_editing.dart#L2340-L2345
The function
sendTextConnectionClosedToFrameworkIfAny
is only called at 3 distinct locations of the web engine.1. IOSTextEditingStrategy
As described in the comment
sendTextConnectionClosedToFrameworkIfAny
is called if the browser is sent to the background or the tab is changed.https://github.com/flutter/engine/blob/cbda68a720904137ee9dfdf840db323afcf52705/lib/web_ui/lib/src/engine/text_editing/text_editing.dart#L1632-L1656
2. AndroidTextEditingStrategy
Same situation as for iOS.
sendTextConnectionClosedToFrameworkIfAny
is also called ifwindowHasFocus
is false, which is the case if the browser is sent to background or the tab is changed.https://github.com/flutter/engine/blob/cbda68a720904137ee9dfdf840db323afcf52705/lib/web_ui/lib/src/engine/text_editing/text_editing.dart#L1773-L1785
3. TextInputFinishAutofillContext
This call seems to always happen when
finishAutofillContext
is triggered by the framework.https://github.com/flutter/engine/blob/cbda68a720904137ee9dfdf840db323afcf52705/lib/web_ui/lib/src/engine/text_editing/text_editing.dart#L2075-L2083
Proposed Fix
The fixed proposed and implemented by this PR is to simply delete the call to
_finalizeEditing
in theconnectionClosed
function of editable_text.dart.flutter/packages/flutter/lib/src/widgets/editable_text.dart
Lines 3487 to 3499 in 0b540a8
The reasoning for this being:
_finalizeEditing
is only called inconnectionClosed
for the web engine._finalizeEditing
call in 3 cases._finalizeEditing
as it only instructs the platform to save the current values. Other platforms also don't have anything that would trigger onSubmitted being called, so it seems safe to remove it._finalizeEditing
unifies the platform behaviour. See also[Text Input] Only unfocus when receive connectionClosed on platform except web #123929
Close connection on keyboard close engine#41500
List which issues are fixed by this PR. You must list at least one issue.
#134846
To simplify the evaluation, here are two versions of the minimal example given in the issue, build with the current master and with this PR applied:
current master: https://tauu.github.io/flutter-onsubmit-test/build/web-master/
current master PR applied: https://tauu.github.io/flutter-onsubmit-test/build/web/
Pre-launch Checklist
///
).