Skip to content

[BUG]: LinkAuthenticationElement no longer fires onChange event when it is mounted. #365

@alexdiv87

Description

@alexdiv87

What happened?

Hi There, I am upgrading from version 1.7.0 to the latest 1.16.1. We are noticing a difference in behavior with the LinkAuthenticationElement. Previously, when this component was mounted, the onChange event would consistently fire. We used this event to rely on Stripe to perform the email validation. After upgrading, we are seeing that the onChange event doesn't always fire when the component is mounted, it seems intermittent. Sometimes it fires, and other times it does not. I'll include a code snippet, any help would be appreciated.

export const StripeLinkAuthenticationElement = (): React.ReactElement => {
  const [email, setEmail] = useLocalStorage<string>(
    EnumStorageKeys.CUSTOMER_EMAIL,
    '',
  )

  const {
    paymentIntentId,
    orderSessionId,
    setIsLinkAuthenticatorReady,
    setIsLinkAuthenticatorCompleted,
  } = useContext(StripeComponentsContext)

  const video = useStore((state) => state.video)
  const checkoutItem = useStore(selectedCheckoutItemSelector)

  return (
    <LinkAuthenticationElement
      options={{ defaultValues: { email: email ? email : '' } }}
      onChange={(e) => {
        if (setIsLinkAuthenticatorCompleted) {
          setIsLinkAuthenticatorCompleted(e.complete)
          setEmail(e.value.email)
        }
      }}
      onReady={() => {
        if (setIsLinkAuthenticatorReady) {
          setIsLinkAuthenticatorReady(true)
        }
      }}
    />
  )
}

As a result, when Stripe Link is enabled, the customer may open the checkout form and have all of their information pre-populated, but we since the onChange event doesn't fire, their email address does not get validated and the button remains disabled. You can reproduce this by visiting this URL: https://fw-staging.tv/embed-url.html?video=oAwwE0&channel=alexdiv&max_videos=1 . Choose any non $0 product and click "Buy Now", Login using Stripe Link, close the popup and reopen. it will open a checkout form where sometimes the button is enabled (onChange event fired). And other times, the button remains disabled when onChange never fired.

What dictates whether onChange fires when the component mounts? Do you have any tools for manually validating email addresses, if we need to manually validate the email address in the onReady event, we want to ensure we're using the same validation that is used in the onChange event.

Environment

Chrome, MacOS

Reproduction

https://fw-staging.tv/embed-url.html?video=oAwwE0&channel=alexdiv&max_videos=1

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions