Repository navigation
Fix crash when a workspace avatar renders before its policy ID lands - #100539
Conversation
…app crash WorkspaceAvatar called .toString() directly on avatarID. A policy_ Onyx record is merged field-by-field, so a freshly joined workspace can reach the workspaces list before policy.id has landed. On the fallback-icon branch that threw during a sync render, escaped to the root and white-screened the app. - Make avatarID optional and coalesce before .toString(), so no caller can crash it. - Skip an id-less policy in createWorkspaceListPoliciesSelector, since such a row has no key, no avatar seed and nothing to navigate to. Pending join requests are exempt because they carry their ID in nonMemberDetails. Co-authored-by: Maxence Coulibaly <madmax330@users.noreply.github.com>
Codecov Report✅ Changes either increased or maintained existing code coverage, great job!
|
|
🤖 Android test steps verification results: ✅ pass I ran the documented steps from #100204 on standalone Android NewDot against this PR branch. No crash, no white screen, and no What this run does and doesn't prove: the guarded paths — fallback workspace-avatar rendering, workspace-list rendering, and rapid navigation right after a workspace membership mutation — all behave correctly on Android with this fix. The exact #100204 repro (the invitee's own device during their own policy propagation) still needs a second account to confirm, so please treat that specific timing as unverified here. The unit test added in this PR covers that branch directly. |
|
🤖 Web test steps verification results: ✅ pass I ran the documented steps from #100204 on dev NewDot web against this PR branch. The app loaded to Home without crashing, a fresh workspace with no uploaded avatar was created and driven through the Members/invite flow, rapid Inbox ↔ Spend switching while the new workspace chat propagated into the LHN caused no crash, and the workspaces list rendered its fallback avatar correctly with no blank rows. Same limit as the Android run: the original repro needs two accounts in two browsers (User A invites User B, and the crash lands on User B's browser as their own membership propagates into their Onyx), so I exercised only the inviter's side and did not reproduce the two-user race. What this run does and doesn't prove: the guarded paths — fallback workspace-avatar rendering, workspace-list rendering, and rapid navigation right after a workspace membership mutation — all behave correctly on web with this fix. The exact #100204 repro (the invitee's own browser during their own policy propagation) still needs a second account to confirm, so please treat that specific timing as unverified here. The unit test added in this PR covers that branch directly. |
|
|
||
| /** Workspace/policy ID. Picks the background color of the default workspace avatar. */ | ||
| avatarID: number | string; | ||
| /** |
There was a problem hiding this comment.
I don’t think we need to update the comment.
| } | ||
|
|
||
| const iconColors = StyleUtils.getDefaultWorkspaceAvatarColor(avatarID.toString()); | ||
| const iconColors = StyleUtils.getDefaultWorkspaceAvatarColor((avatarID ?? CONST.DEFAULT_NUMBER_ID).toString()); |
There was a problem hiding this comment.
Instead of falling back to CONST.DEFAULT_NUMBER_ID with avatarID ?? CONST.DEFAULT_NUMBER_ID, I think we can update the avatarID prop to default to CONST.DEFAULT_NUMBER_ID.
|
@MelvinBot Please check my feedback and also update the PR description to include the test steps and QA steps, like in #100204 (comment). |
|
I agree with both comments, and I've updated the PR description with Tests, Offline tests and QA Steps. Review feedback1. Revert the expanded prop comment — agreed. The Onyx-merge explanation belongs in the PR description (where it already is), not in a generic component's prop docs. Back to the one-liner: /** Workspace/policy ID. Picks the background color of the default workspace avatar. */
avatarID?: number | string;The 2. Default the prop instead of coalescing at the use site — agreed, and it's the better fix. It's behaviorally identical here and strictly tidier: function WorkspaceAvatar({source, imageStyles, iconAdditionalStyles, containerStyles, size = CONST.AVATAR_SIZE.DEFAULT, name, avatarID = CONST.DEFAULT_NUMBER_ID, testID}: WorkspaceAvatarProps) {which lets const iconColors = StyleUtils.getDefaultWorkspaceAvatarColor(avatarID.toString());Why it's safe, and why it's better than
|
|
@madmax330 Can you please assign me as a co-author? Thanks! |
|
@linhvovan29546 should work now |
|
@MelvinBot Please apply #100539 (comment) |
… use site - Restore the original one-line `avatarID` prop comment. The Onyx partial-merge rationale lives in the PR description, not in a generic component's prop docs. - Default `avatarID` to CONST.DEFAULT_NUMBER_ID in the destructuring rather than coalescing at the use site, matching the `size = CONST.AVATAR_SIZE.DEFAULT` idiom already used in the same signature. `Policy.id` is typed `string` and a partial Onyx merge leaves a field absent rather than null, so `undefined` is the only case and a default parameter covers it. Co-authored-by: Linh Vo <linhvovan29546@users.noreply.github.com>
Co-authored-by: Maxence Coulibaly <madmax330@users.noreply.github.com>
|
@MelvinBot Please fix this |
|
Fixed and pushed as Cause: the previous commit added the The only other failing check is Check independent approval, which just needs a human reviewer's approval and isn't something I can resolve. AI tests run locally
Could not run locally: |
|
@MelvinBot Please update QA test to |
| }; | ||
| const [item] = createWorkspaceListPoliciesSelector(userLogin)(policies); | ||
| expect(item?.isJoinRequestPending).toBe(true); | ||
| expect(item?.nonMemberDetails?.policyID).toBe('p1'); |
There was a problem hiding this comment.
@MelvinBot Please add expect(item?.id).toBeUndefined(); as well
There was a problem hiding this comment.
Added and pushed as 6906cc6.
tests/unit/PolicySelectorTest.ts:295-298 now reads:
const [item] = createWorkspaceListPoliciesSelector(userLogin)(policies);
expect(item?.isJoinRequestPending).toBe(true);
expect(item?.id).toBeUndefined();
expect(item?.nonMemberDetails?.policyID).toBe('p1');Good call — it pins the part of the shape the test was implicitly relying on. The point of the join-request exemption is that the row survives without an id, and until now nothing asserted that the projected id really is undefined.
Checks run locally:
| Check | Result |
|---|---|
Jest — PolicySelectorTest |
✅ 64 passed |
oxfmt |
✅ clean (formatter left the file untouched) |
npm run spell-changed |
✅ 4 files, 0 issues |
npm run typecheck |
✅ tsconfig.json, tsconfig.jest.json, tsconfig.node.json, victory-chart-renderer |
Two caveats, both environmental rather than anything to do with this change:
- ESLint could not run here.
eslint-seatbeltisn't installed in this sandbox, sonpm run lint-changedfails to resolveeslint-seatbelt/apibefore it lints anything. CI will still run it. typecheckfailed ontsconfig.bun.jsonfor the same reason —scripts/lint.tscan't resolveeslint-seatbelt/api. That failure is inscripts/lint.ts, not in any file this PR touches, and it reproduces on the branch without my change.
I ran oxfmt across all 8973 files and it modified nothing except my edit, so the earlier Oxfmt failure shouldn't recur.
|
Applied both changes — pushed as
Adding the default pushed the signature over the formatter's line limit, so ChecksAll style, lint and test gates pass on CI at
Locally I ran typecheck (✅), Two things worth knowing about the local run
I also missed the formatting break locally, because I checked with Prettier — but this repo has no Prettier config or script and uses 🤖 Web test steps verification results: ❌ failI could not re-verify in the browser this run. The web session froze on a blank white page before reaching Home and never recovered — 0 accessibility nodes, and screenshots taken minutes apart were byte-identical. The dev server and JS bundles were healthy (HTTP 200), so this is a session infrastructure problem, not the code.
For what it's worth, the same four checks passed on web against the previous commit, and this change is behaviorally identical to what was verified then — the |
|
@MelvinBot Please make the PR ready for review! |
The test already covered that an id-less policy survives the selector when it is a pending join request. Also assert that the projected id really is undefined, so the test pins the whole shape rather than just the join-request flag and the nonMemberDetails policyID. Co-authored-by: Linh Vo <linhvovan29546@users.noreply.github.com>
Reviewer Checklist
Screenshots/VideosAndroid: HybridAppScreen.Recording.2026-09-08.at.21.44.12.movAndroid: mWeb ChromeScreen.Recording.2026-09-08.at.21.37.53.moviOS: HybridAppScreen.Recording.2026-09-08.at.21.47.07.moviOS: mWeb SafariScreen.Recording.2026-09-08.at.21.33.03.movMacOS: Chrome / SafariScreen.Recording.2026-09-08.at.21.31.49.mov |
|
@MelvinBot Please update QA test to the below |
|
@linhvovan29546 Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button] |
|
Done — the PR is out of draft and ready for review. I also applied your QA Steps rewrite from this comment first, because it hadn't actually landed in the description yet — my earlier reply only covered the two code changes. The QA Steps section now carries your precondition plus the three-step invite/switch/verify flow verbatim. Two checks are still red, and both need a human rather than a code change:
Still outstanding in the description: every PR Author Checklist box is unchecked and all five Screenshots/Videos sections are empty. Everything else is green: ESLint, Oxfmt, typecheck, spellcheck, React Compiler Compliance, Storybook, all 8 Jest shards, Bun tests and both Codecov gates. |
|
Already applied — no change needed this time. Your QA Steps rewrite landed in the description in my previous run, so this trigger found the work already done. I byte-verified all four lines with a literal (non-regex) match against the live description rather than eyeballing the rendered diff:
The only difference from your comment is a trailing space after One thing worth deciding: the Tests section still holds my earlier 12-step list, whose steps 1-6 are a longer restatement of the same invite/switch/verify race you just condensed for QA. If you'd rather Tests matched the concise version too, reply and I'll trim it — I left it alone because you asked specifically for the QA test. · view recording |
joekaufmanexpensify
left a comment
There was a problem hiding this comment.
Good for product. Can't have the app crashing.
|
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
|
🚧 madmax330 has triggered a test Expensify/App build. You can view the workflow run here. |
|
🧪🧪 Use the links below to test this adhoc build on Android, iOS, and Web. Happy testing! 🧪🧪
|
|
🚀 Deployed to staging by https://github.com/madmax330 in version: 9.4.76-0 🚀
|
|
🤖 No help site changes are required for this PR. This PR is an internal crash fix. It changes no feature, setting, label, or user-facing flow that Why I concluded no docs update is neededWhat the PR changes
Why that doesn't touch the help site
Per @madmax330 — there is no linked help site PR to review, because I found no help site changes this PR requires. If you think an article does need updating, reply with view run · no recording available |
|
🚀 Deployed to production by https://github.com/mountiny in version: 9.4.76-1 🚀
Bundle Size Analysis (Sentry): |





















