Uncaught DOMException: Failed to execute 'remove' on 'DOMTokenList':

Created on 17 October 2023, about 1 year ago
Updated 20 May 2024, 6 months ago

Problem/Motivation

The following error arises after I updated my Drupal installation to D10, together with Metatag 2.0:

Uncaught DOMException: Failed to execute 'remove' on 'DOMTokenList': The token provided ('not available') contains HTML space characters, which are not valid in tokens.

This breaks admin JS functionality.

🐛 Bug report
Status

RTBC

Version

2.0

Component

Code

Created by

🇳🇱Netherlands steven buteneers

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @steven buteneers
  • First commit to issue fork.
  • Pipeline finished with Failed
    about 1 year ago
    Total: 68s
    #39835
  • 🇪🇪Estonia mikkmiggur

    I got the same error when the content was in the Korean language.
    Uncaught DOMException: Failed to execute 'remove' on 'DOMTokenList': The token provided ('알 수 없음') contains HTML space characters, which are not valid in tokens.

  • 🇪🇪Estonia mikkmiggur

    Issue is coming from the yoast_seo.js file line 305

        // We convert the label to lowercase here, which is not as good as clean_css that's being called on the back-end,
        // but is good enough for the constraints on the classes we use.
        scoreDisplay.classList.remove(scoreLabel.innerHTML.toLowerCase());
    

    Content of scoreDisplay.innerHTML is:

        <span class="score_circle"></span>
        <span class="score_value">알 수 없음</span>
  • 🇪🇪Estonia mikkmiggur

    That issue is coming from Drupal translation.
    When I change that field back to English then there is no issue.

  • 🇪🇪Estonia mikkmiggur

    overall_score.html.twig file contain

    <div {% if overall_score_target_id %}id="{{ overall_score_target_id }}"{% endif %}
         class="overallScore {{ overall_score|clean_class }}">
        <span class="score_circle"></span>
        <span class="score_value">{{ overall_score }}</span>
    </div>
    

    When I remove that "clean_class" from here then I don't have that issue anymore.
    When we add "clean_class" and later try to update the value and use "overall_score" as an indicator then these 2 values can not match in some cases.

  • 🇮🇳India dharmendraqed42

    I got an error that said, 'Uncaught DOMException: Failed to execute 'remove' on 'DOMTokenList': The token provided ('not available') contains HTML space characters, which are not valid in tokens.'

    I fixed it by changing this part of the code in yoast_seo.js file:

    Before:
    scoreDisplay.classList.remove(scoreLabel.innerHTML.toLowerCase());
    scoreDisplay.classList.add(newLabelText.toLowerCase());

    After:
    scoreDisplay.classList.remove(scoreLabel.innerHTML.toLowerCase().replace(' ', '-'));
    scoreDisplay.classList.add(newLabelText.toLowerCase().replace(' ', '-'));

    This change fixed the problem.

  • 🇪🇸Spain eduardo morales alberti Spain, 🇪🇺

    Same error here.

  • 🇪🇪Estonia mikkmiggur

    #7 didn't work in my case.

  • First commit to issue fork.
  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 7.4 & MySQL 5.7
    last update about 1 year ago
    Composer require-dev failure
  • @lendude opened merge request.
  • Pipeline finished with Failed
    about 1 year ago
    Total: 67s
    #49992
  • 🇳🇱Netherlands Lendude Amsterdam

    The change needed to be done in both the remove and the add commands to really get rid of the issue, pushed changes to the MR

  • 🇳🇱Netherlands Johan den Hollander

    The changes in the MR work well for me.

  • Status changed to Needs review about 1 year ago
  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 7.4 & MySQL 5.7
    last update about 1 year ago
    Composer require-dev failure
  • 🇳🇱Netherlands Lendude Amsterdam
  • Status changed to RTBC about 1 year ago
  • 🇧🇪Belgium tim-diels Belgium 🇧🇪

    I got the same error and the MR fixed it for me.

  • 🇳🇱Netherlands watergate

    Although already marked as RTBC, I can confirm it resolves our problem as well.

  • 🇫🇷France Grimreaper France 🇫🇷

    Hi,

    I have tested patch from comment 7 which is currently the same change as the MR and I too confirm it fixes the bug.

    Thanks for the fix!

  • 🇧🇪Belgium fernly

    Tested patch #7 and confirming it works.

    RTBC +1

  • 🇮🇳India arunkumark Coimbatore

    Reviewed patch #7, applied successfully, and resolved the issue. +RTBC

    Before Patch

    After Patch

  • Pipeline finished with Failed
    6 months ago
    #176770
  • 🇮🇳India arunkumark Coimbatore

    arunkumark changed the visibility of the branch 3394487-uncaught-domexception-failed to hidden.

  • Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 7.4 & MySQL 5.7
    last update 6 months ago
    Waiting for branch to pass
  • Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 7.4 & MySQL 5.7
    last update 6 months ago
    Waiting for branch to pass
  • 🇮🇳India arunkumark Coimbatore

    Created MR from the #7 patch.

  • Pipeline finished with Failed
    6 months ago
    Total: 128s
    #176771
Production build 0.71.5 2024