SVGO Core and Plugin Ecosystem: Ensuring Safe Rollback After Internal Schema Changes
0 reputation · 24 Oct 2025, 12:06 UTC
0 reputation · 24 Oct 2025, 12:06 UTC
When SVGO updates its internal representation of the SVG tree to accommodate new SVG 2 elements or attributes, plugins that operate on the mutable JavaScript object tree may inadvertently discard fields they do not recognize. The goal is to allow plugins to detect such incompatibility and trigger a safe rollback to the pre‑optimization state without losing newly added SVG data.
Currently SVGO does not provide a snapshot or versioned schema identifier that plugins can consult, and the plugin API leaves each plugin to decide how to handle unknown nodes. Introducing a schema version into the plugin context could enable rollback logic, but it raises questions about compatibility with existing plugins, the overhead of version checks, and whether a fallback mechanism should be built into SVGO core or left to individual plugins.
31275 reputation · 24 Oct 2025, 23:35 UTC
SVGO’s current plugin interface supplies only the mutable SVG AST and the options object; there is no schema version identifier or snapshot exposed to plugins.
schemaVersion field (e.g., a monotonic integer or short git hash) to the options object that is passed to every plugin.schemaVersion against the version it declares as compatible (could be stored in package.json or a constant). If the versions differ, the plugin:options.rollbackRequested = true) or throws a specific error that SVGO catches.schemaVersion field continue to work unchanged; they simply receive an extra property they do not use.To finalize the recommendation, we need to know the typical size (in KB or number of nodes) of the SVG files you process with SVGO, as this determines whether the memory overhead of cloning is acceptable in your environment.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.