Skip to content

Conversation

@jhlggit
Copy link

@jhlggit jhlggit commented Oct 24, 2025

Related issue: #XXXX

Description

In the SVG Loader, there's some code to read styles from embedded style sheets, which are held in a collection called stylesheetStyles. This collection was being indexed into using svgName, but the styles in an embedded style sheet are actually identified by the slightly different jsName so, where these two differed, the styles were not being picked up.

The fix is a one-line change, in which stylesheetStyles[ svgName ] is replaced with stylesheetStyles[ jsName ] (two occurrences).

For example, here is a style node from an SVG file:

<style>.highlightBox { fill: #ffa500; fill-opacity: .2; } .highlightBoxReferent { fill: #9ff3db; fill-opacity: .3; }</style>

Elsewhere in the file, there are elements with this attribute
class="highlightBox"

With the old code, these elements were rendered as fully opaque but, with this fix, they are now rendered with the specified opacity of .2.

The likely reason this wasn't noticed before is that not all styles are affected. In the example above, the fill colour was not affected because, for fill colour, the svgName and the jsName are the same (namely, "fill").

SVG file referenced in this example:
LogicEssence1_TimesNewRomanPSMT_TimesNewRomanPSMT.xml

screenshot with old code:
opaque

screenshot with fixed code:
transparent


if ( node.hasAttribute( svgName ) ) style[ jsName ] = adjustFunction( node.getAttribute( svgName ) );
if ( stylesheetStyles[ svgName ] ) style[ jsName ] = adjustFunction( stylesheetStyles[ svgName ] );
if ( stylesheetStyles[ jsName ] ) style[ jsName ] = adjustFunction( stylesheetStyles[ jsName ] );
Copy link
Collaborator

@Mugen87 Mugen87 Oct 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure this bit is correct. The test SVG style-css-inside-defs.svg in the webgl_loader_svg example now renders incorrectly with this change. The red border becomes too wide.

You can test by comparing Prod with this PR:

https://threejs.org/examples/#webgl_loader_svg
https://rawcdn.githack.com/jhlggit/three.js/StyleSheetNameFixBranch/examples/index.html#webgl_loader_svg

If you open the SVG directly in Chrome or via mac Preview, it renders like in the Prod version.

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 this pull request may close these issues.

2 participants