Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix safari no styles #132

Merged
merged 4 commits into from
Aug 29, 2016
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions lib/assets/javascripts/turbograft/turbohead.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ updateScriptTags = (activeDocument, newScripts, callback) ->
)

extractTrackedAssets = (doc) ->
for node in doc.head.children when node.dataset.turbolinksTrack?
node
[].slice.call(doc.querySelectorAll('[data-turbolinks-track]'))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this do anything that the original turbolinks fix doesn't do?

Copy link
Contributor Author

@marutypes marutypes Aug 29, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It outputs considerably more legible javascript than a coffeescript array comprehension.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about Array.prototype.slice instead of [].slice? http://stackoverflow.com/questions/9006553/slice-or-array-prototype-slice suggests prototype is more performant, unfortunately jsperf is dead :(

Copy link

@WillsonSmith WillsonSmith Aug 29, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The performance diffs here are so negligible it doesn't really matter what you choose unless you're going to run this hundreds of thousands of times.

Average of running 1 million instances. Each one of these were run 5 separate times.

[].slice.call Array.prototype.slice.call
394.88ms 378.16ms

That's about 16ms diff at 1 million times, about 1 frame.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, at that point it's mostly a matter of whether you think Array.prototype.slice.call or [].slice.call looks nicer.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks! 👍 as is!


filterForNodeType = (nodeType) ->
(node) -> node.nodeName == nodeType
Expand Down
29 changes: 28 additions & 1 deletion test/javascripts/turbolinks_test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -185,6 +185,33 @@ describe 'Turbolinks', ->
assertLinks(['foo.css'])
done()

it 'many subsequent navigations do not break head asset tracking', (done) ->
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless we have a way to run Safari in CI, these don't seem valuable. They probably give a false sense of confidence to the next people who come along and try to update the head query.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's fair. I'll wipe them. :)

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()
Expand Down