Fix crash in DomainUpsellCard when site.slug is undefined#108580
Fix crash in DomainUpsellCard when site.slug is undefined#108580StevenDufresne wants to merge 1 commit intotrunkfrom
Conversation
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
Jetpack Cloud live (direct link)
Automattic for Agencies live (direct link)
|
|
This PR modifies the release build for the following Calypso Apps: For info about this notification, see here: PCYsg-OT6-p2
To test WordPress.com changes, run |
fushar
left a comment
There was a problem hiding this comment.
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 ) { |
There was a problem hiding this comment.
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 🤔
There was a problem hiding this comment.
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.
Fixes DOTMSD-1029
Proposed Changes
site.slugbeing undefined in theDomainUpsellCardcomponent to prevent aTypeErrorcrash.Why are these changes being made?
Sentry issue CALYPSO-2GR5 reports a
TypeError: Cannot read properties of undefined (reading 'split')in theuseDomainSuggestionhook. TheSiteTypeScript interface declaresslugas required, but the API can return site objects without aslugproperty in certain edge cases (e.g., deleted or transitioning sites). This guard prevents the crash by returningnullwhensite.slugis missing, consistent with the existingsitePlanguard.Testing Instructions
Pre-merge Checklist