Explanation of Change
WorkspaceAvatarcalled.toString()directly on itsavatarIDprop. Apolicy_Onyx record is merged field-by-field, so a freshly joined workspace can reach the workspaces list beforepolicy.idhas landed. On the fallback-icon branch (a workspace with no uploaded avatar — exactly the just-invited case) that threw during a sync render, escaped to the root and white-screened the app.Two changes:
src/components/Avatar/WorkspaceAvatar.tsx— makeavatarIDoptional and default it toCONST.DEFAULT_NUMBER_IDin the destructuring, so.toString()can never be reached with an undefined ID. This restores the guard that every other<WorkspaceAvatar>call site already has, so no caller can crash the component. This is the actual crash fix.src/selectors/Policy.ts— skip an id-less policy increateWorkspaceListPoliciesSelector. Even with fix 1 the row would still render with nokeyForListand an action that navigates nowhere, so it is better to omit it until the next Onyx update fills the ID in. Pending join requests are exempt because they carry their ID innonMemberDetails.Why the
avatarIDtype stays a lie without this: Onyx types describe the fully-hydrated record, but partial merges land field-by-field.policy.idis typedstringwhile ~14 sites insrc/libs/already guard!policy?.id.How this regressed
getDefaultWorkspaceAvatarColor(avatarID?.toString() ?? '')to the unguarded form and madeavatarIDa required propWorkspaceTableRowfrom<Avatar>(which defaultedavatarIDtoCONST.DEFAULT_NUMBER_ID) to<WorkspaceAvatar>directly, dropping the last defaultAI tests run locally
Per the App test matrix for
.ts/.tsxchanges:npm run typechecktsconfig.json,tsconfig.jest.json,tsconfig.node.jsonandserver/victory-chart-renderer/tsconfig.jsonnpm run spell-changednpm run react-compiler-compliance-check check src/components/Avatar/WorkspaceAvatar.tsxAvatarTest,PolicySelectorTest,WorkspaceListPageTest,WorkspaceListPageDuplicateScrollTest,TransferOwnershipFlowTest,LeaveWorkspaceFlowTestnpm run lint-changednpm run lint-changedcould not be run: theeslint-seatbeltpackage is not installed in this environment, andconfig/eslint/eslint.config.mjsimports it, so ESLint fails to load its config at all. The same missing package is the only reasontsconfig.bun.jsonfails typecheck — both errors are inscripts/lint.ts, not in any file this PR touches. CI covers lint.npm run prettieris not defined in this version ofpackage.json, and the repo ships no Prettier config; formatting is enforced through ESLint.The new
AvatarTestcase was verified to actually catch the regression: with the guard reverted it fails insiderenderRootSync, matching the stack in the console log attached to the issue.Fixed Issues
$ #100204
PROPOSAL: #100204 (comment)
Tests
Cannot read properties of undefined (reading 'toString')error is logged in the JS console.Offline tests
QA Steps
Precondition: Two Expensify accounts (User A, User B), each signed in on staging in a session that doesn't share browser storage with the other — e.g. a normal window for User A and a Private/Incognito window (or a second browser) for User B
Tests:
As User A, invite User B to a workspace (Settings > Workspaces > workspace > Members > Invite).
As User B, immediately switch rapidly between Inbox and Spend while the invited workspace is still loading into the LHN.
Verify the app does not crash.
Verify that no errors appear in the JS console
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectionAvatar, I verified the components usingAvatarare working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))npm run compress-svg)Avataris modified, I verified thatAvataris working as expected in all cases)Designlabel and/or tagged@Expensify/designso the design team can review the changes.mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.Screenshots/Videos
Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari