From 7ad9aee38b90a7b4645cdc68ec90c80edb458084 Mon Sep 17 00:00:00 2001 From: Dante Date: Fri, 25 Sep 2026 04:12:36 +0000 Subject: [PATCH] fix(billing-web): theme Stripe Elements from the checkout's own theme scope (#18686) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary The Stripe Address and Payment Element labels on the billing-web checkout were near-invisible (dark gray on the dark panel), and the input boxes rendered white. Stripe's appearance tokens now come from the checkout's own dark theme scope. ## Changes - **What**: - Why: in dark mode on testbilling.comfy.org, "Full name", "Country or region", "Address" and the country select text were barely readable, and the card inputs sat in a white box. - Root cause: `StripePaymentForm` resolved every appearance color (and `fontFamily`) on a probe appended to `document.body`. billing-web applies `.dark-theme` to a wrapper `div` (`CheckoutView`/`HostedSurface`), not to `body`, so the probe read the light-theme tokens: `colorText` = charcoal-800, `colorBackground` = white. The main app was unaffected because its theme class sits above `body`'s children. - How: resolve the tokens and font inside the payment element's container, so they inherit whichever theme scope the form renders in. The Payment and Address Elements share one `elements()` appearance, so both stay consistent. Light mode resolves the same tokens as before. - Test: a new `StripePaymentForm` case renders the form inside a scoped container whose tokens differ from `body` and asserts Stripe receives the scoped `colorText`/`colorBackground`. It fails on main (it gets the body values) and passes with the fix. ## Review Focus The probe is appended to the payment element's target before Stripe mounts into it, and removed straight away. ## AS IS / TO BE | AS IS | TO BE | | --- | --- | | AS IS | TO BE | Team workspace checkout (`plan=team_per_credit_monthly&team_credit_stop_id=team_700`) against testcloud, card and address filled with Stripe Magic fill. - AS IS: https://testbilling.comfy.org (main build). The Billing address labels and values ("Jenny Rosen", "United States", "354 Oyster Point Blvd", …) are dark gray on the dark panel. - TO BE: this branch on http://localhost:5174. Labels and values read in the checkout's dark-theme text color, on dark inputs. ## Plan position: Milestone 2 payment-test fixes Found in the live M2 run (testcloud → testbilling, Team per-credit checkout). None of these PRs depends on another to merge. Solid arrows gate a milestone step; dotted ones are nice-to-have. | PR | Defect | Dependency | |---|---|---| | [D5 cloud#10518](https://github.com/Comfy-Org/cloud/pull/10518) | test-v2 billing-worker uses the wrong Stripe key; every confirm fails `parameter_missing client_secret` | Blocker on test only (config). Unblocks the live re-run. | | [D4 cloud#10514](https://github.com/Comfy-Org/cloud/pull/10514) | preview-subscribe attaches `payment_method_configuration_id` only when `embedded_checked_enabled` is on | Required before widening `hosted_billing_destination` past the flag cohort. | | [D3 FE #18684](https://github.com/Comfy-Org/ComfyUI_frontend/pull/18684) | billing-web asks for a card on plan changes that need none | Independent. Shares e2e fixtures with #18687. | | [D6 FE #18687](https://github.com/Comfy-Org/ComfyUI_frontend/pull/18687) | failed-payment UI ignores `recovery_action` / `retryable` | Independent. Shares e2e fixtures with #18684. | | **[D8 FE #18686](https://github.com/Comfy-Org/ComfyUI_frontend/pull/18686) (this PR)** | Stripe Element labels invisible in dark theme | Independent (cosmetic). | | [D7 FE #18685](https://github.com/Comfy-Org/ComfyUI_frontend/pull/18685) | billing-web font URL broken (`/fonts/inter-*.woff2`) | Independent (cosmetic). | ```mermaid flowchart LR c10518["D5 cloud#10518
test-v2 Stripe key"] c10514["D4 cloud#10514
always attach pmc id"] f18684["D3 #18684
no card for plan change"] f18687["D6 #18687
recovery_action UI"] f18686["D8 #18686
dark-theme labels"] f18685["D7 #18685
fonts"] RERUN(["M2 live payment re-run
testcloud → testbilling"]) ROLLOUT(["Widen hosted_billing_destination
beyond flag cohort"]) c10518 --> RERUN c10514 --> ROLLOUT f18684 --> ROLLOUT f18687 --> ROLLOUT f18686 -.-> ROLLOUT f18685 -.-> ROLLOUT RERUN --> ROLLOUT f18684 <-. "shared e2e fixtures:
second to merge pulls main" .-> f18687 style f18686 fill:#f9d71c,stroke:#333,stroke-width:3px,color:#000 ``` --- .../billing/stripe/StripePaymentForm.test.ts | 44 ++++++++++++++++++- .../src/billing/stripe/StripePaymentForm.vue | 9 ++-- 2 files changed, 48 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..523331681f6 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,36 @@ 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() + 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)', + fontFamily: 'Inter' + }) + }) + }) + ) + }) + 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 3bcfdd203d6..b32187f4379 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