10up / safe-svg

Enable SVG uploads and sanitize them to stop XML/SVG vulnerabilities in your WordPress website.
https://wordpress.org/plugins/safe-svg/
GNU General Public License v2.0
263 stars 31 forks source link

Uncaught TypeError: Cannot read properties of undefined (reading 'isSavingPost') #182

Closed turtlepod closed 5 months ago

turtlepod commented 5 months ago

Describe the bug

JS fatal error. Uncaught TypeError: Cannot read properties of undefined (reading 'isSavingPost')

Steps to Reproduce

Enable Safe SVG in Classic Editor Edit Post

Screenshots, screen recording, code snippet

image

Environment information

WPEngine

WordPress information

WordPress 6.4.x

Code of Conduct

turtlepod commented 5 months ago

@dkotter I think it's because of this line of code: https://github.com/10up/safe-svg/blob/f8f90d483a9ed83c8c322ee31c40ea54cec4395b/includes/optimizer.php#L43

The JS need gutenberg, so, technically, this need to be updated from admin_enqueue_scripts to enqueue_block_editor_assets ?

dkotter commented 5 months ago

@turtlepod That makes sense to me but I've been unable to reproduce this.

That JS file is only loaded if the optimizer feature is enabled (do this by returning true in the safe_svg_optimizer_enabled filter). I've set this up and I see the file loading but I'm not getting any errors in the console when testing in the Classic Editor. Are there other steps I need to take?

dkotter commented 5 months ago

And I guess one other thing in thinking through this more, I believe this was set up to fire not only in the editor but when media is directly uploaded, so I think loading the script on enqueue_block_editor_assets would break that functionality

turtlepod commented 5 months ago

@dkotter I tested and I can reproduce. Yes, this issue is only if we use the safe_svg_optimizer_enabled filter. Apparently the issue is probably a conflict with Yoast SEO. Can you confirm this and simply enable Yoast to check? Thanks

dkotter commented 5 months ago

@turtlepod Thanks for the additional information. I had originally tested with Yoast but couldn't reproduce the issue. Turns out I had another plugin installed that was loading the proper dependencies which fixed the issue. I've opened #187 to address this, if you have time to test that and ensure it fixes things for you.

turtlepod commented 5 months ago

@dkotter I tested and the fix is working as expected! Thank you!