Problem/Motivation
When having the title and description SEO fields being editable ("Enable title editing" and "Enable description editing"),
the joast_seo.js gives me an error:
Uncaught TypeError: snippetTitle.attr is not a function
and
An error occurred during the execution of the Ajax response: TypeError: snippetMeta.attr is not a function
This seems to be caused by lines 360 and 409 of the yoast_seo.js, because the element is not wrapped in a jQuery object around it, being the .attr function a jQuery function indeed.
And i also noticed: when i go editing a node, having the setting "Enable auto refresh of the Real Time SEO widget result" disabled i always get the field in the form saying "Bad", even if the form loads with a high score.
To my eye seems the scheduleUpdate function keeps calling itself, but never actually gets to do any update to the form, because my setting makes it so that the refreshData function at line 240 will always get a false:
if (
!jQuery('.ajax-progress').length &&
this.config.auto_refresh_seo_result
) {
// Click the refresh data button to perform a Drupal AJAX submit.
this.$form.find('.yoast-seo-preview-submit-button').mousedown();
}
else {
this.scheduleUpdate();
}
At page load, though, we want to force an update with real data from the node.
Steps to reproduce
Edit a content type allowing title and or description to be edited
Proposed resolution
- Wrapping the elements in a jQuery call, or (maybe better) using a pure javascript way for handling those attributes.
- Adding a forceRefresh parameter to the function so that at load we can trigger a real update
Remaining tasks
User interface changes
API changes
Data model changes
| Comment | File | Size | Author |
|---|---|---|---|
| #12 | Peek 2025-10-27 22-25.gif | 809.75 KB | kburakozdemir |
| #7 | 3537343-MR-43_fix-javascript-error.patch | 1.83 KB | altcom_neil |
Issue fork yoast_seo-3537343
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
joey-santiago commentedConfirm this happens also on a simplytest me test site, so this doesn't look like is caused by our install.
Comment #5
freezernick commented+1 RTBC for #4
Comment #6
joey-santiago commentedAdded another fix to the JS.
At page load, now we can force an update of the widget to show the correct value for the node being edited.
Comment #7
altcom_neil commentedWe have just updated to Drupal 10.5.1 and yoast_seo 2.2.0 and ran into this javascript error.
Using the diff of the changes fixes the error for us. Attached here as a patch so it can be installed as a composer patch.
+1 RTBC
Comment #8
dewancodes commentedWhen I upgraded existing drupal 10 site to Drupal 11.2, I see there is error on the console:
VM155:1145 An error occurred during the execution of the Ajax response: TypeError: snippetTitle.attr is not a function
I applied patch from @altcom_neil and after 'drush cr' it fixed the issue for me.
Comment #9
akhtardahaI face the same error after upgrade to drupal 10.5.2 and the patch from #7 fixed the issue.
Comment #10
alexius commentedYes, patch #7 is working
Comment #11
gedur commentedPatch working on Drupal 11.2, thanks!
Comment #12
kburakozdemir commentedI use Drupal 10.5.4 and patch #7 is working. thanks a lot.
I am not sure if the following is related with this issue but you can see a gif below. on the right side, 8.x-1.9 version and on the left 8.x-2.2 version (patch #7 is applied).
on the left (new version of module) does not edit the url alias inline., although "seo title" and "meta description" work.
please right click and open the image in a new tab to see it clearly...
Comment #13
anruetherThank you! This fixed the JS error when I click on "Seo preview":
An error occurred during the execution of the Ajax response: TypeError: snippetMeta.attr is not a functiondrupal 11.3.3, yoast_seo 2.2
Comment #14
anruetherNope, this leads to #3578388: Edit form jumps to YoastSeo field
Comment #15
anruetherFor me the error is fixed when I apply #3560779-7: Cannot edit SEO title or description in Yoast SEO widget