frappe / datatable

The Missing Javascript Datatable for the Web
https://frappe.io/datatable
MIT License
1.02k stars 164 forks source link

In function removeStyle() this.stylesheet is null #96

Closed faburem closed 4 years ago

faburem commented 4 years ago

We are occasionally seeing the following error stack in our app using Frappe datatable:

Screenshot 2020-01-26 at 12 34 17

It seems to be related to the timing when the datatable is rendered on the page because it is not happening every time. I am wondering if we could add a check here to prevent this.stylesheet to be null and thus preventing the error stack above: https://github.com/frappe/datatable/blob/3475f6ccaa5b1306dd12927537d752ebc1082756/src/style.js#L122

faburem commented 4 years ago

Turns out this was not related to frappe datatable but to the way the framework we are using (Meteor.js) cleans up after itself (spoiler alert: it's bad). For anybody else trying this combination, here is how to resolve it (assuming that you create a datatable instance in the onRendered Callback and store it's reference in the template instance:

Template.yourTemplate.onDestroyed(() => {
  Template.instance().datatable.destroy()
  Template.instance().datatable = undefined
})