diff --git a/plugins/collapseGroups.js b/plugins/collapseGroups.js
index 8f999755b..449059d20 100644
--- a/plugins/collapseGroups.js
+++ b/plugins/collapseGroups.js
@@ -1,3 +1,4 @@
+import { computeStyle, collectStylesheet } from '../lib/style.js';
import { inheritableAttrs, elemsGroups } from './_collections.js';
/**
@@ -50,7 +51,9 @@ const hasAnimatedAttr = (node, name) => {
*
* @type {import('./plugins-types.js').Plugin<'collapseGroups'>}
*/
-export const fn = () => {
+export const fn = (root) => {
+ const stylesheet = collectStylesheet(root);
+
return {
element: {
exit: (node, parentNode) => {
@@ -68,11 +71,14 @@ export const fn = () => {
node.children.length === 1
) {
const firstChild = node.children[0];
+ const nodeHasFilter = !!(
+ node.attributes.filter || computeStyle(stylesheet, node).filter
+ );
// TODO untangle this mess
if (
firstChild.type === 'element' &&
firstChild.attributes.id == null &&
- node.attributes.filter == null &&
+ !nodeHasFilter &&
(node.attributes.class == null ||
firstChild.attributes.class == null) &&
((node.attributes['clip-path'] == null &&
diff --git a/test/plugins/collapseGroups.18.svg.txt b/test/plugins/collapseGroups.18.svg.txt
new file mode 100644
index 000000000..99c3eb60b
--- /dev/null
+++ b/test/plugins/collapseGroups.18.svg.txt
@@ -0,0 +1,45 @@
+Don't collapse groups if outer group has filter (as style or attribute).
+
+===
+
+
+
+@@@
+
+
\ No newline at end of file