 @scrollToMessage = (id) ->
   if id[0] == '#'
     id = id[1..]
-  if id of id2template
-    template = id2template[id]
+  if id of id2dom
+    dom = id2dom[id]
     $('html, body').animate
-      scrollTop: template.firstNode.offsetTop
+      scrollTop: dom.offsetTop
     , 200, 'swing', ->
       ## Focus on title edit box when scrolling to message being edited.
-      ## We'd like to use `template.$('input.title')`
+      ## We'd like to use `$(dom).find('input.title')`
       ## but want to exclude children.
-      heading = template.firstNode?.firstChild
+      heading = dom.firstChild
       $(heading).find('input.title').focus() if heading?
   else
     scrollToLater = id

    ## initImage calls updateFileQuery which will do this:
    #images[data._id].file = data.file
    #initImageInternal data.file if data.file?
    id2template[data._id] = @
    ## If message is naturally folded, don't count images it references.
    images[data._id].naturallyFolded = naturallyFolded data
    images[data._id].children = data.children?.length

    elt.addEventListener 'dragstart', listener for elt in elts
    -> elt.removeEventListener 'dragstart', listener for elt in elts
  , [folded, history?, messageFileRef.current, message]

  ## Maintain id2dom mapping
  useEffect ->
    id2dom[message._id] = ref.current
    -> delete id2dom[message._id]
  , [message._id, ref.current]
  ## Scroll to this message if it's been requested.
  useEffect ->
    if scrollToLater == message._id
      scrollToLater = null
      scrollToMessage message._id
    undefined
  , [message._id]

  onFold = (e) ->
    e.preventDefault()
