-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
[Bug]: Cannot read properties of undefined (reading 'trim')
in loadSVGFromString
with @media
in CSS
#9679
Comments
Cannot read properties of undefined (reading 'trim')
when parsing SVG with @media
Cannot read properties of undefined (reading 'trim')
when parsing SVG with @media
in CSS
Cannot read properties of undefined (reading 'trim')
when parsing SVG with @media
in CSSCannot read properties of undefined (reading 'trim')
in loadSVGFromString
with @media
in CSS
Upgrade fabric to latest v6 beta. It works for our use case, even thought it does not fix the upstream issue fabricjs/fabric.js#9679 that #29326 relates to.
I can confirm and reproduce |
Yeah, removal should be possible in this case. We convert SVG to PNG via fabric and a |
agreed |
Upgrade fabric to latest v6 beta. It works for our use case, even thought it does not fix the upstream issue fabricjs/fabric.js#9679 that go-gitea/gitea#29326 relates to. (cherry picked from commit c4b0cb4d0d527793296cf801e611f77666f86551) Conflicts: public/assets/img/favicon.svg public/assets/img/logo.svg
Do SVGs as graphic format support media queries? Or is a browser specific support? |
we recently added a fix for fontface declaration that has a very similar sintax, maybe you can leverage that |
Good question. In this i read:
The |
I mean but if you open it in inkscape, what are you going to see? the dark or light version? |
yes inkscape has a pure svg parsers. I m sure for now we can't really support mediaqueries and if we do we won't be able anyway to do into node. So for now we can just fix to avoid crashing. |
On the web, this technique is somewhat common to say the least, as popularized by blog posts such as this one. I guess fabric could expose a API to set dark/light mode. But as for this issue, I'd be happy if it wouldn't crash and produce the light mode output, e.g. ignoring the media query. |
that pr/commit that i linked, is that clear to you? you can try to PR based on that code, knowing the are you have to look around is in that few lines. |
Yes, I can try it. Sounds like you are not using a AST parser? I think you should, like postcss for example. |
we don't have dependencies by choice for now |
is also unrealistic to hope to implement all the SVG features, there are so many and some are so complicated. |
AST parsers are reasonably lightweight and they can run in bother node and browser. I think you could definitely share the parser between all environments. postcss' primary use case is as a CSS transformation tool, but I don't see why it couldn't be used as a parser only. There is also https://bundlephobia.com/package/postcss@8.4.35 |
i understand 49Kb is not much, but whole fabric is 300k. is a sixth of fabric i would add to save on 3 dumb loops i do. |
I guess it's okay for fabric's use case to not support the latest and greatest CSS features. Usage of CSS in SVG is rare, but this media query example is something that will be encountered sometimes as it's a nice way to create a portable dark-mode compatible SVG. |
CheckList
Version
6.0.0-beta19
In What environments are you experiencing the problem?
Node.js
Node Version (if applicable)
21.6.1
Link To Reproduction
See simple node script below
Steps To Reproduce
Expected Behavior
No error.
Actual Behavior
Script errors. Observations:
@media
line makes it work.6.0.0-beta19
and5.3.0
.Error Message & Stack Trace
The text was updated successfully, but these errors were encountered: