Dynamic styles when using CSP #1709
Unanswered
outofthisworld
asked this question in
Q&A
Replies: 1 comment 3 replies
-
Panda works by static extraction. Also your particular usecase; where you're defining those dynamic variables does not require panda or any css framework. You can consume the variables in panda, but defining them doesn't require it. |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I was wondering if there is a better way to pass dynamic variables to styled jsx components rather than using the style attribute.
I had a component before introducing CSP which looked something like this:
<StyledSnowfallSnow key={i} style={{'--data-delay': Math.random(), '--data-left': Math.random()}}/>
Then I introduced
Content Security Policy (CSP)
, which does not like inline styles like this.I tried
<StyledComponent className={css({'-data-dynamic-var':Math.random()}}}/>
however, although it generates the class name on the component the css variable does not get output in the generated css (Next13 new app dir). I'm not sure why this is, as it would seem like this should be possible?Finally, I resorted to a solution to allow styles to work with CSP, however its not pretty and requires extra elements in the generated html.. increasing the file size quite a bit
Also, I noticed that even using
style={{'--dynamic-var':1}}
the linter/compiler complains that this style attribute doesn't exist. How can I fix that?Thanks!
Beta Was this translation helpful? Give feedback.
All reactions