test_track_js_client icon indicating copy to clipboard operation
test_track_js_client copied to clipboard

Doesn’t work with turbolinks

Open temochka opened this issue 5 years ago • 0 comments

Currently, when imported, the JS client adds "_tt" CSS class to the document body and fires a relevant event. The Test Track Chrome extension looks for this class name when determining whether to be active for the current page. This approach doesn’t play well with Turbolinks, which entirely replaces the document body on every page transition, but keeps existing scripts in <head> loaded. To integrate with libraries that store some state in page DOM, Turbolinks can fire a hook on every URL change, which would be the perfect place to re-initialize TestTrack:

# turbolinks-classic

$(document).on('ready page:load', function(event) {
  initTestTrack();
});

# turbolinks

document.addEventListener("turbolinks:load", function() {
  initTestTrack();
})

Unfortunately, the existing TestTrack.initialize() doesn’t redo the DOM modification if the class is missing. Is there a good reason why? The related question is whether testtrack should be doing any DOM modification on load at all or that part should be deferred until initialization?

temochka avatar Dec 18 '19 17:12 temochka