From 125b4a1aa7cd0090dcde1dc412ddfc2889526e6d Mon Sep 17 00:00:00 2001 From: Mathew Allen Date: Fri, 26 Aug 2016 14:49:05 -0400 Subject: [PATCH 1/4] switch implementation of extractTrackedAssets to querySelector --- lib/assets/javascripts/turbograft/turbohead.coffee | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/assets/javascripts/turbograft/turbohead.coffee b/lib/assets/javascripts/turbograft/turbohead.coffee index 814798ea..22784431 100644 --- a/lib/assets/javascripts/turbograft/turbohead.coffee +++ b/lib/assets/javascripts/turbograft/turbohead.coffee @@ -26,8 +26,7 @@ updateScriptTags = (activeDocument, newScripts, callback) -> ) extractTrackedAssets = (doc) -> - for node in doc.head.children when node.dataset.turbolinksTrack? - node + return [].slice.call(doc.querySelectorAll('[data-turbolinks-track]')) filterForNodeType = (nodeType) -> (node) -> node.nodeName == nodeType From 507aca3139dffd750f25b0e2ebb3c51e1fe5cb9e Mon Sep 17 00:00:00 2001 From: Mathew Allen Date: Fri, 26 Aug 2016 14:49:25 -0400 Subject: [PATCH 2/4] add test for many subsequent requests and many subsequent synchronouse requests --- test/javascripts/turbolinks_test.coffee | 29 ++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/test/javascripts/turbolinks_test.coffee b/test/javascripts/turbolinks_test.coffee index a8d1fdf7..38d80d9c 100644 --- a/test/javascripts/turbolinks_test.coffee +++ b/test/javascripts/turbolinks_test.coffee @@ -64,7 +64,7 @@ describe 'Turbolinks', -> visit = ({options, url}, callback) -> $(document).one('page:load', (event) -> - setTimeout((-> callback(event)), 0) + setTimeout((-> callback(event) if callback), 0) ) Turbolinks.visit('/' + url, options) @@ -185,6 +185,33 @@ describe 'Turbolinks', -> assertLinks(['foo.css']) done() + it 'many subsequent navigations do not break head asset tracking', (done) -> + requestsToDo = 10 + + recursiveVisit = -> + visit url: 'twoLinksInHead', -> + visit url: 'singleLinkInHead', -> + assertLinks(['foo.css']) + requestsToDo -=1 + return recursiveVisit() if requestsToDo > 0 + done() + + recursiveVisit() + + it 'many subsequent synchronous navigations do not break head asset tracking', (done) -> + requestsToDo = 10 + + recursiveVisit = -> + visit url: 'twoLinksInHead' + visit url: 'singleLinkInHead' + visit url: 'twoLinksInHead', -> + assertLinks(['foo.css', 'bar.css']) + requestsToDo -=1 + return recursiveVisit() if requestsToDo > 0 + done() + + recursiveVisit() + describe 'transforms the current head to have the same links in the same order as the upstream document with minimal moves', -> it 'maintains order when moving from an empty head to a page with link nodes.', (done) -> linkTagInserted = sinon.spy() From 66fb0e95a960b03eef50a3bd4e67881bfa9a9503 Mon Sep 17 00:00:00 2001 From: Mathew Allen Date: Fri, 26 Aug 2016 16:28:57 -0400 Subject: [PATCH 3/4] extraneous return --- lib/assets/javascripts/turbograft/turbohead.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/assets/javascripts/turbograft/turbohead.coffee b/lib/assets/javascripts/turbograft/turbohead.coffee index 22784431..aa13dfa1 100644 --- a/lib/assets/javascripts/turbograft/turbohead.coffee +++ b/lib/assets/javascripts/turbograft/turbohead.coffee @@ -26,7 +26,7 @@ updateScriptTags = (activeDocument, newScripts, callback) -> ) extractTrackedAssets = (doc) -> - return [].slice.call(doc.querySelectorAll('[data-turbolinks-track]')) + [].slice.call(doc.querySelectorAll('[data-turbolinks-track]')) filterForNodeType = (nodeType) -> (node) -> node.nodeName == nodeType From 7b62ecb9c596eea391227c231d2e668be956799f Mon Sep 17 00:00:00 2001 From: Mathew Allen Date: Mon, 29 Aug 2016 11:50:43 -0400 Subject: [PATCH 4/4] remove misleading tests --- test/javascripts/turbolinks_test.coffee | 27 ------------------------- 1 file changed, 27 deletions(-) diff --git a/test/javascripts/turbolinks_test.coffee b/test/javascripts/turbolinks_test.coffee index 38d80d9c..8508ebcb 100644 --- a/test/javascripts/turbolinks_test.coffee +++ b/test/javascripts/turbolinks_test.coffee @@ -185,33 +185,6 @@ describe 'Turbolinks', -> assertLinks(['foo.css']) done() - it 'many subsequent navigations do not break head asset tracking', (done) -> - requestsToDo = 10 - - recursiveVisit = -> - visit url: 'twoLinksInHead', -> - visit url: 'singleLinkInHead', -> - assertLinks(['foo.css']) - requestsToDo -=1 - return recursiveVisit() if requestsToDo > 0 - done() - - recursiveVisit() - - it 'many subsequent synchronous navigations do not break head asset tracking', (done) -> - requestsToDo = 10 - - recursiveVisit = -> - visit url: 'twoLinksInHead' - visit url: 'singleLinkInHead' - visit url: 'twoLinksInHead', -> - assertLinks(['foo.css', 'bar.css']) - requestsToDo -=1 - return recursiveVisit() if requestsToDo > 0 - done() - - recursiveVisit() - describe 'transforms the current head to have the same links in the same order as the upstream document with minimal moves', -> it 'maintains order when moving from an empty head to a page with link nodes.', (done) -> linkTagInserted = sinon.spy()