#bjrn-j_api

1 messages · Page 1 of 1 (latest)

radiant solsticeBOT
#

👋 Welcome to your new thread!

⏲️ We'll be here soon! We typically respond in a few minutes, but in some cases we might need a bit more time (e.g., server's busy, you've got a complex question, etc.).

⏱️ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can start a new thread if you have another question.

🔗 This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1256304505729974354

📝 Have more to share? Add details, code, screenshots, videos, etc. below.

fading rampart
#

Hi 👋

I'm going to need a lot more detail in order to help.

Can you start with only the relevant parts of your JavaScript code?

#

And the exact error message you are receiving

sturdy flare
#

I’m gonna get the code for you, but the error itself come from your side and not mine. There is a problem with fingerprints somehow.

#

I had the same issue a few weeks ago, but you couldn’t reproduce it and all of a sudden it worked for me so it’s quite intermittent

fading rampart
#

Regardless of where the error comes from, I need the exact text

sturdy flare
#

Yes, of course, give me a minute. The issue is on the computer and I’m writing on my phone.

#

“Could not retrieve elements store”

fading rampart
#

And you JS code?

sturdy flare
#

const cardPaymentElementLoaded = ref(false);
const loadPaymentElements = () => {
const appearance = {
theme: "stripe",
};
elements = stripe.elements({ appearance, amount: totalAmount.value, currency: "sek", mode: "payment" });

const paymentElementOptions = {
layout: "tabs",
fields: {
billingDetails: {
address: {
country: "never",
postalCode: "never",
},
},
},
};

const paymentElement = elements.create("payment", paymentElementOptions);

paymentElement.on("ready", function (event) {
window.setTimeout(() => (cardPaymentElementLoaded.value = true), 200);
});
if (paymentElement) paymentElement.mount("#payment-element");
};

fading rampart
#

Would I be correct in assuming this line is the one throwing the error?

elements = stripe.elements({ appearance, amount: totalAmount.value, currency: "sek", mode: "payment" });
sturdy flare
#

This is from incognito view

#

No I cannot locate the culprit in my code at all.

#

It is working in development as far as I can tell

fading rampart
#

Looking at our internal code, this error is thrown when Stripe.Js is trying to use an existing instance of elements but it doesn't exist

#

This most often happens with React when an instance of elements is created/destroyed in response to a user action. It is less common in vanilla JS integrations

sturdy flare
#

oh

#

This is vue

#

Can it happen when navigating around and coming back?

fading rampart
#

Hmm for Vue, the reactivity is less of an issue

#

Do you create/destroy your Stripe elements instance on navigation or do you persist it?

sturdy flare
#

It might persist because i am not destrying on leaving

#

Perhaps I should

fading rampart
#

I have a test integration written in Vue and I haven't hit these errors. But I am building a pretty basic approach.

First, you said it runs without error in development?

#

Can you identify any behavior differences between dev and prod?

sturdy flare
#

For now, yes

fading rampart
#

Like, if you take the exact same steps and the same code, can you repro the error?

sturdy flare
#

Not really. I have tried different things. Last time (now that I wrote to you) I removed from cart, changed page and added somthing else, and voila

#

Same steps give different outcome. Even if reload the page, same issue

#

Yeah, okey so:
New chrome profile:

  1. Add to card
  2. To to checkout
  3. Remove from cart
  4. Add other product
  5. Back to checkout - Error
#

I am not seeing this behavior on dev

#

Yes, I am now

#

Okey, so in dev if I just move it out from main thread by wrapping loadPaymentElements in setTimeout it seems to work 100% of the time

fading rampart
#

How are you integrating StripeJS into your Vue front-end? Are you using something like stripe-vue to create a single global instance of Stripe?

sturdy flare
#

script: [{ hid: "stripe", src: "https://js.stripe.com/v3/" }] in nuxt.config and let stripe; first thing in <script setup> in that view

fading rampart
#

Oh, I'm using Nuxt too. But I use vue-stripe plugin so I have

import Vue from 'vue'
import { StripePlugin } from '@vue-stripe/vue-stripe'

export default () => {
  const options = {
    pk: 'STRIPE_PUBLIC_KEY', 
  }
  Vue.use(StripePlugin, options)
}

in a vue-stripe.js file in my plugins directory. Then every page/component has a this.$stripe property

sturdy flare
#

oh, I have never used that

fading rampart
#

It's not something We built but we do coordinate with the maintainers of that library

sturdy flare
#

That do sound more robust

#

I will take a look ASAP

fading rampart
#

I try to assign the stripe elements instance to my Page so it persists but I don't have a lot of navigation in my integrations

#

E.g.

this.elements = this.$stripe.elements()
sturdy flare
#

I am testing quickly now.

fading rampart
#

Okey, so in dev if I just move it out from main thread by wrapping loadPaymentElements in setTimeout it seems to work 100% of the time
I'm still a little confused about this. But it sounds like you are able to both reproduce and eliminate the error

sturdy flare
#

Still issue on prod. Just deployed

#

vue-stripe seems to break SSR

fading rampart
#

But I wouldn't necessarily depend on vue-stripe in this case. I suspect the issue is the instance of elements here is being accessed when it doesn't exist