Skip to content

Bug: "This Element has already been destroyed" when clicking Subscribe in paywall/purchase #763

@kyomster

Description

@kyomster

Bug: "This Element has already been destroyed" when clicking Subscribe in paywall/purchase

Environment

  • @revenuecat/purchases-js: 1.26.0
  • Next.js 15 (App Router)
  • React 19
  • Browser: Chrome (also reproduced in Safari)
  • React Strict Mode: disabled

Description

When calling purchases.purchase() or purchases.presentPaywall(),
the paywall/checkout UI renders correctly, but clicking the "Subscribe"
button triggers the Stripe error:

IntegrationError: This Element has already been destroyed. Please create a new one.

The error occurs on the first call — this is not a re-mount issue.

Minimal reproduction

"use client"
import { useEffect, useState } from "react"
import { Purchases } from "@revenuecat/purchases-js"

export default function TestPage() {
    useEffect(() => {
        Purchases.configure({
            apiKey: "rcb_...",
            appUserId: "test-user",
        })
    }, [])

    const handleBuy = async () => {
        const purchases = Purchases.getSharedInstance()
        const offerings = await purchases.getOfferings()
        const pkg = offerings.current?.availablePackages[0]
        if (!pkg) return

        // Both methods produce the same error:
        await purchases.purchase({ rcPackage: pkg })
        // OR: await purchases.presentPaywall({ offering: offerings.current })
    }

    return <button onClick={handleBuy}>Buy</button>
}

Stack trace

The error originates inside the SDK's own Stripe initialization:

initializeStripe (Purchases.es.js:13157)
→ Stripe Elements are created
→ SDK internal render cycle (_emit, destroy)
→ Elements are destroyed by the SDK itself
→ "This Element has already been destroyed"

Key frames:

  • initializeStripe (Purchases.es.js:13157)
  • i.destroy (stripe.js:494640)
  • Internal SDK render: Sd, Ne, hr, lu (Purchases.es.js)

What I've tried (none worked)

  • Providing htmlTarget (new div on document.body, on documentElement)
  • Creating fresh div each time with document.createElement
  • Re-calling Purchases.configure() before each purchase
  • Isolating in a blank page with zero other React components
  • Disabling React Strict Mode
  • Using purchase() instead of presentPaywall()

The error reproduces on a completely isolated test page with no
other components, confirming it's internal to the SDK.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions