Skip to content
This repository was archived by the owner on Oct 21, 2022. It is now read-only.
This repository was archived by the owner on Oct 21, 2022. It is now read-only.

Tablesaw doesn't properly initialize when script is loaded after document has loaded #342

@porcus

Description

@porcus

I have gotten tablesaw to work as desired in a mock-up, but when integrating it into my app, I couldn't get it to work as expected. I traced the problem to the fact that in my app I am loading tablesaw.js script dynamically AFTER the document has loaded and then calling Tablesaw.init(). Because of this, domContentLoadedTriggered is never set to true, because it doesn't detect that the DOMContentLoaded event has fired, so it doesn't initialize properly.

I've identified a work-around for this which works for now. I just manually trigger the DOMContentLoaded event on the document after dynamically loading the script. (As expected, it works whether I call Tablesaw.init() either before or after manually triggering that event.)

Another way that I've found to make this work is to make the following changes to how domContentLoadedTriggered is used:

...
  var document = window.document;
var domContentLoadedTriggered = /complete|loaded/.test(document.readyState);
document.addEventListener("DOMContentLoaded", function() {
...
	init: function(element) {
		domContentLoadedTriggered = domContentLoadedTriggered || /complete|loaded/.test(document.readyState);
		if (!domContentLoadedTriggered) {
...

Because the DOMContentLoaded event is fired while the document is in the interactive ready state, I didn't include it in the regexes above. This way, it doesn't inadvertently initialize too early. But once the document is in a complete ready state, then it is definitely not too early for the DOMContentLoaded event to have fired, so domContentLoadedTriggered is set.

I hope you'll consider incorporating something like the above change into a future release in order to allow tablesaw to work as one would expect when the script is loaded after the DOMContentLoaded event fires. If it would help, I can create a pull request with those changes above. Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions