Problem/Motivation

A polyfill for CustomEvent is needed for Internet Explorer 11.

This is one of the three polyfills from #3076171: Provide a new library to replace jQuery UI autocomplete and we are now addressing each in their own issue.

Note: White it is currently a nice-to-have, the CustomEvent polyfill will be necessary in order for the new Autocomplete issue #3076171: Provide a new library to replace jQuery UI autocomplete to land.

CommentFileSizeAuthor
#3 customevent_polyfill.mp41.46 MBhooroomoo

Issue fork drupal-3239507

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:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

hooroomoo created an issue. See original summary.

hooroomoo’s picture

FileSize
1.46 MB

Spoke with user @bnjmnm and was informed despite there being no existing use to change, this polyfill is useful in reducing the scope of the Autocomplete issue.

To provide evidence the polyfill works, I temporarily added the polyfill to the messages library used by the Olivero theme. I pasted this code snippet into the JS console in IE11.

As the video shows, I received the expected console output of "event fired, cat name is Buddy"

var obj = document.querySelector('body');
obj.addEventListener('cat', function(e) {console.log('event fired, cat name is ' + e.detail.catName)});
var event = new CustomEvent('cat', {
  detail: {
    catName: 'Buddy',
  },
});
obj.dispatchEvent(event);
hooroomoo’s picture

Status: Active » Needs review
bnjmnm’s picture

Status: Needs review » Needs work

It looks like the test runner stops at spellcheck

--- Commands Executed ---
core/scripts/dev/commit-code-check.sh --drupalci
Return Code: 1
--- Output ---
Creating list of files to check by comparing branch to 9.3.x
/var/www/html/core/core.libraries.yml:189:8 - Unknown word (customevent)
/var/www/html/core/core.libraries.yml:192:20 - Unknown word (customevent)

CSpell: failed

Here's information on working with the spellchecker https://www.drupal.org/node/3122084

This can be addressed by either adding customevent to the skipped words dictionary or adding comments to ignore the usages in the file they appear. I recommend the first option as other libraries may wind up depending on drupal.customevent, and this ensures the spellchecker won't object every time a new library adds this as a dependency.

hooroomoo’s picture

Status: Needs work » Needs review
bnjmnm’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community

The MR and change record look good, and the video in #3 confirms it works as expected.

While it's true there is no current use of CustomEvent in core (other than libraries that already have this polyfilled), adding this here is helpful to reduce the overall size of #3076171: Provide a new library to replace jQuery UI autocomplete, an issue that must land for Drupal 10, and one that is unlikely to change in a manner that makes the CustomEvent polyfill unnecessary. Even if the unlikely occurs and the Autocomplete issue no longer uses CustomEvent, the presence of this polyfill is not a major burden on core as it's small, demonstrated to work, and is only loaded if explicitly added as a dependency to another library.

  • catch committed b986c49 on 9.3.x
    Issue #3239507 by hooroomoo, bnjmnm: Add CustomEvent polyfill to support...
catch’s picture

Status: Reviewed & tested by the community » Fixed

Makes sense to get this in separate to the autocomplete issue.

Committed b986c49 and pushed to 9.3.x. Thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.