Encountering a problem with Vue StripeCheckout while navigating to a different component

I'm looking to integrate the StripeCheckout component into my Vue application. After copying and updating their example code using the composition API from here, everything works fine when I route to the subscribe component. However, if I try to navigate to a different component after rendering the subscribe page, an error occurs while trying to unmount the StripeCheckout component.

Error Message:

Uncaught (in promise) TypeError: Cannot read properties of undefined (reading '__asyncLoader')
    at isAsyncWrapper (runtime-core.esm-bundler.js?d2dd:2243:1)
    at unmount (runtime-core.esm-bundler.js?d2dd:6061:1)
    at unmountComponent (runtime-core.esm-bundler.js?d2dd:6183:1)
    at unmount (runtime-core.esm-bundler.js?d2dd:6068:1)
    at unmountChildren (runtime-core.esm-bundler.js?d2dd:6212:1)
    at unmount (runtime-core.esm-bundler.js?d2dd:6086:1)
    at unmountComponent (runtime-core.esm-bundler.js?d2dd:6183:1)
    at unmount (runtime-core.esm-bundler.js?d2dd:6068:1)
    at unmountChildren (runtime-core.esm-bundler.js?d2dd:6212:1)
    at unmount (runtime-core.esm-bundler.js?d2dd:6086:1)

Subscribe Component Code:

<template>
  <div>
    <stripe-checkout
      ref="checkoutRef"
      mode="subscription"
      :pk="publishKey"
      :line-items="lineItems"
      :success-url="successUrl"
      :cancel-url="cancelUrl"
      @loading="(v) => (this.loading = v)"
    />
    <button @click="submit">Subscribe!</button>
  </div>
</template>

<script lang="ts" setup>
import { StripeCheckout } from "@vue-stripe/vue-stripe";
import { ref } from "vue";
import { EnvironmentVariableManager } from "@/utils/environment-variable-manager";

const publishKey = EnvironmentVariableManager.getStripePublishableKey();
const loading = ref(false);
const lineItems = [
  {
    price: "price_1MLUEMLQEklYWrzRVqxFJqt8",
    quantity: 1,
  },
];

const successUrl = EnvironmentVariableManager.getUrl() + "/subscribe";
const cancelUrl = EnvironmentVariableManager.getUrl() + "/subscribe";

const checkoutRef = ref<StripeCheckout | null>(null);

const submit = () => {
  if (checkoutRef.value) {
    checkoutRef.value.redirectToCheckout();
  } else {
    console.error("Checkout ref not found");
  }
};
</script>

Router Setup:

const routes = [{
    path: "/subscribe",
    name: "Subscribe",
    component: HomeView,
    children: [{ name: "Subscribe", path: "", component: Subscribe }],
  },
];

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes,
});

While researching, I found that with StripeElements, you can call the destroy function before unmounting components. I'm wondering if something similar needs to be implemented for StripeCheckout, although there are no documented functions for this purpose. Any insights on why StripeCheckout triggers an exception during routing/unmounting?

Answer №1

I've encountered the same issue and while I haven't found a permanent solution yet, I have discovered a temporary workaround that has been effective for me.

     <stripe-checkout
      v-if="readyToPay"
      ref="checkoutRef"
      mode="subscription"
      :pk="publishKey"
      :line-items="lineItems"
      :success-url="successUrl"
      :cancel-url="cancelUrl"
      @loading="(v) => (this.loading = v)"
    /> 
    ...
    <script>
     export default {
     name: "Packages",
     data(){return{readyToPay:false}}
     }
    </script>

Then, I utilize a submit function for the payment button to activate the stripe-checkout component, allowing it to display and proceed with the payment process afterwards.

      async submit() {
      this.readyToPay = true;
      await this.$nextTick();
      ...
      }

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Why is the lifecycle callback not being triggered?

I am currently learning how to develop with Vue.js. I have been trying to use the lifecycle callbacks in my code. In my App.vue file, I have implemented the onMounted callback. However, when I run the code, I do not see the message appearing in the consol ...

Exploring the power of Prosemirror with NextJS through Tiptap v2

Greetings everyone, I am a newcomer to Stack Overflow and I am reaching out for assistance regarding an issue that has arisen. The problem at hand pertains to the development of the Minimum Viable Product (MVP) for my startup which specializes in creating ...

Experiencing excessive CPU utilization from Node.js while executing the vue-cli-service serve command

Whenever I run my npm script that uses vue-cli-service serve, the CPU usage by Node exceeds 100%. How can I troubleshoot this problem? I am using a Mac and have installed Node through nvm. My Node version is 10.16 and my npm version is 6.9. ...

