Skip to content

Fix crash in DomainUpsellCard when site.slug is undefined#108580

Open
StevenDufresne wants to merge 1 commit intotrunkfrom
fix/domain-upsell-card-undefined-slug
Open

Fix crash in DomainUpsellCard when site.slug is undefined#108580
StevenDufresne wants to merge 1 commit intotrunkfrom
fix/domain-upsell-card-undefined-slug

Conversation

@StevenDufresne
Copy link
Contributor

Fixes DOTMSD-1029

Proposed Changes

  • Add a guard for site.slug being undefined in the DomainUpsellCard component to prevent a TypeError crash.

Why are these changes being made?

Sentry issue CALYPSO-2GR5 reports a TypeError: Cannot read properties of undefined (reading 'split') in the useDomainSuggestion hook. The Site TypeScript interface declares slug as required, but the API can return site objects without a slug property in certain edge cases (e.g., deleted or transitioning sites). This guard prevents the crash by returning null when site.slug is missing, consistent with the existing sitePlan guard.

Testing Instructions

  • Visit a site overview page for a site that might have an undefined slug (e.g., a deleted or transitioning site).
  • Verify the domain upsell card does not crash.
  • For normal sites with a valid slug, verify the domain upsell card still renders correctly.

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)?

Guard against undefined site.slug in the DomainUpsellCard component
to prevent TypeError when the API returns a site without a slug property.

Fixes CALYPSO-2GR5
@StevenDufresne StevenDufresne marked this pull request as ready for review February 9, 2026 00:52
@StevenDufresne StevenDufresne requested a review from a team as a code owner February 9, 2026 00:53
@matticbot matticbot added the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label Feb 9, 2026
@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

  • agents-manager
  • help-center
  • notifications
  • wpcom-block-editor

To test WordPress.com changes, run install-plugin.sh $pluginSlug fix/domain-upsell-card-undefined-slug on your sandbox.

Copy link
Contributor

@fushar fushar left a comment

Choose a reason for hiding this comment

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

Visit a site overview page for a site that might have an undefined slug (e.g., a deleted or transitioning site).

The overview page should have not rendered at all because I've (tried to) fix this case here: #108438, so something else must have caused it 🥹

const DomainUpsellCard = ( { site }: { site: Site } ) => {
const { data: sitePlan } = useQuery( siteCurrentPlanQuery( site.ID ) );
if ( ! sitePlan ) {
if ( ! sitePlan || ! site.slug ) {
Copy link
Member

Choose a reason for hiding this comment

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

It would cause a bunch of cascading type errors, but should we change the definition of Site.slug to make it explicit that undefined is possible 😬

The deleted or transitioning site edge case seems easy to miss.

Also, how have they managed to load to the overview page, which requires a slug in the URL, if the slug is missing? Seems like a lot of critical things don't handle this edge case, not just this upsell card 🤔

Copy link
Member

Choose a reason for hiding this comment

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

In particular this line would cause all-important <SiteLink> component to produce a bogus link.

Does there really seem a reason shy a deleted site or transitioning site should not have a slug? Seems perhaps we could fix it server side.

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

Labels

[Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants