Skip to content

Fix TypeError in MasterbarLoggedIn.renderProfileMenu when user is null#108576

Draft
StevenDufresne wants to merge 1 commit intotrunkfrom
fix/masterbar-profile-menu-null-user
Draft

Fix TypeError in MasterbarLoggedIn.renderProfileMenu when user is null#108576
StevenDufresne wants to merge 1 commit intotrunkfrom
fix/masterbar-profile-menu-null-user

Conversation

@StevenDufresne
Copy link
Contributor

@StevenDufresne StevenDufresne commented Feb 8, 2026

Fixes CALYPSO-297Z

Proposed Changes

  • Add a null guard in MasterbarLoggedIn.renderProfileMenu() to return null when the user prop is not yet available
  • Add test coverage for the profile menu rendering with and without a user

Why are these changes being made?

getCurrentUser() can return null before user data has finished loading from the Redux store. When this happens, renderProfileMenu() attempts to access user.display_name and user.username, which throws a TypeError: Cannot read properties of null (reading
'display_name').

This error has been tracked as https://a8c.sentry.io/issues/CALYPSO-297Z since March 2025.

The fix gracefully skips rendering the profile menu until the user object is available. This is safe because there is nothing meaningful to display without user data — the menu shows the user's display name, username, and gravatar, all of which require the user object.

Testing Instructions

  1. Open the WordPress.com dashboard while logged in
  2. Verify the masterbar profile menu ("Howdy, ...") renders correctly
  3. The fix addresses a race condition during initial page load, so it is best validated by confirming the Sentry error stops recurring after deploy

Pre-merge Checklist

  • Has the general commit checklist been followed? (PCYsg-hS-p2)
  • Have you written new tests for your changes?
  • Have you tested the feature in Simple (P9HQHe-k8-p2), Atomic (P9HQHe-jW-p2), and self-hosted Jetpack sites (PCYsg-g6b-p2)?
  • Have you checked for TypeScript, React or other console errors?
  • Have you tested accessibility for your changes? Ensure the feature remains usable with various user agents (e.g., browsers), interfaces (e.g., keyboard navigation), and assistive technologies (e.g., screen readers) (PCYsg-S3g-p2).
  • Have you used memoizing on expensive computations? More info in Memoizing with create-selector and Using memoizing selectors and Our Approach to Data
  • Have we added the "[Status] String Freeze" label as soon as any new strings were ready for translation (p4TIVU-5Jq-p2)?
    • For UI changes, have we tested the change in various languages (for example, ES, PT, FR, or DE)? The length of text and words vary significantly between languages.
  • For changes affecting Jetpack: Have we added the "[Status] Needs Privacy Updates" label if this pull request changes what data or activity we track or use (p4TIVU-aUh-p2)?

`getCurrentUser()` can return null before user data has loaded,
causing a crash when `renderProfileMenu()` accesses `user.display_name`.
Add a null guard to gracefully skip rendering the profile menu until
the user object is available.

Fixes CALYPSO-297Z

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

This PR modifies the release build for the following Calypso Apps:

For info about this notification, see here: PCYsg-OT6-p2

  • help-center

To test WordPress.com changes, run install-plugin.sh $pluginSlug fix/masterbar-profile-menu-null-user on your sandbox.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants