Uncaught TypeError: can't access property "tagify_facets_widget", settings.tagify is undefined

Created on 2 July 2025, about 20 hours ago

Problem/Motivation

Hi there!

This is a weird error i am able to reproduce only in production and only for the anonymous users (i think, admin didn showed this)
I have a view with the facets and all works fine in local DDEV, test (same config as prod) and prod (except for the anonymous setting)

The error i get is:

Uncaught TypeError: can't access property "tagify_facets_widget", settings.tagify is undefined
initTagify ....

under:

        // eslint-disable-next-line no-undef
        const tagify = new Tagify(input, {
          dropdown: {
            enabled: 0,
            highlightFirst: true,
            searchKeys: ['text'],
            fuzzySearch: !!parseInt(
              settings.tagify.tagify_facets_widget.match_operator,
              10,
            ),

(there are 2 additional places in the JS raising the same error to me

Steps to reproduce

not sure, i have just a view with facets i configured from select2 and was working in combination with BEF; but as mentioned, only happens to me in prod

Proposed resolution

I have found two valid solutions for this error:
1) update the JS to return a default value if the property is not declared

-              settings.tagify.tagify_facets_widget.match_operator,
+              settings?.tagify?.tagify_facets_widget?.match_operator ?? 'CONTAINS',
.....
-              settings.tagify.tagify_facets_widget.max_items ?? Infinity,
+              settings?.tagify?.tagify_facets_widget?.max_items ?? Infinity,
......
-          placeholder: settings.tagify.tagify_facets_widget.placeholder,
+          placeholder: settings?.tagify?.tagify_facets_widget?.placeholder ?? '',

2) add 'hook_page_attachments' in tagify.module:

/**
 * Implements hook_page_attachments().
 */
function tagify_page_attachments(array &$page) {

  $page['#attached']['drupalSettings']['tagify'] = [];
}

AND create tagify_facets.module containing:


<?php

/**
 * @file
 * Provides integration with Tagify libraries.
 */

/**
 * Implements hook_page_attachments().
 */
function tagify_facets_page_attachments(array &$page) {

  $page['#attached']['drupalSettings']['tagify_facets_widget'] = [
    'match_operator' => "CONTAINS",
    'max_items' =>  "10",
    'placeholder' =>  "Select one value",
  ];
}

With any of both solutions, the code works to me in production, but i am still not sure from where the error comes in first place....

Remaining tasks

Choose a solution and implement it

Many thnks in advance

🐛 Bug report
Status

Active

Version

1.2

Component

Code

Created by

🇧🇪Belgium gorkagr

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

Comments & Activities

Production build 0.71.5 2024