Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JS error from CMB2 TinyMCE #1482

Open
gyrus opened this issue Jan 4, 2023 · 2 comments
Open

JS error from CMB2 TinyMCE #1482

gyrus opened this issue Jan 4, 2023 · 2 comments

Comments

@gyrus
Copy link
Contributor

gyrus commented Jan 4, 2023

There's a JS error in WP admin with a site I manage, and I've traced it to the inclusion of WYSIWYG fields via CMB2.

Unfortunately I can't replicate it with a vanilla installation, so it's probably a clash with something in our custom theme. However I've spent a long time trying to track this down without success, so I wondered if anyone might have encountered something similar, or is aware of related issues that might give a clue about how to debug this.

The error is coming from /wp-includes/js/tinymce/themes/modern/theme.js line 2427:

elm.setAttribute(name === 'role' ? name : 'aria-' + name, value);

The error is 'Uncaught TypeError: Cannot read properties of undefined (reading 'setAttribute')'. The var elm here seems to have this opening tag (name = 'role' and value = 'button' - check source context for how vars are derived):

<div id="mceu_50" class="mce-container mce-toolbar mce-stack-layout-item mce-first mce-last" role="toolbar">

The error prevents the whole metabox that the TinyMCE field is in from being rendered, and halts JS execution on the page.

This is with WP 6.1.1 (using multisite to run the client's main site and a subsite together), and CMB2 2.10.1.

I appreciate since this can't be replicated there might not be much you can do, but the issue has started happening recently (the site is a few years old), and I've spent so much time on it I need to move onto other work now and I'm posting on the off-chance it rings a bell for someone.

@tw2113
Copy link
Contributor

tw2113 commented Jan 4, 2023

I assume it's perhaps only happening when you are editing a post that has a CMB2-powered WYSIWYG field? What if you temporarily remove that field type from the config, does the rest just work?

@gyrus
Copy link
Contributor Author

gyrus commented Jan 4, 2023

Yes, it only happens when the page you're editing has a metabox with a WYSIWYG CMB2 field.

Update: I've discovered that the issue doesn't happen on pages where we've disabled Gutenberg (e.g. the home page, where there are only custom fields, no main content space - Gutenberg is disabled selectively using the gutenberg_can_edit_post_type and use_block_editor_for_post_type filters). However, things worked on Gutenberg screens for the vanilla installation testing. But, we have a gutenberg.php functions file in our custom theme, and I tried copying everything in there across to the vanilla installation functions file, and everything still worked. I'll keep you posted if I find anything else.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants