As reported on WordPress.org, if svg optimization is turned on (which is a feature added in #79), there's a scenario where saving content doesn't work.
In testing myself, I was able to reproduce and discover the problem. A javascript console error ends up being thrown (n.blocks is not iterable) which causes any other javascript to no longer execute (like the save action).
In looking at that code, it seems to listen for the save event and then it tries iterating through all the block content to find any svgs that need optimization. The problem here is if no block changes happened, this causes an error because we try iterating on an element that doesn't actually exist.
There may be a better fix for this but at the very least, we need to ensure the changes.blocks attribute exists before we try iterating over it.
Describe the bug
As reported on WordPress.org, if svg optimization is turned on (which is a feature added in #79), there's a scenario where saving content doesn't work.
In testing myself, I was able to reproduce and discover the problem. A javascript console error ends up being thrown (
n.blocks is not iterable
) which causes any other javascript to no longer execute (like the save action).This error comes from this line: https://github.com/10up/safe-svg/blob/72a69f0f93e7f589f6113facb9db751a18626a8a/assets/js/admin/admin.js#L249
In looking at that code, it seems to listen for the save event and then it tries iterating through all the block content to find any svgs that need optimization. The problem here is if no block changes happened, this causes an error because we try iterating on an element that doesn't actually exist.
There may be a better fix for this but at the very least, we need to ensure the
changes.blocks
attribute exists before we try iterating over it.Steps to Reproduce
Follow the instructions shown in the video here: https://wordpress.org/support/topic/pages-fails-to-update-when-optimizer-enabled/
Screenshots, screen recording, code snippet
No response
Environment information
No response
WordPress information
No response
Code of Conduct