From 4d89b5556a560604541b75cb9a209a61c332a396 Mon Sep 17 00:00:00 2001 From: dante01yoon Date: Wed, 23 Sep 2026 23:22:58 -0400 Subject: [PATCH 1/2] fix(billing-web): theme Stripe Elements from the checkout's own theme scope StripePaymentForm resolved its appearance tokens on a probe appended to document.body. billing-web scopes .dark-theme to a wrapper div, so the probe read the light tokens: dark labels and text over the dark panel, and white input boxes. Resolve the tokens and font inside the payment element's container so they follow the theme the form renders in. --- .../billing/stripe/StripePaymentForm.test.ts | 41 ++++++++++++++++++- .../src/billing/stripe/StripePaymentForm.vue | 9 ++-- 2 files changed, 45 insertions(+), 5 deletions(-) diff --git a/packages/account-ui/src/billing/stripe/StripePaymentForm.test.ts b/packages/account-ui/src/billing/stripe/StripePaymentForm.test.ts index 0973e5b86e4..af13091ae1a 100644 --- a/packages/account-ui/src/billing/stripe/StripePaymentForm.test.ts +++ b/packages/account-ui/src/billing/stripe/StripePaymentForm.test.ts @@ -1,6 +1,14 @@ import userEvent from '@testing-library/user-event' import { cleanup, render, screen, waitFor } from '@testing-library/vue' -import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' +import { + afterEach, + beforeEach, + describe, + expect, + it, + onTestFinished, + vi +} from 'vitest' import { h } from 'vue' import type { @@ -75,10 +83,12 @@ function renderForm( publishableKey?: string onConfirm?: (token: string) => void onSubmittingChange?: (submitting: boolean) => void + container?: HTMLElement } = {} ) { - const { publishableKey = 'pk_test_example', ...rest } = props + const { publishableKey = 'pk_test_example', container, ...rest } = props return render(StripePaymentForm, { + container, props: { publishableKey, amountCents, @@ -156,6 +166,33 @@ describe('StripePaymentForm', () => { }) }) + it('themes Stripe from the theme scope the form renders in, not the page body', async () => { + document.body.style.setProperty('--base-foreground', 'rgb(20, 20, 20)') + document.body.style.setProperty('--base-background', 'rgb(255, 255, 255)') + const darkScope = document.createElement('div') + darkScope.style.setProperty('--base-foreground', 'rgb(250, 250, 250)') + darkScope.style.setProperty('--base-background', 'rgb(30, 30, 30)') + document.body.append(darkScope) + onTestFinished(() => { + darkScope.remove() + document.body.removeAttribute('style') + }) + + renderForm(66500, 'pmc_test', { container: darkScope }) + await waitFor(() => expect(stripeMocks.stripe.elements).toHaveBeenCalled()) + + expect(stripeMocks.stripe.elements).toHaveBeenCalledWith( + expect.objectContaining({ + appearance: expect.objectContaining({ + variables: expect.objectContaining({ + colorText: 'rgb(250, 250, 250)', + colorBackground: 'rgb(30, 30, 30)' + }) + }) + }) + ) + }) + describe('checkout journey instrumentation', () => { it('emits payment_element_ready on the ready callback for the live mount', async () => { renderForm() diff --git a/packages/account-ui/src/billing/stripe/StripePaymentForm.vue b/packages/account-ui/src/billing/stripe/StripePaymentForm.vue index bcf629d54c1..69e0ccef168 100644 --- a/packages/account-ui/src/billing/stripe/StripePaymentForm.vue +++ b/packages/account-ui/src/billing/stripe/StripePaymentForm.vue @@ -234,6 +234,9 @@ onMounted(async () => { failElementInit() return } + const themeRoot = paymentElementTarget.value + const resolveThemeColor = (variable: string) => + resolveColorIn(themeRoot, variable) stripeElements.value = stripe.elements({ mode: 'subscription', @@ -257,7 +260,7 @@ onMounted(async () => { // Same token as the pricing table's "Save 20%" pill, so all // deal/discount badges share one accent. colorSuccess: resolveThemeColor('--primary-background'), - fontFamily: getComputedStyle(document.body).fontFamily, + fontFamily: getComputedStyle(themeRoot).fontFamily, borderRadius: '10px', spacingUnit: '5px' }, @@ -363,10 +366,10 @@ async function submit() { } } -function resolveThemeColor(variable: string) { +function resolveColorIn(themeRoot: HTMLElement, variable: string) { const probe = document.createElement('span') probe.style.color = `var(${variable})` - document.body.append(probe) + themeRoot.append(probe) const color = getComputedStyle(probe).color probe.remove() return color From c328d2196ec3eedd425305c3d3d50c1207f6ebc9 Mon Sep 17 00:00:00 2001 From: dante01yoon Date: Thu, 24 Sep 2026 08:03:21 -0400 Subject: [PATCH 2/2] test(account-ui): cover the scoped font lookup for Stripe appearance --- .../account-ui/src/billing/stripe/StripePaymentForm.test.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/account-ui/src/billing/stripe/StripePaymentForm.test.ts b/packages/account-ui/src/billing/stripe/StripePaymentForm.test.ts index af13091ae1a..523331681f6 100644 --- a/packages/account-ui/src/billing/stripe/StripePaymentForm.test.ts +++ b/packages/account-ui/src/billing/stripe/StripePaymentForm.test.ts @@ -169,9 +169,11 @@ describe('StripePaymentForm', () => { it('themes Stripe from the theme scope the form renders in, not the page body', async () => { document.body.style.setProperty('--base-foreground', 'rgb(20, 20, 20)') document.body.style.setProperty('--base-background', 'rgb(255, 255, 255)') + document.body.style.fontFamily = 'serif' const darkScope = document.createElement('div') darkScope.style.setProperty('--base-foreground', 'rgb(250, 250, 250)') darkScope.style.setProperty('--base-background', 'rgb(30, 30, 30)') + darkScope.style.fontFamily = 'Inter' document.body.append(darkScope) onTestFinished(() => { darkScope.remove() @@ -186,7 +188,8 @@ describe('StripePaymentForm', () => { appearance: expect.objectContaining({ variables: expect.objectContaining({ colorText: 'rgb(250, 250, 250)', - colorBackground: 'rgb(30, 30, 30)' + colorBackground: 'rgb(30, 30, 30)', + fontFamily: 'Inter' }) }) })