🐛 - Cap home shortcuts to 4 to prevent Android crash#614
Conversation
There was a problem hiding this comment.
Code Review
This pull request limits the number of home screen shortcuts to four to prevent potential crashes on Android devices. Feedback includes a critical fix for a potential ClassCastException on Android caused by passing a boolean value to the subtitle field instead of a string or undefined, and a suggestion to move the MAX_HOME_SHORTCUTS constant to the top level of the file for better maintainability.
| .map((route) => ({ | ||
| type: `favorite-${route.id}`, | ||
| title: route.label || fromText(route), | ||
| subtitle: !route.label && toText(route), |
There was a problem hiding this comment.
The expression !route.label && toText(route) evaluates to false when route.label is present. Passing a boolean value to Shortcuts.setShortcuts for a field that expects a string (like subtitle) can cause a ClassCastException on the native Android side when the library attempts to call getString("subtitle"). It is safer to use a ternary operator to ensure the value is either a string or undefined.
| subtitle: !route.label && toText(route), | |
| subtitle: !route.label ? toText(route) : undefined, |
|
|
||
| // Both iOS quick actions and Android dynamic shortcuts cap at ~4-5 per app; | ||
| // some Android devices report lower limits and throw if exceeded. | ||
| const MAX_HOME_SHORTCUTS = 4 |
There was a problem hiding this comment.
Summary
Shortcuts.setShortcutsIllegalArgumentException: Max number of dynamic shortcuts exceededon Android devices whosegetMaxShortcutCountPerActivity()is lower than the number of saved favorites (reported on Samsung SM-A155F running Android 16). iOS also caps quick actions at 4, so the same constant is safe cross-platform.Test plan