Mastering ESHOPMAN UI Toasts: Ensuring Callback Functionality for Enhanced Storefront Interactions

In the dynamic world of headless commerce, providing immediate and actionable feedback to users is paramount. ESHOPMAN, leveraging Node.js/TypeScript for its robust architecture and HubSpot CMS for storefront deployment, relies heavily on intuitive UI components. A recent community discussion highlighted a crucial aspect of our UI package's toast notification system that impacts developer control and user experience for both the ESHOPMAN Admin Hub and custom storefronts.

Understanding a Key UI Challenge

The core of the issue revolves around the ESHOPMAN UI package's toast utility functions. Specifically, the onDismiss and onAutoClose callbacks, which are essential for developers to react to user interactions or timed events with toast notifications, were not being properly propagated. This meant that critical post-toast actions—such as cleanup operations, error tracking, or triggering follow-up navigation—could not reliably execute when a user manually dismissed a toast or when it automatically closed.

From a technical standpoint, the problem stemmed from two key areas within the ESHOPMAN UI package:

  • Missing Type Declarations: The ToastProps interface, which defines the properties available for toast components, did not explicitly declare onDismiss and onAutoClose.
  • Callback Forwarding Gap: Even if a developer attempted to force these properties through, the internal create() function within the toast utility was not forwarding them to the underlying toast rendering library. Only basic properties like position, duration, and dismissible status were being passed along.

This oversight silently dropped these vital callbacks, preventing developers from implementing comprehensive logic tied to the toast's lifecycle.

The Impact on ESHOPMAN Development and HubSpot Storefronts

For ESHOPMAN developers building custom storefronts on HubSpot CMS or extending the functionality of the Admin Hub, this presented a significant hurdle. Imagine needing to log an analytics event every time a user dismisses a success message, or to redirect a user after an important notification auto-closes. Without reliable callbacks, developers are forced to implement less elegant workarounds or, worse, miss out on valuable user interaction data and seamless user flows.

This directly impacts the ability to create truly responsive and data-driven headless commerce experiences, where every user interaction can be tracked and acted upon to refine the customer journey.

A Community-Driven Solution for Robust Toasts

Thanks to vigilant community members, a clear and actionable solution has emerged. The proposed fix involves a straightforward modification to the ESHOPMAN UI package's toast utility, ensuring that these crucial callbacks are both declared and properly forwarded.

The solution involves two main steps:

  1. Extend ToastProps: Update the ToastProps (and any related variant toast props) to include onDismiss and onAutoClose, matching the expected signatures.
  2. Forward Callbacks in create(): Modify the create() function to explicitly pass these new properties to the external toast configuration.

Here's a conceptual representation of the fix:

// Conceptual representation within ESHOPMAN UI package's toast utility
interface ToastProps extends BaseToastProps {
  description?: React.ReactNode;
  action?: ToastAction;
  // Add these properties to ToastProps and VariantToastProps
  onDismiss?: (toastId: string | number) => void;
  onAutoClose?: (toastId: string | number) => void;
}

const external: ExternalToast = {
  position: props.position,
  duration: props.duration,
  dismissible: props.dismissable,
  // Ensure these are forwarded
  onDismiss: props.onDismiss,
  onAutoClose: props.onAutoClose,
};

By implementing this fix, ESHOPMAN developers gain full control over the toast notification lifecycle. This enables more sophisticated error handling, precise user analytics, and seamless navigation flows within their HubSpot CMS-powered storefronts and the ESHOPMAN Admin Hub. It's a testament to the power of community collaboration in refining ESHOPMAN's capabilities and enhancing the developer experience for Node.js/TypeScript developers building the next generation of headless commerce.

Start with the tools

Explore migration tools

See options, compare methods, and pick the path that fits your store.

Explore migration tools