Angular JSON converter - Transform XML data to JSON format

Struggling to convert XML API response to JSON using xml2js library, facing issues with getting 'undefined' in the console. Here is my API service: export class WordgameService { public apiUrl = "http://www.wordgamedictionary.com/api/v1/reference ...

JavaScript's async function has the capability to halt execution on its own accord

Presented here is a JavaScript async function designed to populate a sudoku board with numbers, essentially solving the puzzle. To enhance the user experience and showcase the recursion and backtracking algorithm in action, a sleeper function is utilized b ...

Is it possible to set up tsc to compile test specifications specifically from a designated directory?

I have been working on integrating e2e tests into an Angular project that was not originally set up with @angular-cli, so I have been manually configuring most of it. Currently, I am trying to define a script in the package.json file to transpile only the ...

Tips on dynamically translating resources using ngx-translate

Can anyone help me with ngx-translate? I'm struggling to figure out how to dynamically translate resources in HTML. Here's an example: "agreement.status.0": "New", "agreement.status.1": "Rejected", ...

Typescript threw an error stating "Cannot access properties of an undefined object" in the React-Redux-axios

As a backend developer, I am not very familiar with frontend development. However, for my solo project, I am attempting to create some frontend functionalities including user login right after setting the password. Below is the code snippet from UserSlice. ...

Experiencing Problems with Bot Framework Authentication - Receiving HTTP 401 Error

My current project involves creating a chat bot using the Microsoft Bot Framework and SDK in TypeScript. I am working on implementing user authentication for the bot to interact with Azure DevOps on behalf of users. While testing authentication in Azure Po ...

Using esri-loader in Nativescript applications

I'm currently facing an issue while trying to incorporate esri-loader into my Nativescript Vue application in order to display a basic map. The code snippet I am using is outlined below: <script> import * as esriLoader from 'esri-loader&ap ...

Error message: An unhandled TypeError occurs when attempting to access properties of an undefined object (specifically, the 'then' property) while refreshing the token using axios

Is there a way to refresh tokens in axios without interrupting the flow? For example, when the server returns an access token expiration error, I want to queue the request and replay it after getting a new token. In React, I'm using promises as shown ...

How can a child component be imported into a parent component within the same JS file using VueJS3 in Options API mode?

const MamaComponent = { template: ` <div >Mama Component</div> ` } const BabyComponent = { template: ` <div >Baby Component</div> ` } What is the process to import BabyComponent into MamaComponent w ...

Angular 6 ActivatedRoute Parameters

I'm having trouble retrieving the data of each record using ActivatedRoute. I've been able to get the ID for each one, but I can't seem to access the other data. Any suggestions? Check out my stackblitz example: https://stackblitz.com/edit/ ...

Elements that allow for asynchronous data submission without requiring a traditional submit button

Hey there, I could really use some help with this puzzle I'm trying to solve. Here's the situation: <ul> <li>Number: <span id="Number">123</span></li> </ul> I want to set up a connection between t ...

The placement of the FirebaseAuth.onAuthStateChanged call in an Angular application is a common concern for developers

Where is the best place to add a global listener initialization call in an Angular app? Take a look at this code snippet: export class AuthService { constructor( private store: Store<fromAuth.State>, private afAuth: AngularFireAuth ) { ...

Exploring the possibilities of TypeScript/angularJS in HTTP GET requests

I am a beginner in typescript and angular.js, and I am facing difficulties with an http get request. I rely on DefinitelyTyped for angular's type definitions. This is what my controller code looks like: module game.Controller { 'use strict& ...

Why isn't my Next.js middleware working properly with TypeScript?

My issue arises from the fact that, despite following the documentation, the middleware in Next.js is not functioning as I anticipated. I experimented with what I thought was the simplest middleware possible. I expected that when navigating to /, a conso ...

Building nested components with Vue.js involves creating a complex routing structure within the architecture

Utilizing vue.js for my administration app, I aim to create a highly modular UI architecture. Therefore, I have structured and enclosed the Header, Body, Sidebar, and Main in single file components as illustrated below. Tree App - Header - dynamic cont ...

Trigger a 'change password' notification using Javascript

Issue: I am currently working on developing a web application that includes a password change functionality without the use of form submission. The process I have in mind is as follows: Show a Bootstrap modal pop-up User enters new password Upon clickin ...

Using the Moment library in a NestJS application

I am integrating momentjs into my nestjs application and I want to ensure that my services can be tested effectively. To achieve this, I have included momentjs in my module setup as shown below: providers: [ { provide: 'MomentWrapper', ...