Skip to content

[web] Use defensive null check in text editing placeElement - #180795

Merged
auto-submit[bot] merged 2 commits into
flutter:masterfrom
flutter-zl:null_0109
Jan 29, 2026
Merged

[web] Use defensive null check in text editing placeElement#180795
auto-submit[bot] merged 2 commits into
flutter:masterfrom
flutter-zl:null_0109

Conversation

@flutter-zl

Copy link
Copy Markdown
Contributor

Fixes #178619

Uses defensive null check (?.) instead of null assertion (!) when calling focusWithoutScroll() on focusedFormElement in GloballyPositionedTextEditingStrategy.placeElement().

This prevents a crash that can occur due to a race condition where hasAutofillGroup returns true but focusedFormElement is null by the time it's accessed.

@github-actions github-actions Bot added a: text input Entering text in a text field or keyboard related problems engine flutter/engine related. See also e: labels. platform-web Web applications specifically labels Jan 10, 2026
@flutter-zl
flutter-zl requested a review from mdebbar January 12, 2026 01:05
@flutter-zl
flutter-zl marked this pull request as ready for review January 12, 2026 01:05
// does not appear on top-left of the page.
// Refocus on the elements after applying the geometry.
focusedFormElement!.focusWithoutScroll();
focusedFormElement?.focusWithoutScroll();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm concerned this may be putting a band-aid on the real issue. When hasAutofillGroup is true, the expectation is that focusedFormElement is always a real value.

@gemini-code-assist any idea why focusedFormElement would be null here some times?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a very good concern, @mdebbar. The pull request description clarifies this point: "This prevents a crash that can occur due to a race condition where hasAutofillGroup returns true but focusedFormElement is null by the time it's accessed."

This indicates that while hasAutofillGroup might be true, the focusedFormElement itself can become null due to a timing issue between when hasAutofillGroup is checked and when focusedFormElement is actually accessed. Race conditions like this can be challenging to eliminate entirely, especially in asynchronous environments.

The ?. operator acts as a defensive measure, preventing a null pointer exception (crash) if focusedFormElement happens to be null at that exact moment. While it doesn't prevent the underlying race condition from occurring, it ensures the application remains stable. If this race condition is observed frequently or causes other unexpected behavior, a deeper investigation into the lifecycle and synchronization of focusedFormElement and hasAutofillGroup might be warranted to try and prevent the null state from ever occurring.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added a comment explaining the re-entrancy issue.

  1. placeElement() checks hasAutofillGroup → true
  2. placeForm() does DOM operations (insertBefore, etc.)
  3. DOM ops trigger synchronous event handlers that process a pending TextInput.updateConfig
  4. applyConfiguration() replaces inputConfiguration with a config where autofillGroup = null
  5. Back in placeElement(), focusedFormElement is now null → crash

@flutter-zl
flutter-zl requested a review from mdebbar January 14, 2026 21:57

@mdebbar mdebbar left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@flutter-zl flutter-zl added the autosubmit Merge PR when tree becomes green via auto submit App label Jan 27, 2026
@auto-submit auto-submit Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Jan 27, 2026
@auto-submit

auto-submit Bot commented Jan 27, 2026

Copy link
Copy Markdown
Contributor

autosubmit label was removed for flutter/flutter/180795, because The base commit of the PR is older than 7 days and can not be merged. Please merge the latest changes from the main into this branch and resubmit the PR.

@flutter-zl flutter-zl added the autosubmit Merge PR when tree becomes green via auto submit App label Jan 27, 2026
@auto-submit auto-submit Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Jan 27, 2026
@auto-submit

auto-submit Bot commented Jan 27, 2026

Copy link
Copy Markdown
Contributor

autosubmit label was removed for flutter/flutter/180795, because The base commit of the PR is older than 7 days and can not be merged. Please merge the latest changes from the main into this branch and resubmit the PR.

@fluttergithubbot

Copy link
Copy Markdown
Contributor

An existing Git SHA, d7d35fdd9f068b7346de77ee318039ed74518cfa, was detected, and no actions were taken.

