     appComponent = @
 
     modal = @state.modal
-    if @props.bodyWrapper
-      body = @props.bodyWrapper null, @props.activeRouteHandler()
+    # TODO warn on initialization failure
+    if @state.initializationState.state == 'pending'
+      body = null
     else
       body = @props.activeRouteHandler()
+    if @props.bodyWrapper
+      body = @props.bodyWrapper null, body
     React.DOM.div {className: 'lead'},
       React.DOM.div {className: 'nav-bar'},
         Router.Link {to: 'notebook', className: 'title'}, 'lead'

      if @props.footer
        React.DOM.div {className: 'modal-footer'}, @props.footer

AppComponent = React.createClass
  displayName: 'AppComponent'
  getInitialState: ->
    modal: null
  mixins: [Router.Navigation]
  componentWillMount: ->
    modalModel.onValue (modals) =>

      Router.NotFoundRoute {handler: NotFoundComponent}

  # TODO handle errors, timeouts
  initializationPromise = Modules.init_modules(module_names)

  React.renderComponent routesComponent, target
  initializationPromise.done()

exports.raw_cell_url = (value) ->
  # TODO don't require appComponent
