Coder Social home page Coder Social logo

svg-weirdness's Introduction

SVG Weirdness

A repository for documenting bugs and other weird SVG behaviors, inspired by Scott Jehl’s “Device Bugs” repo.

This is not necessarily meant to be a full list of bugs in SVG implementations, but a the very least a list of bugs and other “gotchas” primarily in browsers that are not likely to be upgraded (older WebKit-based browsers on Android, older IE browser versions etc).

All SVG issues are welcome though, as long as they are accompanied by documentation of which browser engines and version numbers they affect.

svg-weirdness's People

Contributors

emilbjorklund avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

looveh sandstedt

svg-weirdness's Issues

Willful Internet Explorer spec violations

While IE9+ don't have perfect SVG implementations, Microsoft was kind enough to state explicitly what feature omissions were intentional and not a result of bugs.

The list, for those who don't want to click through:

  • xml:space is not supported.
  • A value of 0 on the viewBox height or width does not disable rendering of the element.
  • IE9 does not support SVG filters.
  • The normalizedPathSegList and pathLength DOM interface attributes are not supported.
  • <tref> is not supported.
  • The glyph-orientation-horizontal and glyph-orientation-vertical attributes are not supported.
  • The dominant-baseline, alignment-baseline, and baseline-shift attributes are not supported.
  • The kerning attribute is not supported.
  • <altGlyph> is not supported.
  • Properties of <marker> inherit at the point of reference, not from its ancestors.
  • color-interpolation and color-interpolation-filters are not supported.
  • color-rendering, text-rendering, and image-rendering are not supported.
  • The display property affects <pattern>s and references to those pattern elements.
  • The clip CSS property is not supported.
  • <clipPath> allows indirect references. Indirect references are not an error.
  • zoomAndPan is ignored.
  • <cursor> is not supported.
  • Parameters for viewBox elements in fragment specifications may be delimited by single spaces in addition to commas.
  • externalResourcesRequired is not supported.
  • SMIL is only supported enough to make its animVal attributes always reflect baseVal.
  • <foreignObject> is not supported.
  • The title attribute supports the click event even though it should not be supported.
  • The currentView IDL attribute is not supported.

I think this means the inline SVG overflow bug was actually a bug. (You know, the svg:not(:root) {overflow: hidden} one.)

Firefox reader view strips styles from inline SVG

While testing issue #36 in other browsers, I found that Firefox’s reader view will display inline SVG, but it strips any CSS styling from them. Given the purpose behind “reader views,” that may make sense for typographical elements, but for SVG images, it can lead to colors or other features being removed.

IE miscalculates aspect ratio of SVG background images, unless width and height are set.

Background SVG images in IE get very weird dimensions sometimes, unless the width and height attributes are set on the <svg> element in the source graphic (and match the aspect ratio).

Fix: set width and height (as well as viewBox) on all your SVG background images, and you’re done. It doesn’t matter which measurements you use, as long as they match the aspect ratio of the graphic: if they’re there, you can always resize the background in CSS.

If width and height are missing, a few different scenarios seem to occur:

  • IE 9-10 will resize the SVG canvas according to the background-size property, but the positioning/sizing of stuff inside the SVG viewport gets squashed in mysterious ways.
  • IE11 is slightly better in that it doesn't squash stuff, just sizes it in unexpected ways.
  • If you set background-size in just one dimension (e.g. background-size: 100% auto), all of the IE:s will pick the aspect ratio for the background from the aspect ratio of the element dimensions. Whoa.

The bug is fixed in MS Edge.

(As a sidenote, I believe a lot of people miss this bug when they first try out SVG backgrounds, because they use square SVG graphics for square elements, e.g. icons)

Writeup on my blog, demos at JSbin

feSpotlight positioning does not work in Safari

I'm using a spotlight effect that seems to only work perfectly in chrome, ok in firefox, but will not position (x,y,z) at all in Safari. (Other browsers not tested)

I've tried different filter and primitive units, and while this makes a difference, Safari still cannot seem to position the lighting effect in any case.

In pursuit of understanding what is going on, I've tried lots of workarounds (including #22/#27), different userSpaceOnUse/objectBoundingBox combos, and different svg structure but have never been able to find one that works on Safari.

Examples

Default filter/primitive units (Safari positions it off-canvas to the right):
https://jsfiddle.net/localnerve/y470d52v/

