     if remoteNode = body.querySelector('[id="'+nodeId+'"]')
       remoteNode.parentNode.replaceChild(existingNode, remoteNode)
 
-persistPermanentNodes = (body) ->
+persistPermanentNodes = (body, sourceBody) ->
   allNodesToKeep = []
 
-  nodes = document.querySelectorAll("[data-turbolinks-permanent]")
+  nodes = sourceBody.querySelectorAll("[data-turbolinks-permanent]")
   allNodesToKeep.push(node) for node in nodes
 
   keepNodes(body, allNodesToKeep)
   return
 
-getTemporaryNodes = ->
-  node for node in document.querySelectorAll('[data-turbolinks-temporary]')
+getTemporaryNodes = (body)->
+  node for node in body.querySelectorAll('[data-turbolinks-temporary]')
 
 getPermanentNodes = ->
-  node for node in document.querySelectorAll('[data-turbolinks-permanent]')
+  node for node in body.querySelectorAll('[data-turbolinks-permanent]')
 
 getNodesMatchingChangeKeys = (keys, body) ->
   matchingNodes = []

  triggerEvent EVENTS.CHANGE
  triggerEvent EVENTS.UPDATE

refreshAllExceptWithKeys = (keys, body) ->
  allNodesToKeep = []

  for key in keys
    for node in document.querySelectorAll('[id^="'+key+'"]')
      allNodesToKeep.push(node)

  keepNodes(body, allNodesToKeep)

    document.location.href = document.location.href
  else
    window.scrollTo 0, 0

clone = (original) ->
  return original if not original? or typeof original isnt 'object'
