 
 
   componentDidMount: =>
+    roots[0].appendChild @portal
     document.addEventListener 'keydown', @handleEsc
+    $(document).on 'turbolinks:before-cache.modal', () =>
+      roots[0].removeChild @portal
 
 
   componentDidUpdate: (prevProps) =>

import { createPortal } from 'react-dom'

export class Modal extends PureComponent
  portals = document.getElementsByClassName('js-react-modal')


  @inTree: (event) ->
    portals[0] in event.composedPath()


  constructor: ->


  componentWillUnmount: =>
    document.removeEventListener 'keydown', @handleEsc
    $(document).off '.modal'


  handleEsc: (e) =>
