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

Issue fork yoast_seo-3537343

Command icon 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

joey-santiago created an issue. See original summary.

joey-santiago’s picture

Confirm this happens also on a simplytest me test site, so this doesn't look like is caused by our install.

joey-santiago changed the visibility of the branch 3537343-javascript-error to hidden.

freezernick’s picture

+1 RTBC for #4

joey-santiago’s picture

Issue summary: View changes

Added 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.

altcom_neil’s picture

StatusFileSize
new1.83 KB

We 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

dewancodes’s picture

When 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.

akhtardaha’s picture

I face the same error after upgrade to drupal 10.5.2 and the patch from #7 fixed the issue.

alexius’s picture

Yes, patch #7 is working

gedur’s picture

Patch working on Drupal 11.2, thanks!

kburakozdemir’s picture

StatusFileSize
new809.75 KB

I 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...

new and old module comparision

anruether’s picture

Status: Active » Reviewed & tested by the community

Thank 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 function

drupal 11.3.3, yoast_seo 2.2

anruether’s picture

Status: Reviewed & tested by the community » Needs work
anruether’s picture