Skip to content

Comments

Fix navigation menu issues#22576

Merged
nbradbury merged 42 commits intotrunkfrom
issue/menu-fixes
Feb 12, 2026
Merged

Fix navigation menu issues#22576
nbradbury merged 42 commits intotrunkfrom
issue/menu-fixes

Conversation

@nbradbury
Copy link
Contributor

@nbradbury nbradbury commented Feb 9, 2026

Description

Partially addresses CMM-1166.

This PR is the result of asking Claude to investigate the Menus feature and locate potentially serious issues. The following problems were found and fixed in this PR:

  • Cache sync after reorder: updateMenuItemOrder() now updates currentMenuItems after a successful server-side swap, preventing stale data from causing incorrect menu order assignments, wrong available parents, and cascading reorder failures
  • Silent navigation failures: navigateToEditMenu(), navigateToMenuItems(), and navigateToEditMenuItem() now log a warning and show an error to the user instead of silently returning when an item isn't found in cache
  • NavController null safety: Added navigateTo() helper with null-check logging so navigation failures when navController isn't set are visible in logs instead of silently swallowed
  • JSON parsing logging: parseJsonStringArray() now logs parse failures via AppLog.w instead of silently returning an empty list
  • sanitizeInput trims on every keystroke: The trim() should happen at save time, not during input, otherwise users can't type spaces in the input fields

These two bugs found during testing are also fixed:

  • Keyboard hides Save button: The menu detail and menu item detail screens are now scrollable so the keyboard no longer prevents access to the Save button
  • Link URL validation: Previously we validated link item URLs, but checking the web app it doesn't validate but instead lets the user enter anything and then makes it a valid URL. We now follow the same approach here.

Testing instructions

Reorder menu items:

  1. Open a site with navigation menus
  2. Navigate to a menu's items list
  3. Reorder an item using the up/down buttons
  4. Tap the reordered item to edit it
  • Verify the edit screen shows the correct data (not stale pre-reorder data)
  1. Reorder the same item again
  • Verify the second reorder works correctly without data inconsistency

Navigation error handling:

  1. Open the menus list
  2. Tap a menu to view its items
  • Verify navigation works normally when data is in cache
  • Verify an error message appears if the menu data is missing (edge case)

Sanitize input:

  • Verify you can type spaces in titles & descriptions

Keyboard hides Save button:

  • Verify you can scroll the Save button into view when the keyboard is showing the menu detail and menu item detail screens

Link URL validation:

  • Verify that link URLs are normalized after saving the menu item

nbradbury and others added 29 commits February 5, 2026 06:12
Implements infinite scroll pagination for menu list, menu item list, and
linkable items dropdown with page size of 20. Shows loading spinner when
fetching more items.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Fix pagination not triggering after second page by properly tracking
  state changes in LaunchedEffect keys
- Remove inaccurate menu item count from menu list
- Remove unused fetchAllMenuItems function
- Move Edit Items button to end of menu card, centered vertically
- Fix detekt warnings: swallowed exceptions, unused imports, complexity
- Extract MenuItemListContent and sibling helper functions

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The ExposedDropdownMenu doesn't support LazyColumn (SubcomposeLayout
intrinsic measurement issue), causing crashes when opening the dropdown.
This replaces it with a ModalBottomSheet which properly supports
pagination with LazyColumn.

