hotwired / stimulus

A modest JavaScript framework for the HTML you already have
https://stimulus.hotwired.dev/
MIT License
12.62k stars 418 forks source link

IE11 - Error connecting controller - TypeError: Object doesn't support property or method 'matches' #207

Closed nicholas-c closed 5 years ago

nicholas-c commented 5 years ago

Getting this error thrown with a controller, seems to be linked to accessing a target, but unconfirmed.

image

Stripped back my controller to the following code... Console.log('1') fires, the rest is where the error is thrown.

Data-controller is on the body, as it needs to be a site-wide thing.

// Samples Controller
import { Controller } from 'stimulus'

export default class extends Controller {
  static targets = ['counter']

  connect() {
    this.updateCount()
  }

  updateCount() {
    console.log('1')
    console.log(this.counterTargets)
    console.log('2')
  }
}

It seems to stem from this...

Scope.prototype.findAllElements = function (selector) {
        var head = this.element.matches(selector) ? [this.element] : [];
        var tail = this.filterElements(Array.from(this.element.querySelectorAll(selector)));
        return head.concat(tail);
    };

Edit: this.targets.findAll('counter') returns the same error in all controllers.

javan commented 5 years ago

Browser Support

Stimulus supports all evergreen, self-updating desktop and mobile browsers out of the box.

If your application needs to support older browsers like Internet Explorer 11, include the  @stimulus/polyfills  package before loading Stimulus.

Are you using that 👆?

nicholas-c commented 5 years ago

Doh!!! My bad! Deepest apologies!

jalada commented 5 years ago

I get this issue again, because the @stimulus/polyfills version matcher for element-closest is pulling in 3.0.0, which doesn't work the same / is broken: https://github.com/jonathantneal/closest/issues/25 & https://github.com/jonathantneal/closest/blob/master/CHANGELOG.md

javan commented 5 years ago

Fixed in v1.1.1 via https://github.com/stimulusjs/stimulus/commit/0251c87795f351a7462d00fa0f028b2daf967a01. Thanks for the heads up, @jalada!

glaszig commented 5 years ago

this is incompatible with the latest webpacker which depends on core-js 3 :(

chrisokamoto commented 4 years ago

@glaszig did you find a solution?

glaszig commented 4 years ago

@chrisokamoto this occured to me while upgrading to the latest webpacker at the time on a rails 5.2 code base. i reverted that upgrade and things work fine.

chrisokamoto commented 4 years ago

@chrisokamoto this occured to me while upgrading to the latest webpacker at the time on a rails 5.2 code base. i reverted that upgrade and things work fine.

@glaszig yeah, the same for me. but I don't want to downgrade Rails and Webpacker.. I'll try something else, which include stop using stimulus.. :( it's just a small component in my case. Thanks for the reply :)