Repository navigation
chore: remove hardcoded messages - #3192
Conversation
WalkthroughExternalized many hardcoded default UI strings to props and CMS settings across search, navigation, product, cart, region, filter, and shipping codepaths; added several new optional props and CMS fields and refactored useShippingSimulation to accept an options object with an error message override. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. |
There was a problem hiding this comment.
Actionable comments posted: 7
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (7)
packages/core/src/components/ui/Breadcrumb/Breadcrumb.tsx (1)
7-12:⚠️ Potential issue | 🟡 MinorType inconsistency:
iconis required but guarded with nullish coalescing.
iconis typed as requiredstring, but line 30 usesicon ?? Icon.props.name, implying it could be undefined at runtime. Either:
- Make
iconoptional if CMS might not provide it:icon?: string- Remove the fallback if CMS guarantees the value
Suggested fix if icon should be optional
export interface BreadcrumbProps extends UIBreadcrumbProps { - icon: string - alt: string + icon?: string + alt: string }Also applies to: 30-30
packages/core/src/components/search/Filter/FilterSlider.tsx (1)
128-154:⚠️ Potential issue | 🟡 MinorAccessibility concern: button labels may render empty.
Both
clearButtonLabelandapplyButtonLabelare optional props. When undefined, buttons render without visible text, which violates accessibility best practices.Since this is a breaking change requiring CMS configuration, consider either:
- Adding validation/console warnings in development when labels are missing
- Documenting clearly that these props are now required for proper UX
packages/core/src/sdk/shipping/useShippingSimulation.ts (1)
178-187:⚠️ Potential issue | 🟡 MinorMissing dependency in
useCallback.
invalidPostalCodeErrorMessageis used insidehandleSubmitbut is not included in the dependency array. This could cause the callback to use a stale error message if the prop changes.Proposed fix
- }, [country, shippingItem, shippingPostalCode]) + }, [country, shippingItem, shippingPostalCode, invalidPostalCodeErrorMessage])packages/core/src/components/ui/ProductDetails/ProductDetailsSettings.tsx (1)
194-205:⚠️ Potential issue | 🟠 MajorGuard against empty
buyButtonTitleto avoid an unlabeled/blank button.With the default removed, a missing CMS value yields no visible label (children are falsy) and risks an unlabeled button. Please enforce non-empty CMS config or add a runtime guard/
aria-labelfallback so the button always has an accessible name. As per coding guidelines: Use semantic HTML and proper ARIA labels for accessibility.✅ Suggested guard + accessible-name fallback
- ) : ( - <BuyButton.Component - {...BuyButton.props} - icon={ - <Icon.Component - {...Icon.props} - name={buyButtonIconName ?? Icon.props.name} - aria-label={buyButtonIconAlt ?? Icon.props['aria-label']} - /> - } - {...buyProps} - > - {buyButtonTitle} - </BuyButton.Component> - )} + ) : buyButtonTitle || buyButtonIconAlt ? ( + <BuyButton.Component + {...BuyButton.props} + aria-label={buyButtonTitle || buyButtonIconAlt} + icon={ + <Icon.Component + {...Icon.props} + name={buyButtonIconName ?? Icon.props.name} + aria-label={buyButtonIconAlt ?? Icon.props['aria-label']} + /> + } + {...buyProps} + > + {buyButtonTitle} + </BuyButton.Component> + ) : null}packages/core/src/components/region/RegionSlider/RegionSlider.tsx (1)
339-348:⚠️ Potential issue | 🟡 MinorGuard the clear button against empty labels (accessibility).
With defaults removed, this can render a button without an accessible name if the CMS entry is missing. Consider only rendering
clearBtnPropswhen the label is non-empty (or set anaria-label) to avoid unlabeled controls.💡 Suggested guard
- clearBtnProps={ - isChangingPickupPoint - ? { + clearBtnProps={ + isChangingPickupPoint && + cmsData?.deliveryPromise?.regionSlider?.pickupPointClearFilterButtonLabel + ? { variant: 'secondary', disabled: shouldDisableClearButton, onClick: () => clearFilter(), children: cmsData?.deliveryPromise?.regionSlider ?.pickupPointClearFilterButtonLabel, } : undefined }packages/core/src/components/product/ProductCard/ProductCard.tsx (1)
85-188:⚠️ Potential issue | 🟠 MajorPass
buttonLabelthrough toUIProductCardContent.After removing the default, the CTA renders without text because
buttonLabelisn’t forwarded. This is a UX/accessibility regression whenonButtonClickis set.🔧 Suggested fix
<UIProductCardContent title={name} price={{ value: spotPrice, listPrice: listPrice, formatter: useFormattedPrice, }} ratingValue={ratingValue} outOfStock={outOfStock} + buttonLabel={buttonLabel} onButtonClick={onButtonClick} linkProps={linkProps} showDiscountBadge={hasDiscount && showDiscountBadge} includeTaxes={taxesConfiguration?.usePriceWithTaxes} includeTaxesLabel={taxesConfiguration?.taxesLabel} sponsored={!!advertisement} sponsoredLabel={sponsoredLabel} deliveryPromiseBadges={shouldDisplayDeliveryPromiseBadges && badges} />packages/core/src/sdk/deliveryPromise/useDeliveryPromise.ts (1)
224-252:⚠️ Potential issue | 🟡 MinorAvoid emitting empty labels for facets/badges.
With CMS defaults removed, labels can be
''/undefined, yet badges and facets still render. Consider skipping entries when labels are falsy (or fallback to a safe label) to prevent blank UI.💡 Example guard for badges
- if (hasDelivery) { - badges.push({ - label: getBadgeLabel('delivery', true), - availability: true, - }) - } else { - badges.push({ - label: getBadgeLabel('delivery', false), - availability: false, - }) - } + const deliveryLabel = getBadgeLabel('delivery', hasDelivery) + if (deliveryLabel) { + badges.push({ + label: deliveryLabel, + availability: hasDelivery, + }) + }Also applies to: 466-491
🤖 Fix all issues with AI agents
In `@packages/components/src/molecules/ProductCard/ProductCardContent.tsx`:
- Around line 94-104: ProductCardContent is rendering badges/labels/buttons even
when CMS-provided strings (sponsoredLabel, includeTaxesLabel, outOfStockLabel,
buttonLabel) may be undefined; update the JSX in ProductCardContent to
conditionally render each element only when its corresponding label or flag is
present (e.g., wrap sponsored badge rendering with a check for sponsored &&
sponsoredLabel, includeTaxes text only when includeTaxes && includeTaxesLabel,
outOfStock badge only when outOfStockLabel exists, and the CTA button only when
buttonLabel is truthy), and apply the same conditional pattern for
deliveryPromiseBadges and any other label-driven UI between lines ~120-174 so
empty/unlabeled controls are not output.
In `@packages/core/src/components/region/RegionPopover/RegionPopover.tsx`:
- Around line 49-53: RegionPopover: guard against rendering dangling punctuation
or empty nodes when CMS props (title, textBeforeLocation, textAfterLocation,
description) are missing by conditionally composing and rendering the
surrounding text and punctuation only when the related prop exists; i.e., build
the location string by joining non-empty pieces (textBeforeLocation + location +
textAfterLocation) and only render the description element when description has
content (trimmed), remove hardcoded defaults, and ensure the close button uses
the provided closeButtonAriaLabel (or is given a proper semantic button
role/aria-label only if supplied) so markup remains semantic and accessible.
In `@packages/core/src/components/search/Filter/FilterDeliveryMethodFacet.tsx`:
- Around line 20-25: The mapDeliveryMethodLabel currently typed as
Record<string, string> can contain undefined values from deliveryMethods; change
its type to Record<string, string | undefined> or directly assign fallback
strings from CMS (e.g., default labels) so values are never undefined, and
update usages (references to mapDeliveryMethodLabel in
FilterDeliveryMethodFacet) to fall back to a safe string (e.g.,
mapDeliveryMethodLabel['delivery'] ?? 'Delivery') to ensure accessible button
labels; touch symbols: mapDeliveryMethodLabel, deliveryMethods, and any render
sites in FilterDeliveryMethodFacet to implement the type change and fallback
logic.
In `@packages/core/src/components/search/Filter/FilterSlider.tsx`:
- Around line 186-189: The button in FilterSlider.tsx renders only the MapPin
icon when deliveryPromiseSettings?.deliveryMethods?.setLocationButtonLabel is
undefined; update the button rendering (where setLocationButtonLabel is used) to
fall back to a sensible default string (e.g., "Set Location" or a localized
fallback) and add an accessible label (aria-label) using the same fallback so
screen readers always have text; ensure you reference
deliveryPromiseSettings?.deliveryMethods?.setLocationButtonLabel for the primary
label and use the fallback for both visible text and aria-label.
In `@packages/core/src/components/sections/ProductGallery/EmptyGallery.tsx`:
- Around line 25-58: Guard rendering of the toolbar buttons in EmptyGallery:
only render each UILinkButton when both the button object has a non-empty url
and label (e.g., check firstButton?.url && firstButton?.label for the first and
same for secondButton), and only pass the UIIcon (or its name prop) when an icon
name exists (e.g., conditionally include the icon prop or pass name when
firstButton?.icon is truthy) so UILinkButton never receives undefined href and
UIIcon never receives undefined name; apply the same pattern for both
firstButton and secondButton.
In `@packages/core/src/components/ui/Breadcrumb/Breadcrumb.tsx`:
- Line 9: Breadcrumb's `alt` prop is currently assumed present which risks the
home link losing its accessible name if CMS omits it; update the Breadcrumb
component to make the `alt` prop optional and supply a defensive fallback (e.g.,
const accessibleName = alt ?? "Home") wherever the home link/aria-label is set,
or add a runtime validation/logging path that warns when `alt` is undefined
before rendering; reference the `alt` prop and the Breadcrumb component's home
link/aria-label assignment when making the change.
In `@packages/core/src/components/ui/PickupPoints/PickupPointCards.tsx`:
- Line 52: The radio group's aria-label
(aria-label={choosePickupPointAriaLabel}) in the PickupPointCards component may
be undefined; update the component to guarantee an accessible label by providing
a fallback default or making the prop required. Specifically, ensure
choosePickupPointAriaLabel (prop of PickupPointCards) has a sensible default
(e.g., "Choose a pickup point") or else validate/require the prop, or use a
fallback expression in the JSX (aria-label={choosePickupPointAriaLabel ||
"Choose a pickup point"}) so screen readers always receive a name.
🧹 Nitpick comments (2)
packages/core/src/components/search/SearchHistory/SearchHistory.tsx (1)
8-14: Tighten props typing to preserve TS safety.The index signature makes props effectively
any. Consider extendingReact.ComponentProps<typeof UISearchHistory>(orHTMLAttributes<HTMLDivElement>) plustitleto retain type checking.💡 Example typing
-interface SearchHistoryProps { - title?: string - [key: string]: unknown -} +type SearchHistoryProps = React.ComponentProps<typeof UISearchHistory> & { + title?: string +}packages/core/src/components/cart/EmptyCart/EmptyCart.tsx (1)
22-35: Consider fallback text or conditional rendering for accessibility.If
buttonLabelisundefined, the button renders with no visible text, which degrades accessibility. Similarly, an undefinedtitlemay result in an empty heading.Since CMS defaults exist, this should rarely occur in practice, but defensive rendering would improve robustness:
♻️ Proposed fallback handling
function EmptyCart({ title, buttonLabel, onDismiss }: Props) { return ( <UIEmptyState - title={title} + title={title ?? ''} titleIcon={ <UIIcon name="ShoppingCart" width={56} height={56} weight="thin" /> } > - <UIButton onClick={onDismiss} variant="secondary"> - {buttonLabel} - </UIButton> + {buttonLabel && ( + <UIButton onClick={onDismiss} variant="secondary"> + {buttonLabel} + </UIButton> + )} </UIEmptyState> ) }
## What's the purpose of this pull request? Removing hardcoded labels: - #3099 - #3102 - #3107 - #3104 - #3103 - #3125 - #3131 - #3116 - #3142 - #3192 Setting Up locales - #3141 - #3143 - #3147 - #3156 - #3162 - #3145 - #3164 - #3169 - #3171 - #3176 - #3180 - #3169 custom path - #3185 - #3162 - #3156 - #3170 Components - #3093 - #3175 Fetching content - #3165 Others - #3176 - #3171 - #3181 - #3189 - #3205 ## How to test locally? - Run `pnpm I` (install all the new dependencies and needed packages) - If you want to try localization feature, go to`/discovery.config.default.js`: Enable localization: ``` localization: { enabled: true } ``` - Run `node packages/cli/bin/run.js generate-i18n ./packages/core` to fetch the bindings If the contentSource is not set to content platform yet, you will see a message to update to it. > contentSource: { > type: 'CP', > },⚠️ Note: Ensure the url is set to localhost for local testing. These locale bindings are generated in `discovery.config` after running the generate-i18n command. ```diff localization: { enabled: true, defaultLocale: 'en-US', regions: {...}, locales: { 'pt-BR': { ... bindings: [ { currencyCode: 'BRL', - url: 'https://brandless.fast.store/pt-BR', + url: 'http://localhost:3000/pt-BR', salesChannel: '2', isDefault: true, locales: [ { code: 'pt-BR', isDefault: true, }, ], }, ], }, 'it-IT': { ... bindings: [ { currencyCode: 'EUR', - url: 'https://brandless.fast.store/it-IT', + url: 'http://localhost:3000/it-IT', salesChannel: '3', isDefault: true, locales: [ { code: 'it-IT', isDefault: true, }, ], }, { currencyCode: 'EUR', - url: 'https://brandless.fast.store/europe/it', + url: 'http://localhost:3000/europe/it', salesChannel: '3', isDefault: false, locales: [ { code: 'it-IT', isDefault: true, }, ], }, ], }, 'en-US': { code: 'en-US', name: 'English', languageCode: 'en', languageName: 'English', script: 'Latn', textDirection: 'ltr', regionCode: 'US', bindings: [ { currencyCode: 'USD', - url: 'https://brandless.fast.store', + url: 'http://localhost:3000, salesChannel: '1', isDefault: true, locales: [ { code: 'en-US', isDefault: true, }, ], }, ], }, ... } ``` - Go to /packages/core and run `npmn dev` --------- Co-authored-by: Larícia Mota <[email protected]> Co-authored-by: Leandro Rodrigues <[email protected]> Co-authored-by: Otavio Moreira Meirelles <[email protected]> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
What's the purpose of this pull request?
This PR removes hardcoded messages, ensuring that all default messages are centralized in CMS configuration files (
sections.jsonandcontent-types.json). This enables better localization support and allows store owners to customize all UI messages through the CMS without requiring code changes.This PR will be merged in the feat/multilanguage feature branch, which will be available only in the next faststore major version.
How it works?
In each commit I have fixed an specific part to make review process easier, then I'd recommend review per commit. Some I've only removed the hardcoded message because its default was already present in the CMS files, and others I had to also add the default in the CMS file.
Key Changes:
Components updated:
Components intentionally skipped:
How to test it?
Sync CMS changes, publish the affected pages and check the messages appear.
Starters Deploy Preview
Summary by CodeRabbit
New Features
Improvements
✏️ Tip: You can customize this high-level summary in your review settings.