#ludvig-paymentelement-appearance
1 messages ยท Page 1 of 1 (latest)
I noticed something strange.
If I hard refresh when my page theme is set to light, and I then change the theme to dark, the <PaymentElement> appearance works as expected when switching themes.
If I hard refresh when my page theme is set to dark, the background of <PaymentElement> is consistently white, both initially and when I switch themes, except for the buttons/inputs which work as they should.
What do you think it could be?
I'm guessing it's some hydration mismatch or similar on my side, I'll scan my code to see if there is something I've done bad.
I'll post a reproduction if I can't figure it out
yeah I'm not sure we've seen people do this switch often but if you have a repro we can narrow it down!
Here is a repro I made to show the issue I'm having, I hope the repro is good enough.
When you enter the codesandbox, fill out the .env file with your env variables.
If you are forking the codesandbox, it will not have the same url anymore I believe, therefore;
Change the url to your own url that is inside the fetch request to the api/serverless function, otherwise you're sending a fetch request to my codesandbox.
After that, disregard the yarn terminal window and open a new terminal and run npm run dev
https://codesandbox.io/s/nifty-moon-33706?file=/.env
Open up the other window which uses port 3001 instead.
Again - Try updating the website when on dark mode, then switch themes.
Then try updating the website when on light mode, then switch themes.
See that it doesn't behave as it should with the iframe background when loading the UI on dark mode, but it does when loading it on light mode?
Thanks for sharing the reproduction. I'll take a look soon
Thanks a lot!
@wild current I don't want to be a pain but do you have an easier repro? ๐
I never use codesandbox and it's painful to work with when you can just hardcode one client_secret in the client to render UPE right?
we really should only need a simple client-side code to render exactly what you see
I can't really play with your exmaple, it requires an account which in turn requires a login with my google or github account which I'd never do
yeah 2 other people on my team looked and we're a bit stuck. I would usually figure out how to repro but it's React with SCSS too and I'm lost to be honest
Alrighty, I'll see if I can make it even simpler
But is it a problem that it is on codesandbox?
What do you mean with UPE?
what if I get you some login credentials so you can access the repro and play around with it? What is it that you're stuck on exactly?
yes codesandbox is a problem is we need to make any change to view the problem. Just loading it crashes for us and making any modifications requires a codesandbox account which we won't have
UPE == PaymentElement sorry
this is the problem
it just crashes entirely on load and we can't do anything with it.
Well did you try what I wrote initially?
aah well
If I supply you with login credentials will you login to use codesandbox? because then you can fork it
I'd rather avoid this if possible
You should be able to hardcode the publishable key + a client_secret right? You don't need any backend or custom thing
Hmm that's actually true
But I want to use next.js because the theme package i'm using is specifically for nextjs I believe
therefore I chose to set it up the way I have it myself
just in case that's the problem
yeah that's fair. Though I have never touched Next.js at all
which I strongly dislike :p
it's just to render out static sites easily
I was really hoping you'd make the simplest vanilla JS repro to demonstrate a bug in PaymentElement itself
but maybe the bug does only happen with your exact setup
But step 1: if you can make it so that it just renders on codesandbox, we can look at the result and the styles applied to understand the issue
of course, thanks for yours, I know it can take a while to reproduce those things outside of your own environment ๐ฆ
I have someone on my team who is a wizard at CSS debugging so I'm hoping that once I get a real live repro we can pair and they'll know what's up
Yeah ๐ Is there no react guy on your team as well?
Since there is @stripe/react-stripe-js which I'm using
there are a few but it's unlikely to be a React issue, since it's a wrapper over the normal element
Okay. I'm not able to deal with this straight away (maybe in an hour), but I'll write here as soon as I have done something. At what hours are you available to help here, will I have to wait the whole weekend?
my team is here until ~5pm PST roughly and then back on Monday (we don't staff week ends)
It seems as if I can't hardcode a client secret?
The above error occurred in the <PaymentElement> component:
at ClientElement (webpack-internal:///./node_modules/@stripe/react-stripe-js/dist/react-stripe.umd.js:506:20)
at div
at fieldset
at form
at div
at div
at eval (webpack-internal:///./node_modules/react-bootstrap/esm/Col.js:65:8)
at StripePaymentElement (webpack-internal:///./pages/index.js:371:84)
at Elements (webpack-internal:///./node_modules/@stripe/react-stripe-js/dist/react-stripe.umd.js:349:29)
at div
at div
at eval (webpack-internal:///./node_modules/react-bootstrap/esm/Col.js:65:8)
at div
at eval (webpack-internal:///./node_modules/react-bootstrap/esm/Row.js:15:3)
at div
at eval (webpack-internal:///./node_modules/react-bootstrap/esm/Container.js:17:3)
at HomePage (webpack-internal:///./pages/index.js:57:62)
at h (webpack-internal:///./node_modules/next-themes/dist/index.modern.js:10:217)
at MyApp (webpack-internal:///./pages/_app.js:42:27)
at StyleRegistry (webpack-internal:///./node_modules/styled-jsx/dist/stylesheet-registry.js:231:34)
at ErrorBoundary (webpack-internal:///./node_modules/@next/react-dev-overlay/lib/internal/ErrorBoundary.js:26:47)
at ReactDevOverlay (webpack-internal:///./node_modules/@next/react-dev-overlay/lib/internal/ReactDevOverlay.js:90:23)
at Container (webpack-internal:///./node_modules/next/dist/client/index.js:331:9)
at AppContainer (webpack-internal:///./node_modules/next/dist/client/index.js:770:26)
at Root (webpack-internal:///./node_modules/next/dist/client/index.js:891:27)
React will try to recreate this component tree from scratch using the error boundary you provided, ErrorBoundary.
Hey @wild current just wanted to follow up on this
I work with @unreal cove
I tried to reproduce the same behavior on my end and it seems like the issue maybe with how you're wrapping the payment element component because it by default doesnโt have a white background.
my config for the element
wrapping the payment element as in a js/react issue or a css/scss issue?
<form onSubmit={handleSubmit}>
<fieldset>
<div className="FormRow">
<PaymentElement
onChange={(e) => {
if (e.error) {
setPayment({ status: "error" });
setErrorMessage(
e.error.message ?? "An unknown error occurred"
);
}
}}
/>
</div>
</fieldset>
<Button
className="d-flex mx-auto my-3"
type="submit"
disabled={
!["initial", "succeeded", "error"].includes(payment.status) ||
!stripe
}
>
Pay {formatAmountForDisplay(50, "eur")}
</Button>
</form>
It is definitely a CSS one if you're able to make test payments
This is my scss..
// Dark-theme
[data-theme="dark"] {
body {
color: white;
background: #0b1524;
}
}
// Light-theme
[data-theme="light"] {
body {
background: white;
}
}
// Theme-independent
body {
.bg-gray {
background: rgba(160, 160, 160, 0.4);
}
}
I'd start by changing background-color for <div className="FormRow"> and see if it triggers any change and move upwards from there
Well it does work, but the issue persists, when loading dark mode it is still an issue as it uses white
Is there an easy way for me to stream this or show this in video for you?
or maybe a gif or similar
sure feel free to attach a video/gif or something
also if you can show me your element hierarchy using inspect element, that'd help as well
I don't have discord nitro so my limit is 8mb per file
i'm trying to find a good tool for this job
I'll try gyazo
Alright the gifs are rather short but let's see if you understand. This is when you refresh/load the page when light mode has been selected. This is how it should always work, this is how I want it to work.
https://gyazo.com/75d975a54154aa048b4f015578a7eccb
This is how it looks like when you refresh/load the page when dark mode has been selected. This is where you see the issue. During dark mode, it's also white.
https://gyazo.com/bb42dc0c9c7ace4ad228d212d900623d
Here I have bootstrap enabled, but I have tried without it (really minimal css applied, the one I showed you), and it still works the same way
I can continue simplifying the repro so you can try for yourself, but as I said it seems that I can't hardcode a client secret?
I see what you mean. Yeah It is as I suspected earlier.
Your PaymentElement is deeply nested into few other elements and one of them is not transparent.
Well I thought so too
But in dev tools I have tried every layer
to change the appearance
and it works as expected in light mode
but not in dark mode
I want to give you a repro where you can dig around yourself
but again, I can't hardcode a client secret?
I get an error
I tried to console.log one and reuse it
but the paymentelement wont render
it works in light mode because that white matches the white background!
if you change light mode color to grey, you may see the same behavior there
Nope
I'll show you
I'll set light mode to have the background color pink
or maybe green is even clearer
wait I'll do a new gif
sure
make sure to hard refresh the page to get rid of caching (cmd + shift + R in Mac)
ctrl + shift + r in windows
ah I see.
I'm assuming you're changing class names for the containers on button click?
Yup, even have hard refreshing it's like that
is this link to your code the latest one? https://codesandbox.io/s/nifty-moon-33706?file=/pages/_app.js
Yes
But you need to edit the .env and provide public/secret key
And if you fork it, you'll have to edit the fetch links
to match your new url
I believe I'm not changing the classNames on button click
It's done by the next-theme package i'm using
I believe it changes something in the <html>
wait I'll double check
one thing I observed is that when you switch themes, it also makes the label floating
I'm not sure if that's an intended behavior
ah okay cool
const appearance = {
theme: `${resolvedTheme === "dark" ? "night" : "stripe"}`,
labels: `${resolvedTheme === "dark" ? "floating" : ""}`,
variables: {},
rules: {}
};
If you check the gyazo I just sent you'll see the only thing that happens on theme switch afaik
And this is the scss for it:
// Dark-theme
[data-theme="dark"] {
body {
color: white;
background: #0b1524;
}
}
// Light-theme
[data-theme="light"] {
body {
background: green;
}
}
Are you able to try out the repro I sent? Can I provide anything else for you?
I know that color: white should only affect the text but do you wanna take it out and see if that changes anything?
Sure thing
I did a hard refresh (ctrl+shift+r) prior to this screenshot, after I had commented out the color: white rule
As you see, only the text changes
The exact problem persists
hmm. looking at your code the only other thing that I can think of is either the theme-switcher OR bootstrap may have prebuilt classes / styling with white background.
Yeah, I've tried not including bootstrap in my css
or it could also be a border
I can show you that too
There is without bootstrap, which means it's only this css applied:
// Dark-theme
[data-theme="dark"] {
body {
// color: white;
background: #0b1524;
}
}
// Light-theme
[data-theme="light"] {
body {
background: green;
}
}
// Theme-independent
body {
.bg-gray {
background: rgba(160, 160, 160, 0.4);
}
}
the bg-gray could be deleted too, it doesn't do anything
it's for some area below this
okay lets try elimination theory
your component is nested under these parents
<div className="page-container">
<form onSubmit={handleSubmit}>
<fieldset className="">
<div className="FormRow" ```
I'll delete them
I'm gonna have to use react fragments, I'm guessing this is fine?
<> </>
it's like an empty div except it's not a div
I literally deleted everything except the paymentelement
return <PaymentElement />;
Still the same
I'll continue making the repro smaller for you
alright. wondering why is it working for me and not for you ๐ค must be something minor we're not paying attention to
I've got it down to this:
return (
<div>
<h1>Checkout</h1>
<p>Powered by Stripe</p>
<hr />
<Button onClick={() => setTheme("dark")}>Dark mode</Button>
<Button onClick={() => setTheme("light")}>Light mode</Button>
<hr />
{clientSecret && (
<Elements options={options} stripe={stripePromise}>
<PaymentElement />
</Elements>
)}
</div>
);
So is there some way I can hardcode a client secret? I'll give up my public test key to use
I'm guessing I shouldn't provide my secret test key? Although I could do that too
The thing is I don't think it is needed as functionality wise the element is working fine. Just having issues cosmetically
Well I want to provide you with a repro
But then you'd have to download/install the projects dependancies right? that's why a codesandbox is nice because it's already made for you
But I can provide a git repo for you
git repo is fine thanks
Alright, I'll put one together for you
I wanna keep it as bare-bone as possible
I'll try my best
all good! ๐
Are you fine with me doing this to initialize my project
npx create-next-app stripe-repro-payment-element --use-npm
as I'm using next.js?
it's still all react
Or do you want the repro in another way?
Awesome
npm install stripe @stripe/stripe-js @stripe/react-stripe-js next-themes
So 4 packages installed
cool
just to make sure you may not need stripe in npm install stripe npm install --save @stripe/react-stripe-js @stripe/stripe-js
Alright, so I'll do exactly that which you sent me instead
npx create-next-app stripe-repro-payment-element --use-npm
npm install --save @stripe/react-stripe-js @stripe/stripe-js
npm install next-themes
https://github.com/pacocoursey/next-themes
Again, how can I give a hardcoded client secret? If there is no other way, I will need to use the stripe package to build the api/node server to where I send a request for the client secret
Don't worry about that as I have one built on my end.
Really?
ThemeProvider wrapper puts the white background
yup
if you try switching the colors without next-theme it works
How should I switch colors without it?
Is there any way to use it and still have it work?
Is there something I can write as an issue to https://github.com/pacocoursey/next-themes ?
taking a look to see if there's anything we can do
this is with ThemeProvider
this is without it
Hmm...
Well how do you create and switch between two themes without it?
And what might be the underlying issue causing this? Can we speak to the owners of the package on github issues to try and solve this? Or is there something I can do?
it is possible that they have some classes that are using the same name as PaymentElement child elements.
What do you suggest that I do? I kinda want this package as I believe it's great otherwise
Okay so seems like the classes that are being overridden are p-PaymentElement-container, p-p-HeightObserver and probably at some point p-PaymentElement is-animatable
that's weird, why would they get overridden?
Should I send them my repro and ask them if they know what's going on?
Did you try out my very minimal repro? I made a few new commits
to make it even smaller
Have you tried using your app in a diff browser?
i'll try edge
It's not working
Are you doing it the right way to get the issue?
select dark mode, then refresh the page
it will work as it should if you select light mode and then refresh the page
safari vs firefox vs chrome
edge is built on chromium
so it may show you similar bugs
Hmm
That is weird
and you did like this?
https://gyazo.com/a97b8160cfa0a48c7240a1fb8bc7e0d5
yup
Interesting
Very interesting
Just putting this one out here as well
Updating when light mode is selected makes it work as it should
So what can we say about this to the chromium developers then?
If it works on safari
possible that some built in styling parameters are causing this.
I'd highly recommend testing it in a diff browser & if you can host the app somewhere other than codesandbox, I can forward the link to one of my colleagues and they can take a look at it
Thanks a lot for your help! I'll have a go at this tomorrow. When does this thread auto-close, thinking if I should bump it in intervalls just so I can keep posting here while you're off during weekend?
hey @wild current we don't actively monitor discord during weekend. But feel free to create a new thread whenever you wanna follow up. Thanks!
I'm going to archive this thread for now ๐ have a good weekend
Just to follow up on this, We confirmed that it is indeed a chrome/chromium bug. So there's very little we can do on our end. However, I will still pass on this information to our team that handles Web Payments.