     @inPorts.runtime.on 'data', (runtime) =>
       @runtime.stop() if @runtime
       @runtime = runtime
-      @connect @editor, @runtime
+      if @editor
+        @connect @editor, @runtime
+        @editor = null
 
   sendProject: (runtime, project) ->
     if project.components

    return unless editor and runtime
    runtime.on 'connected', =>
      @connected = true
      # TODO: Read basedir from graph?
      runtime.sendComponent 'list', 'noflo-ui-preview'
      @sendGraph runtime, editor.toJSON()
    runtime.on 'disconnected', =>
      @connected = false
    graph = editor.toJSON()
    @subscribeEditor graph.id, editor, runtime

    runtime.on 'component', (message) ->
      if message.payload.name is 'Graph' or message.payload.name is 'ReadDocument'

    @editor = null
    @runtime = null
    @connected = false
    @project = null
    @inPorts =
      editor: new noflo.Port 'object'
      project: new noflo.Port 'object'