To re-trigger presubmits after closing or re-opeing a PR, or pushing a HEAD commit (i.e. with --force) that already was pushed before, push a blank commit (git commit --allow-empty -m "Trigger Build") or rebase to continue.

@flutter-zl flutter-zl reopened this Jan 28, 2026
@fluttergithubbot

Copy link
Copy Markdown
Contributor

An existing Git SHA, d7d35fdd9f068b7346de77ee318039ed74518cfa, was detected, and no actions were taken.

To re-trigger presubmits after closing or re-opeing a PR, or pushing a HEAD commit (i.e. with --force) that already was pushed before, push a blank commit (git commit --allow-empty -m "Trigger Build") or rebase to continue.

@flutter-zl flutter-zl added the autosubmit Merge PR when tree becomes green via auto submit App label Jan 28, 2026
@auto-submit

auto-submit Bot commented Jan 28, 2026

Copy link
Copy Markdown
Contributor

autosubmit label was removed for flutter/flutter/180795, because - The status or check suite Linux linux_host_engine_test has failed. Please fix the issues identified (or deflake) before re-applying this label.

  • The status or check suite Google testing has failed. Please fix the issues identified (or deflake) before re-applying this label.

@auto-submit auto-submit Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Jan 28, 2026
@flutter-zl flutter-zl added the autosubmit Merge PR when tree becomes green via auto submit App label Jan 29, 2026
@auto-submit
auto-submit Bot added this pull request to the merge queue Jan 29, 2026
Merged via the queue into flutter:master with commit fc6d13a Jan 29, 2026
181 of 182 checks passed
@flutter-dashboard flutter-dashboard Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Jan 29, 2026
auto-submit Bot pushed a commit to flutter/packages that referenced this pull request Jan 30, 2026
Roll Flutter from da72d5936d69 to 1d9d6a9a5ef6 (33 revisions)

flutter/flutter@da72d59...1d9d6a9