objectBoundingBox units (easier to see Safari's positioning trouble):
https://jsfiddle.net/localnerve/uyc7o52k/

Pretty weird.

I have pictures on this stackoverflow issue to further demonstrate:
https://stackoverflow.com/questions/44891524/safari-trouble-positioning-svg-fespotlight-filter

Older browsers don't calculate intrinsic dimensions from the viewBox attribute

The viewBox attribute makes can be used instead of explicit width and height to define an SVG element's aspect ratio so that they act just like images do when styled with CSS (height is scaled proportionally when you only declare width, etc.). According to the spec regarding "Intrinsic sizing properties of the viewport of SVG content" (emphasis mine):

If either/both of the ‘width’ and ‘height’ of the outermost svg element are in percentage units (or omitted) (used value is auto), the aspect ratio is calculated from the width and height values of the ‘viewBox’ specified for the current SVG document fragment. If the ‘viewBox’ is not correctly specified, the intrinsic aspect ratio cannot be calculated and is considered unspecified.

Unfortunately, most of the major browsers haven't followed this part of the spec until relatively recently. Chrome 36 introduced support for intrinsic sizing by viewBox in July, 2014; Safari didn't do it until recently, but I haven't been able to hunt down the changelog to see when; Firefox was a late adopter too, but I don't know exactly when they fixed it. iOS and Android browser support should probably be listed separately, too.

Firefox does not like missing leading zeros in animation duration

When doing a SMIL animation, I noticed that it did not work in Firefox when using a dur=".75s".

Doing dur="0.75s"works, however.

Demo here:
Broken: http://jsbin.com/qogefo/2/edit?html,css,output
Fixed: http://jsbin.com/qogefo/3/edit?html,css,output

If I'm reading the SVG spec correctly, the <number> data type allows zero or more digits before the decimal separator, and <time> consists of <number> and a unit, so this appears to be a bug from that perspective. However, the SMIL section of the spec lists a specific and different syntax for time values in animations. Makes me wonder, when else is <time> used in SVG?

Bug report and discussion here.

Firefox may not render svg if xlink:href value has trailing whitespace

When including svgs via <use xlink:href="#someSymbolId"/>, Firefox (v103.0.2 on macOS 12.3.1) seems to be more sensitive to whitespaces in the value of xlink:href. I observed a case where <use xlink:href="#someSymbolId "/> (note the trailing whitespace) would not show the icon. In this case the Firefox devtools simply showed an empty #shadow-root. This did not occur in Chrome (v104.0.5112.79).

Safari can only use symbols above the use in the DOM

In Safari, all SVG symbols must be added to the DOM before the <use /> tag referencing them. All other browsers seem to be fine having the symbols added to the end of the body.

One work around is to modify the symbol content once the page has finished loading. For example adding a loaded class to the SVG will force Safari to re-render the symbol.

Image elements pointing to SVG src might not read correctly in VoiceOver

Not an SVG bug in itself, but rather a browser/a11y bug that pertains to using SVG images.

This markup:

<img src="image.svg" alt="hi">

...will not get read properly in VoiceOver/Safari.
From the excellent post on image accessibility by Scott O'Hara:

Desktop Safari and VoiceOver will announce “hi, group” with no announcement of the element being an “image”. However, what’s more problematic is that iOS Safari and VoiceOver will skip over the element all together, as if it were decorative.

The fix is to add a role="img" attribute to the markup. More from Scott:

Proving an image element with a role="img" will announce the “image” role as intended with macOS Safari, and fix it from being ignored on iOS. You’ll get some automated testing tools throwing warnings for the redundant role, but that’s better than it being incorrectly announced or ignored, in my opinion.

Link to WebKit issue

Safari 9 < 9.1.1 / Mobile Safari 9 < 9.3.2 download external svg sprite file for every <use> xlinks:href instance

This was originally posted by @codecandies on the svg4everybody repo. Copying it to here for posterity.

In this testcase http://phpscripts.zeit.de/svg-use-testcase/ you can see the problem, by loading and examining it with Chrome and a Safari greater 9 (exact version mentioned on the testcase). The problem is also seen in iOs safari, since 9.2 i guess (inspected with Charles proxy).

The problem

For every combination of the code

<svg class="svg-symbol" role="img" aria-labelledby="title">
    <use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="icons.svg#svg-search"></use>
</svg>

the svg file icons.svg is (re-)downloaded by safari/mobile safari browsers. Additionally the file is not cached in the browser or ever served from cache, and the developer tools see this file not as image/svg+xm but as other.

This leads to extreme high content downloads, which, especially on mobile, is not good.

A bug has been logged to webkit: https://bugs.webkit.org/show_bug.cgi?id=156368

@martinwolf has documented the issue in detail here: https://www.youtube.com/watch?v=OAbmDlnq1UE

Screenshots from the network panel from Chrome v50 compared with Safari v9.1:

chrome-version50

safari-version9 1

Fluid SVG Height Trouble

When making SVG fluid, you might find some issues where the height is randomly assigned in Safari on older versions of iOS or IE. You have to set the height to 100% because it’s not readjusting to the viewport width. You can’t use height: auto; because it’s not part of the SVG spec.

Gradients in <use> are invisible if symbol svg is display: none

If you have an SVG with symbols in it that also contain gradients, and you set this SVG to display: none; then anytime you use the symbols with <use>, the gradients will not show up.

SVG Sprite is not hidden and gradient is therefore visible
http://codepen.io/jakobud/pen/jPpboq

SVG Sprite is set to display: none….. gradients do not show up!
http://codepen.io/jakobud/pen/ZGjbde

The work-around:
SVG Sprite is set to display: block, width: 0, height: 0… gradients work again
http://codepen.io/jakobud/pen/KpBdjM

This also occurs if any parent of the symbol SVG is display: none.

Safari filter and html base tag

When using a html <base href="" /> tag svg filter attribute makes element invisible:

example code:

<html>
  <head>
    <base href="test"/> <!-- ######### remove this base tag to make it work ######  -->
  </head>
  <body>
<svg>
  <defs>
    <filter x="0" y="0" width="1" height="1" id="solid">
      <feFlood flood-color="white"/>
      <feComposite in="SourceGraphic"/>
    </filter>
  </defs>
  <path d="m20 20h150v10h-150" stroke="#000" stroke-miterlimit="10"/>
  <text filter="url(#solid)" fill="#c45" x="50" y="30" font-size="50px">tesst</text>
</svg>
  </body>
</html>

Probably related to #22

Fractional offset of inline SVG box shifts pixel grid

Affects: IE 9 to Edge (ex-Spartan), Firefox

While the top-left corner of <svg> bounding box coordinates are rounded, the svg contents are rendered as if there was no rounding.

Demo: https://jsfiddle.net/subzey/8a3wa5nv/1/embedded/result/
Notice how grid becomes blurry when offset is fractional. At the same time the border is rendered sharply all the time.

It's relatively easy to avoid fractional absolute coordinates when setting via JS. But the fractional part may appear if anything in the document flow before the svg element had fractional size, for example, inline-block with text.

Maybe the described behavior is spec compliant, but it's hard to reach pixel-perfect rendering.

IE may render symbols as sticking out of iframe/object/embed etc

Demo of the bug here: http://jsbin.com/soyuka/5

IE (versions 9-11, i.e. all that support SVG) have a bug where SVG content can be rendered as sticking out of an iframe, object or embed element.

I’m not a 100% sure of exactly which conditions trigger the bug, but in the examples, a few things seem to be necessary:

  • A nested symbol element, i.e. a symbol inside of a symbol, being used.
  • A transform applied to that symbol, so that the rendered shape ends up off-canvas.

A few conditions also seem to remedy the behavior:

  • Setting symbol { overflow: visible; } with CSS. Note: visible makes the overflow hidden, which I thought was kind of funny.
  • Using transform on another symbol sometimes seem to correct the rendering. (Uncomment the other markup in the SVG example to see this behavior)

The bug seems somewhat intermittent – sometimes, it renders fine, but on the next reload shows up again.

I initially saw the bug only when the same SVG-file was requested into multiple iframe elements, but not when a single instance was loaded, so I mistakenly thought that there was some form of ”ID collision” going on cross-documents, but that does not seem to be the case.

The bug does not appear in Edge.

Safari 6 doesn't display self-closing <use>-elements.

There was a bug in the WebKit engine for a short while where elements like <use xlink:href="#foo" /> would simply disappear from the page.

Fix: add a closing tag to <use>-elements, e.g. <use xlink:href="#foo"></use>.

This was a short-lived regression that also affected Chrome (20?) but sadly it was released as part of Safari 6.0 (it worked fine in Safari 5.X). It was fixed again in Safari 6.1.

Safari feColorMatrix doesn't work with external a files

This issue was found in Safari 11.1 and Mac OS Sierra 10.2.6

This example shows a red box three times:

  • Box one adds a SVG filter using css to embedd a svg
  • Box two adds a SVG filter using an external svg file with css pointing to file and ID
  • Box three is the default state

When using a file ( filters.svg ) with the ID's of the filters you cannot do this CSS in safari:

.filter {
  filter: url( "filters.svg#deuteranopia" );
}

You have to embed the svg into the HTML and use this in CSS:

.filter {
  filter: url( "#deuteranopia" );
}

IE renders SVG backgrounds as blurry when computed size has fractional pixel values

All SVG-supporting versions of IE seems to have an issue where SVG as background images become slightly blurry when the size computes to fractional pixel values. It seems IE does some kludgy anti-aliasing.

Example: if the background-size (in either axis) is 1.333333em and the font-size is 15px, the background size computes to 19.9999px, and is rendered blurry. If the font size is 16px and the background-size is 1.25em (background-size computes to 20px), the SVG is rendered crisply.

All other browsers I've tested renders the SVG crisply in both cases.

Last I checked, the issue is still present in Edge, but a bug report has been submitted.

Injecting SVG spritesheet via ajax in Internet Explorer 11 displays jagged.

Here is a spritesheet: http://codepen.io/anon/pen/zGJJYZ

Looks fine in all browsers with SVG support.

Here is another codepen ajaxing that same spritesheet into the dom: http://codepen.io/anon/pen/MwqBOg

In IE9 and 10 it looks... okay. It seems slightly off the pixel grid and there seems to be some clipping. In IE11 it looks very aliased - almost as if the svgs are being rendered twice on top of one another - just really strong aliasing.

The issue also happens with the ajax demo at css-tricks: https://css-tricks.com/examples/svg-fallbacks/

Base tag kills your xlink:href, but only in Firefox

Bug or feature?
When using a base tag in your document you might encounter a special behavior in Firefox. It doesn't render the SVG when implemented via a use tag, because it simply can't find the definition. The use tag references the SVG symbol by using a xlink:href="#svg-id". FF prepends the link with the base tag, other major browsers don't. That's kind of tricky when debugging... ;)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.