Also restores PAGE_SIZE to 20 (was 5 for testing).

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This resource was left over after removing the menu item count feature.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Extract duplicate type selection label logic to helper function
- Simplify parseErrorMessage by consolidating redundant cases
- Consolidate findPreviousSiblingIndex/findNextSiblingIndex into single function

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Prevents race conditions when multiple pagination requests occur in
rapid succession. Each pagination function now uses a mutex to ensure
atomic read-check-update operations, preventing duplicate items or
incorrect pagination state.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Ensure canLoadMore remains true when pagination fails, allowing users
to retry after transient errors (network issues, timeouts, etc.).

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Prevents stale data from overwriting state when user rapidly switches
between menu item types.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Support all 22 protocols from wp_allowed_protocols(): http, https, ftp,
ftps, mailto, news, irc, irc6, ircs, gopher, nntp, feed, telnet, mms,
rtsp, sms, svn, tel, fax, xmpp, webcal, urn. Also adds support for
anchor links (#section) and protocol-relative URLs (//).

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Derive offset from UI state instead of cache variables to avoid race
  conditions between initial load and pagination
- Set canLoadMore=true on initial load errors to allow retry

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Pre-compute parent-to-children mapping to reduce child lookup from O(n)
to O(1) per item, improving overall complexity from O(n²) to O(n log n).

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Use when expression to reduce return statements from 4 to 2.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add light and dark mode previews for MenuListScreen, MenuDetailScreen,
MenuItemListScreen, and MenuItemDetailScreen showing various states
including loading, empty, error, and populated views.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…-Android into issue/menus-compose-previews

Conflicts:
	WordPress/src/main/java/org/wordpress/android/ui/navmenus/screens/MenuItemDetailScreen.kt
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Restore onDismissRequest and reset showBottomSheet after hiding,
so users can dismiss by tapping the scrim or swiping down, and
the sheet is properly removed from composition after item selection.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Sync currentMenuItems cache after successful reorder to prevent stale data
- Show error to user instead of silently returning on cache misses in navigation
- Add navigateTo() helper with null-check logging for navController
- Log JSON parsing failures in parseJsonStringArray() instead of silently swallowing

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@dangermattic
Copy link
Collaborator

dangermattic commented Feb 9, 2026

1 Warning
⚠️ PR is not assigned to a milestone.

Generated by 🚫 Danger

@nbradbury nbradbury added the Menus label Feb 9, 2026
@wordpress-mobile wordpress-mobile deleted a comment from claude bot Feb 9, 2026
@wpmobilebot
Copy link
Contributor

wpmobilebot commented Feb 9, 2026

App Icon📲 You can test the changes from this Pull Request in Jetpack Android by scanning the QR code below to install the corresponding build.

App NameJetpack Android
FlavorJalapeno
Build TypeDebug
Versionpr22576-c148937
Build Number1484
Application IDcom.jetpack.android.prealpha
Commitc148937
Installation URL6ir8gjubgb9ho
Note: Google Login is not supported on these builds.

@wpmobilebot
Copy link
Contributor

wpmobilebot commented Feb 9, 2026

App Icon📲 You can test the changes from this Pull Request in WordPress Android by scanning the QR code below to install the corresponding build.

App NameWordPress Android
FlavorJalapeno
Build TypeDebug
Versionpr22576-c148937
Build Number1484
Application IDorg.wordpress.android.prealpha
Commitc148937
Installation URL5cl3ipph9avpg
Note: Google Login is not supported on these builds.

- Sync currentMenuItems cache after successful reorder to prevent stale data
- Show error to user instead of silently returning on cache misses in navigation
- Add navigateTo() helper with null-check logging for navController
- Log JSON parsing failures in parseJsonStringArray() instead of silently swallowing

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

� Conflicts:
�	WordPress/src/main/java/org/wordpress/android/ui/navmenus/NavMenusViewModel.kt
@codecov
Copy link

codecov bot commented Feb 9, 2026

Codecov Report

❌ Patch coverage is 6.66667% with 56 lines in your changes missing coverage. Please review.
✅ Project coverage is 38.17%. Comparing base (8d17379) to head (c148937).
⚠️ Report is 3 commits behind head on trunk.

Files with missing lines Patch % Lines
...wordpress/android/ui/navmenus/NavMenusViewModel.kt 7.84% 45 Missing and 2 partials ⚠️
...ss/android/ui/navmenus/screens/MenuDetailScreen.kt 0.00% 7 Missing ⚠️
...g/wordpress/android/ui/navmenus/NavMenusUiState.kt 0.00% 1 Missing ⚠️
...ndroid/ui/navmenus/screens/MenuItemDetailScreen.kt 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##            trunk   #22576      +/-   ##
==========================================
- Coverage   38.18%   38.17%   -0.01%     
==========================================
  Files        2238     2238              
  Lines      111776   111808      +32     
  Branches    15586    15591       +5     
==========================================
+ Hits        42677    42680       +3     
- Misses      65558    65588      +30     
+ Partials     3541     3540       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@nbradbury nbradbury changed the title Fix navigation menu bugs: cache sync, error handling, and null safety Fix navigation menu issues Feb 10, 2026
@nbradbury nbradbury mentioned this pull request Feb 10, 2026
1 task
Base automatically changed from issue/menus-compose-previews to trunk February 10, 2026 15:09
nbradbury and others added 12 commits February 10, 2026 10:10
Add navMenuItemType to buildMenuItemCreateParams and
buildMenuItemUpdateParams so the API receives the correct
item type (custom, post_type, taxonomy, post_type_archive).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The previous approach used mapTypeLabelToType() which matched against
hardcoded English display strings (e.g. "Page", "Post"). These labels
are localized by the WordPress API, so on non-English sites all items
would incorrectly map to TYPE_CUSTOM. Now uses the NavMenuItemType
enum from the API response directly.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
sanitizeInput() was calling trim() on every keystroke, which stripped
trailing spaces while typing and made it difficult to enter multi-word
text. Now only enforces max length during input, and trims whitespace
when building models at save time.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add imePadding() to MenuDetailScreen and MenuItemDetailScreen so the
Save button remains visible above the keyboard. Also inset the auto-add
switch row to prevent it from extending to the screen edge.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Instead of rejecting URLs without recognized protocols, normalize them
at save time by prepending https:// when needed. Anchor links, relative
paths, and recognized protocols (mailto:, tel:, etc.) are preserved
as-is. This matches WordPress web behavior.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@sonarqubecloud
Copy link

@nbradbury nbradbury requested a review from adalpari February 11, 2026 21:38
@nbradbury nbradbury marked this pull request as ready for review February 11, 2026 21:47
Copy link
Contributor

@adalpari adalpari left a comment

Choose a reason for hiding this comment

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

Great fixes!! 👏
:shipit:

@nbradbury nbradbury merged commit 62feda7 into trunk Feb 12, 2026
33 of 34 checks passed
@nbradbury nbradbury deleted the issue/menu-fixes branch February 12, 2026 11:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants