-
Notifications
You must be signed in to change notification settings - Fork 275
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG]: LinkAuthenticationElement no longer fires onChange
event when it is mounted.
#365
Comments
Hi @alexdiv87, I'm sorry you're experiencing a bug since updating the version. Thank you for providing all of these details and the reproduction! To clarify some of your questions, the intended behavior is that For the bug, I was able to reproduce the issue when I visited the link you provided, but unfortunately didn't have much luck reproducing the issue on my own test integrations. However, we recently made a change between 1.16.0 to 1.16.1 that alters some of our logic for how we add event listeners, and I'd love to nail down whether that's causing the issue you're experiencing here. Could you try installing version 1.16.0, and let me know if the issue persists? For one final thing to try: could you add a log outside of the
|
Hi @awalker-stripe , Thanks for getting back to me so swiftly! I did what you said and tested out version v1.16.0: v1.16.1: In regards to your integration testing of export const RenderStripeComponents: FC<Props> = ({ hidden }) => {
const stripeContainerEl = useRef<HTMLSlotElement | null>(null)
const { clientSecret } = useContext(StripeComponentsContext)
const slot = useRenderStripeElementsContainer({
stripeContainerEl,
clientSecret,
})
return (
<>
<slot name={SLOT_NAME} ref={stripeContainerEl}></slot>
{slot
? createPortal(
<StripeContainer>
<FormSection type={FormTypes.AUTHENTICATOR} hidden={hidden} />
<FormSection type={FormTypes.SHIPPING} hidden={hidden} />
<FormSection type={FormTypes.PAYMENT} hidden={hidden} />
</StripeContainer>,
slot,
)
: null}
</>
)
}
export const StripeContainer = ({
children,
}: {
children: React.ReactNode
}): React.ReactElement => {
const { products } = useProducts()
const accountId = products
? (products[0].payment_providers || []).find((p) => p.provider === 'stripe')
?.uid
: ''
const { clientSecret } = useContext(StripeComponentsContext)
const header: {
betas: string[]
apiVersion: string
stripeAccount?: string
} = useMemo(() => {
return {
betas: ['link_beta_2'],
apiVersion: '2020-08-27;link_beta=v1',
stripeAccount: accountId,
}
}, [accountId])
const stripe = useMemo(
() => loadStripe(defaultStripePublishableKey, header),
[header],
)
return (
<Elements
stripe={stripe}
options={{
clientSecret,
appearance,
}}
>
{children}
</Elements>
)
}
export const useRenderStripeElementsContainer = ({
stripeContainerEl,
clientSecret,
}: Props): HTMLElement | undefined => {
const [slot, setSlot] = useState<HTMLElement | undefined>(undefined)
const renderStripeElements = useCallback(() => {
if (stripeContainerEl && stripeContainerEl.current) {
const storyblock = stripeContainerEl.current.getRootNode().host
const span = document.createElement('span')
span.slot = SLOT_NAME
span.id = STRIPE_CONTAINER_ID
storyblock?.appendChild(span)
setSlot(span)
}
}, [stripeContainerEl])
useEffect(() => {
if (clientSecret) {
renderStripeElements()
}
}, [clientSecret, renderStripeElements])
return slot
} |
Relevant for PaymentElement as well. Downgrading to 1.16.0 fixes it. Environment
|
Hi @alexdiv87 and @vasiliicuhar, Happy New Year, and thank you for your patience on this. Thanks! |
Awesome! Thanks @awalker-stripe Happy New Year to you too! |
@awalker-stripe do you plan to iterate on it later? useEffect is tricky to get right. But one thing for sure, element has to be a real dependency, not a ref, for it to work useEffect(() => {
element.on(/* ... */)
return element.off(/* ... */)
}, [/* important >> */ element]) |
Hey @awalker-stripe , I wonder if you could help me with another issue or I need to file a ticket somewhere else? It's more of a question.. When we upgrade to
This occurs because we are not remounting the Stripe Form when a user clicks Back button. The flow is like so:
From what I can tell, everything seems to be working fine. Although, when it comes to Stripe Link in Staging Env, I can't see which Card they selected, so i'm not able to determine if the Customer is getting charged on the last card they selected, or if it used the first card that was associated with the client secret that was created in the first confirmed Setup Intent. My question is: What is the impact of this warning? |
@vasiliicuhar I appreciate it & totally agree with your comment on the dependencies — this makes sense to me. As a heads up, I do have reproductions of the original issue, and any changes would be tested against that to make sure we don't re-introduce it (thank you again for the in-depth description of your integrations!) @alexdiv87 Similar thread: #246 (comment). In general, we don't support updating the client secret like this, and it could lead to problems down the line. However, there's a workaround in that thread that can get |
Thanks again for all your help. @awalker-stripe |
@awalker-stripe If i try the workaround you recommended (adding
You mentioned that you do not support support this way of updating the client secret but it's what is documented in your docs: https://stripe.com/docs/payments/quickstart#use-webhook. Any thoughts for a real fix or a fix for the exception? Thanks! |
What happened?
Hi There, I am upgrading from version
1.7.0
to the latest1.16.1
. We are noticing a difference in behavior with theLinkAuthenticationElement
. Previously, when this component was mounted, theonChange
event would consistently fire. We used this event to rely on Stripe to perform the email validation. After upgrading, we are seeing that theonChange
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.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 whenonChange
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 theonReady
event, we want to ensure we're using the same validation that is used in theonChange
event.Environment
Chrome, MacOS
Reproduction
https://fw-staging.tv/embed-url.html?video=oAwwE0&channel=alexdiv&max_videos=1
The text was updated successfully, but these errors were encountered: