Skip to content

Preserve SelectableRegion scope across context menu rebuilds#186553

Open
mvincentong wants to merge 1 commit into
flutter:mainfrom
mvincentong:fix-selectionarea-context-menu-rebuild
Open

Preserve SelectableRegion scope across context menu rebuilds#186553
mvincentong wants to merge 1 commit into
flutter:mainfrom
mvincentong:fix-selectionarea-context-menu-rebuild

Conversation

@mvincentong
Copy link
Copy Markdown

Fixes #186459

Description

SelectableRegion conditionally wraps its selection subtree in PlatformSelectableRegionContextMenu on desktop web. When BrowserContextMenu.enabled changes, that wrapper can be removed while the existing root SelectionContainer is still registered, causing a replacement container to register before the old one unregisters.

This keeps the selection status scope keyed from SelectableRegionState, so the selection subtree is reparented across the optional wrapper change instead of recreated.

Tests

  • ../../bin/flutter test --platform chrome test/widgets/selectable_region_test.dart --plain-name 'BrowserContextMenu'
  • ./bin/flutter analyze packages/flutter/lib/src/widgets/selectable_region.dart packages/flutter/test/widgets/selectable_region_test.dart
  • ./bin/dart format --output=none --set-exit-if-changed packages/flutter/lib/src/widgets/selectable_region.dart
  • git diff --check

@github-actions github-actions Bot added the framework flutter/packages/flutter repository. See also f: labels. label May 15, 2026
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a GlobalKey to SelectableRegionState to maintain the SelectableRegionSelectionStatusScope subtree across rebuilds. It also adds a widget test to ensure SelectableRegion can rebuild on the web after disabling the browser context menu. Feedback indicates that the new private GlobalKey should include public-quality documentation and a debugLabel to align with the Flutter style guide.

Comment thread packages/flutter/lib/src/widgets/selectable_region.dart Outdated
@mvincentong mvincentong force-pushed the fix-selectionarea-context-menu-rebuild branch from 01851b9 to 4007a07 Compare May 15, 2026 08:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant