once is not a function (identical to 3277218)

Created on 1 February 2023, almost 2 years ago
Updated 20 November 2023, about 1 year ago

1.0 Problem/Motivation
On version 6.2.2, while rendering the webform, I get, on console, the error twice: Uncaught ReferenceError: once is not defined but for difference js files.

2.0 Detailed steps to reproduce (embed screenshots)

  • Added core contact fields
  • Added custom fields
  • Added address fields

Screenshot:

I believe this issue is similar to https://www.drupal.org/project/webform_civicrm/issues/3277218 but it doesn't affect the payment module this time

3.0 Proposed resolution
Add the same dependencies (- core/once) inside webform_civicrm.libraries.yml for:

  • js/webform_civicrm_forms.js
  • js/webform_civicrm_contact.js

like so:

civicrm_contact:
  css:
    component:
      css/token-input.css: {}
  js:
    js/jquery.tokeninput.js: {}
    js/webform_civicrm_contact.js: {}
  dependencies:
    - core/once <---
    - webform_civicrm/forms

and similarly, add the same core/once dependency on forms.

Cheers

🐛 Bug report
Status

Closed: cannot reproduce

Version

6.2

Component

Webform/Drupal

Created by

🇬🇧United Kingdom vangelisp Fife, Scotland

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

Comments & Activities

  • Issue created by @vangelisp
  • 🇬🇧United Kingdom vangelisp Fife, Scotland

    Coming back to this issue, I was able to identify how this issue/console error gets triggered.

    On my main theme, I have the dependency: - core/jquery.once instead of - core/once.

    That means that if we don't explicitly define in the webform_civicrm.libraries.yml that we want the dependency core/once for each js library that we're using, the webform will use the one of the theme (parent), which (in my case) was core/jquery.once.

    My personal take on this is that we should enforce the proper dependencies so as to avoid any potential situations like mine, although I don't know how many people continue to use the old dependency core/jquery.once.

  • 🇬🇧United Kingdom kenorb

    Same issue on D8, I had to downgrade to 6.2.1.

  • 🇨🇦Canada karing 🇨🇦

    D8 has been end of life for a very long time. It is not supported.

  • Assigned to jitendrapurohit
  • 🇨🇦Canada karing 🇨🇦

    Jitendra: could you please have a look at this re: D9?

  • 🇬🇧United Kingdom kenorb

    This seems to happen in webform_civicrm_admin.js and webform_civicrm_options.js. At the bottom of the script it's using })(Drupal, jQuery, once);

    I've added:

    admin:
      dependencies:
        - core/jquery
        - core/once
    

    to webform_civicrm.libraries.yml as suggested, but didn't seems to help.

  • 🇬🇧United Kingdom kenorb

    Workaround for Drupal 8.x:

    1. Add js/once.js into your theme from https://www.drupal.org/project/once (https://git.drupalcode.org/project/once/-/blob/v1.0.1/src/once.js?ref_ty...).
    2. Load it as dependency in your_theme.libraries.yml

    global-components:
      js:
        js/custom.js: {}
        js/once.js: {}
    
  • 🇮🇳India jitendrapurohit

    It looks like the core/once library was added in https://github.com/colemanw/webform_civicrm/pull/773 already? I cant replicate the console error on my instance.

    Also, we have test running on github which i think also captures any console errors.

    The test is configured to run against drupal version 9.4, 9.5 & v10 and none of them fails with a js error.

    Do you mean its only failing for Drupal 8?

  • Status changed to Closed: cannot reproduce over 1 year ago
  • 🇺🇸United States jptillman

    Comment #7 doesn't work. Not only is once.js at the provided URL a module script that requires being loaded as a module, webform_civicrm doesn't even pick it up once it's loaded.

Production build 0.71.5 2024