2026-01-30 [email protected] enable enhanced debugging for GLES playground (flutter/flutter#181157)
2026-01-30 [email protected] Make the Windows windowing_test in .ci.yaml have bringup as false (flutter/flutter#181664)
2026-01-30 [email protected] Roll Packages from cd4fd61 to 510dd40 (4 revisions) (flutter/flutter#181726)
2026-01-30 [email protected] Roll Skia from edbf7e9eb846 to 4745eb2fe837 (1 revision) (flutter/flutter#181725)
2026-01-30 [email protected] Enhance error handling of WidgetsBindingObserver callbacks (flutter/flutter#181174)
2026-01-30 [email protected] Roll Skia from 05d3cb9d2be9 to edbf7e9eb846 (2 revisions) (flutter/flutter#181715)
2026-01-30 [email protected] Roll Skia from c198e5fa9cd9 to 05d3cb9d2be9 (1 revision) (flutter/flutter#181712)
2026-01-30 [email protected] Roll Dart SDK from 920b7e24583e to 2703fd9733ce (2 revisions) (flutter/flutter#181693)
2026-01-30 [email protected] Roll Skia from b9f40c193e7a to c198e5fa9cd9 (6 revisions) (flutter/flutter#181692)
2026-01-30 [email protected] Roll pub packages (flutter/flutter#181690)
2026-01-30 [email protected] Extend the Windows tool_integration_tests_2_9 shard timeout to 1 hour (flutter/flutter#181678)
2026-01-29 [email protected] Add `android_sdk` dependency to `android_engine_opengles_tests` (flutter/flutter#181681)
2026-01-29 [email protected] Roll Dart SDK from a0685c8e946b to 920b7e24583e (3 revisions) (flutter/flutter#181680)
2026-01-29 [email protected] Roll Skia from 128b5213711e to b9f40c193e7a (14 revisions) (flutter/flutter#181675)
2026-01-29 [email protected] [Impeller] Ensure that HostBuffers/DeviceBuffers allocated by RendererTest tests are valid for the lifetime of the RenderPass (flutter/flutter#181635)
2026-01-29 [email protected] [Impeller] Fix off-by-one indices in the SimilarPointPair/SimilarPointTrio functions used by ShadowPathGeometryTest (flutter/flutter#181623)
2026-01-29 [email protected] 180162 fix radio list tile and switch list tile accept widget states controller (flutter/flutter#180367)
2026-01-29 [email protected] Remove unused test file (flutter/flutter#181671)
2026-01-29 [email protected] Roll libpng to version 1.6.54 (flutter/flutter#181625)
2026-01-29 [email protected] Remove nonstandard ndkpath for `hybrid_android_views` integration test (flutter/flutter#181666)
2026-01-29 [email protected] Add TestWidgetsApp utility and refactor widget tests to use WidgetsApp (flutter/flutter#180456)
2026-01-29 [email protected] Add `TestTextField` and migrate tests (flutter/flutter#180494)
2026-01-29 [email protected] Merge changelog for 3.38.9 (flutter/flutter#181668)
2026-01-29 [email protected] [flutter_tools] Deprecate `plugin_ffi` template (flutter/flutter#181588)
2026-01-29 [email protected] Deprecate onReorder callback (flutter/flutter#178242)
2026-01-29 [email protected] [web] Use defensive null check in text editing placeElement (flutter/flutter#180795)
2026-01-29 [email protected] Roll Packages from 1cb2148 to cd4fd61 (4 revisions) (flutter/flutter#181663)
2026-01-29 [email protected] Roll Skia from 89df65f8324c to 128b5213711e (2 revisions) (flutter/flutter#181651)
2026-01-29 [email protected] [hooks] Don't run build hooks for code assets in `flutter run` (flutter/flutter#181542)
2026-01-29 [email protected] Roll Dart SDK from f10dcbfca98f to a0685c8e946b (5 revisions) (flutter/flutter#181653)
2026-01-29 [email protected] Fixes getUniformX for Vulkan (flutter/flutter#181286)
2026-01-29 [email protected] Roll Fuchsia Linux SDK from adhoq9ouVRh0xzkm3... to isy1ARvK-3bsvtfc-... (flutter/flutter#181641)
2026-01-29 [email protected] Add isDark, isLight, and isSystem getters to ThemeMode (flutter/flutter#181475)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC [email protected],[email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
...
LongCatIsLooong pushed a commit to LongCatIsLooong/flutter that referenced this pull request Feb 6, 2026
…180795)

Fixes flutter#178619

Uses defensive null check (?.) instead of null assertion (!) when
calling focusWithoutScroll() on focusedFormElement in
GloballyPositionedTextEditingStrategy.placeElement().

This prevents a crash that can occur due to a race condition where
hasAutofillGroup returns true but focusedFormElement is null by the time
it's accessed.
flutter-zl added a commit to flutter-zl/flutter that referenced this pull request Feb 10, 2026
…180795)

Fixes flutter#178619

Uses defensive null check (?.) instead of null assertion (!) when
calling focusWithoutScroll() on focusedFormElement in
GloballyPositionedTextEditingStrategy.placeElement().

This prevents a crash that can occur due to a race condition where
hasAutofillGroup returns true but focusedFormElement is null by the time
it's accessed.
rickhohler pushed a commit to rickhohler/flutter that referenced this pull request Feb 19, 2026
…180795)

Fixes flutter#178619

Uses defensive null check (?.) instead of null assertion (!) when
calling focusWithoutScroll() on focusedFormElement in
GloballyPositionedTextEditingStrategy.placeElement().

This prevents a crash that can occur due to a race condition where
hasAutofillGroup returns true but focusedFormElement is null by the time
it's accessed.
creatorpiyush pushed a commit to creatorpiyush/packages that referenced this pull request Jun 10, 2026
…r#10931)

Roll Flutter from da72d5936d69 to 1d9d6a9a5ef6 (33 revisions)

flutter/flutter@da72d59...1d9d6a9

2026-01-30 [email protected] enable enhanced debugging for GLES playground (flutter/flutter#181157)
2026-01-30 [email protected] Make the Windows windowing_test in .ci.yaml have bringup as false (flutter/flutter#181664)
2026-01-30 [email protected] Roll Packages from cd4fd61 to 510dd40 (4 revisions) (flutter/flutter#181726)
2026-01-30 [email protected] Roll Skia from edbf7e9eb846 to 4745eb2fe837 (1 revision) (flutter/flutter#181725)
2026-01-30 [email protected] Enhance error handling of WidgetsBindingObserver callbacks (flutter/flutter#181174)
2026-01-30 [email protected] Roll Skia from 05d3cb9d2be9 to edbf7e9eb846 (2 revisions) (flutter/flutter#181715)
2026-01-30 [email protected] Roll Skia from c198e5fa9cd9 to 05d3cb9d2be9 (1 revision) (flutter/flutter#181712)
2026-01-30 [email protected] Roll Dart SDK from 920b7e24583e to 2703fd9733ce (2 revisions) (flutter/flutter#181693)
2026-01-30 [email protected] Roll Skia from b9f40c193e7a to c198e5fa9cd9 (6 revisions) (flutter/flutter#181692)
2026-01-30 [email protected] Roll pub packages (flutter/flutter#181690)
2026-01-30 [email protected] Extend the Windows tool_integration_tests_2_9 shard timeout to 1 hour (flutter/flutter#181678)
2026-01-29 [email protected] Add `android_sdk` dependency to `android_engine_opengles_tests` (flutter/flutter#181681)
2026-01-29 [email protected] Roll Dart SDK from a0685c8e946b to 920b7e24583e (3 revisions) (flutter/flutter#181680)
2026-01-29 [email protected] Roll Skia from 128b5213711e to b9f40c193e7a (14 revisions) (flutter/flutter#181675)
2026-01-29 [email protected] [Impeller] Ensure that HostBuffers/DeviceBuffers allocated by RendererTest tests are valid for the lifetime of the RenderPass (flutter/flutter#181635)
2026-01-29 [email protected] [Impeller] Fix off-by-one indices in the SimilarPointPair/SimilarPointTrio functions used by ShadowPathGeometryTest (flutter/flutter#181623)
2026-01-29 [email protected] 180162 fix radio list tile and switch list tile accept widget states controller (flutter/flutter#180367)
2026-01-29 [email protected] Remove unused test file (flutter/flutter#181671)
2026-01-29 [email protected] Roll libpng to version 1.6.54 (flutter/flutter#181625)
2026-01-29 [email protected] Remove nonstandard ndkpath for `hybrid_android_views` integration test (flutter/flutter#181666)
2026-01-29 [email protected] Add TestWidgetsApp utility and refactor widget tests to use WidgetsApp (flutter/flutter#180456)
2026-01-29 [email protected] Add `TestTextField` and migrate tests (flutter/flutter#180494)
2026-01-29 [email protected] Merge changelog for 3.38.9 (flutter/flutter#181668)
2026-01-29 [email protected] [flutter_tools] Deprecate `plugin_ffi` template (flutter/flutter#181588)
2026-01-29 [email protected] Deprecate onReorder callback (flutter/flutter#178242)
2026-01-29 [email protected] [web] Use defensive null check in text editing placeElement (flutter/flutter#180795)
2026-01-29 [email protected] Roll Packages from 1cb2148 to cd4fd61 (4 revisions) (flutter/flutter#181663)
2026-01-29 [email protected] Roll Skia from 89df65f8324c to 128b5213711e (2 revisions) (flutter/flutter#181651)
2026-01-29 [email protected] [hooks] Don't run build hooks for code assets in `flutter run` (flutter/flutter#181542)
2026-01-29 [email protected] Roll Dart SDK from f10dcbfca98f to a0685c8e946b (5 revisions) (flutter/flutter#181653)
2026-01-29 [email protected] Fixes getUniformX for Vulkan (flutter/flutter#181286)
2026-01-29 [email protected] Roll Fuchsia Linux SDK from adhoq9ouVRh0xzkm3... to isy1ARvK-3bsvtfc-... (flutter/flutter#181641)
2026-01-29 [email protected] Add isDark, isLight, and isSystem getters to ThemeMode (flutter/flutter#181475)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC [email protected],[email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: text input Entering text in a text field or keyboard related problems engine flutter/engine related. See also e: labels. platform-web Web applications specifically

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Null check operator used on a null value

3 participants