svgo icon indicating copy to clipboard operation
svgo copied to clipboard

Add chainFilters plugin

Open strarsis opened this issue 8 years ago • 10 comments

This PR adds the chainFilters plugin which chains filter elements using CSS filters as workaround for some issues with specific browsers, closes https://github.com/svg/svgo/issues/732. Furthermore a DOM walker is added which can be used for traversing the svgo DOM (by full mode plugins). Currently some plugins and svgo core all use their own custom "monkeys" implementations for this.

If a filter is already assigned to an element using styles and the plugin also got a filter attribute to the same filter element, this plugin would still create a chain - this may be a feature to add - but this kind of corner case should be very rare, also the element shouldn't have a filter assigned by filter attribute and styles in the first place. Also this plugin currently always assumes relative paths in fragment identifiers.

strarsis avatar Jun 02 '17 14:06 strarsis

@drschwabe: You can already test this plugin using:

# using npm:
$ npm install github:strarsis/svgo#chain-filters

# using yarn
$ yarn add github:strarsis/svgo#chain-filters

strarsis avatar Jun 02 '17 14:06 strarsis

@GreLI: The filter bug is indeed a problem in Firefox - maybe this plugin should be enabled by default? Currently the filter element is chained with the element using a CSS class with filter property via IRI. Would it be better to convert the whole filter element into CSS? - Would this be always possible?

strarsis avatar Jun 03 '17 18:06 strarsis

@GreLI: What can I do for further speeding up the review/merge process?

strarsis avatar Nov 08 '17 02:11 strarsis

I haven't made a decision yet. Not sure about the plugin. Need some time to consider.

GreLI avatar Nov 08 '17 19:11 GreLI

@GreLI, @caub: Arguments against merging this plugin into svgo:

  • It doesn't minify or simplify, rather it is a polyfill for a Firefox issue.
  • (When a plugin-as-package architecture has been implemented in svgo) This could also fit in a separate package.
  • I am biased because I made the plugin.

Arguments for merging this plugin into svgo:

  • This Firefox bug can be subtle and puzzling when suddenly some parts of the SVG are missing when viewed in Firefox. Just having this extra step will ensure this problem doesn't happen again for all SVGs processed by svgo.
  • One doesn't necessarily finds this bug when searching for it (I encountered this bug in a svgo issue created by another user and found the exact same symptoms).
  • This plugin can always be disabled or even removed when Firefox has this bug finally fixed.

strarsis avatar Nov 19 '17 15:11 strarsis

@TrySound: Does it make sense to add this plugin to svgo? Loading plugins from other packages (installed from npm) isn't supported yet by svgo.

strarsis avatar Feb 25 '21 11:02 strarsis

@strarsis It is supported. Just require the plugin and pass to plugins array.

TrySound avatar Feb 25 '21 11:02 TrySound

@TrySound: So should this plugin now be merged into svgo repository or rather provided as standalone plugin (e.g. via npm)?

strarsis avatar Mar 19 '21 13:03 strarsis

This looks more like polyfill than optimisation. So yes, this would probably look better as separate package.

TrySound avatar Mar 19 '21 17:03 TrySound

See

TrySound avatar Dec 07 '21 09:12 TrySound

@TrySound: Thanks for the adjustment. I had not looked at this PR for some while.

When I try this test SVG in Chrome and Firefox (both, regular and Developer Edition), the SVG is displayed correctly and equally: https://gist.githubusercontent.com/strarsis/2c769b63b9573b9cf81faa9242adf4ec/raw/1571560b8ca1c895a52fb3669a4ad32615350993/chainfilters-test.svg So does this mean that this issue had been eventually fixed in Firefox?

strarsis avatar Sep 23 '23 21:09 strarsis

Hey! Thanks for creating the PR.

So does this mean that this issue had been eventually fixed in Firefox?

Indeed, it looks like the issue has already been resolved. Makes sense given the amount of time that's passed. ^-^'

SethFalco avatar Dec 09 '23 22:12 SethFalco