Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

linear-gradient in background is parsed as invalid #148

Open
magom001 opened this issue Jan 24, 2022 · 4 comments · May be fixed by #186
Open

linear-gradient in background is parsed as invalid #148

magom001 opened this issue Jan 24, 2022 · 4 comments · May be fixed by #186

Comments

@magom001
Copy link

magom001 commented Jan 24, 2022

I noticed that when I try to do snapshot testing on my react components with inline styles, background: linear-gradient(...) is missing from the snapshot.

I described the issue in details on stackoverflow: https://stackoverflow.com/questions/70832768/jest-tomatchsnapshot-removes-inline-styles

I then tracked the issue to this:

In shorthandSetter the shorthandParser returns undefined because parseColor does know how to handle linear-gradient.

@magom001
Copy link
Author

Changing this from return undefined to return val fixes the issue.

@subrato-pattanaik
Copy link

Nice find! It seems jsdom doesn't handle the logic for any gradient function (linear-gradient, radial-gradient, conic-gradient, and its repeating variant).

@spolarRASP
Copy link

Hi, does someone work on this issue?

@asamuzaK
Copy link
Contributor

asamuzaK commented Feb 11, 2025

Some notes.

  • gradients are not <color>, they are <image>.
    https://drafts.csswg.org/css-images-4/#image-values
    So, it's not a bug that parseColor doesn't handle gradients.

  • cssstyle supports background-image, but it is not following the spec enough.
    https://developer.mozilla.org/en-US/docs/Web/CSS/background-image#formal_syntax

    background-image =
      <bg-image>#
    
    <bg-image> =
      <image> |
      none
    
    <image> =
      <url> |
      <gradient>
    
    <url> =
      <url()> |
      <src()>
    
    <url()> =
      url( <string> <url-modifier>* )  |
      <url-token>
    
    <src()> =
      src( <string> <url-modifier>* )
    

    But IIRC https://github.com/jsdom/cssstyle/blob/main/lib/properties/backgroundColor.js, cssstyle only supports kinda

    background-image =
      <bg-image>	// no multiple images
    
    <bg-image> =
      <image>	// does not support `none`
    
    <image> =
      <url>	// no <gradient>
    
    <url> =
      <url()>	// src() is not supported. However, none of the browsers currently support src()
    
  • Along with background-image, we should add below (although they should be treated as separate issues)

    • border-image-source and it's shorthand border-image
    • list-style-image and it's shorthand list-style

@asamuzaK asamuzaK linked a pull request Feb 15, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants