                 if reconnect
                     @emit('reconnect')
 
+                delete @_connect_lock
                 cb?()
+
+                # This patch application below must happen *AFTER* everything above, including
+                # the callback, since that fully initializes the document and sync mechanisms.
+                if synced_before
+                    # applying missed patches to the new upstream version that we just got from the hub.
+                    #console.log("now applying missed patches to the new upstream version that we just got from the hub: ", patch)
+                    @_apply_patch_to_live(patch)
+                    reconnect = true
 
     disconnect_from_session: (cb) =>
         @_remove_listeners()

                if resp.event == 'error'
                    err = resp.error
                if err
                    cb?(err); return

                @session_uuid = resp.session_uuid
                @readonly = resp.readonly

                if @_last_sync?
                    # We have sync'd before.
                    @_presync?() # give syncstring chance to be updated by true live.
                    patch = @dsync_client._compute_edits(@_last_sync, @live())

                @dsync_client = new diffsync.DiffSync(doc:resp.content)

                if @_last_sync?
                    # applying missed patches to the new upstream version that we just got from the hub.
                    @_apply_patch_to_live(patch)
                    reconnect = true
                else
                    # This initialiation is the first.
                    @_last_sync   = resp.content
                    reconnect = false

    # "connect(cb)": Connect to the given server; will retry until it succeeds.
    # _connect(cb): Try once to connect and on any error, cb(err).
    _connect: (cb) =>

        if @_connect_lock  # this lock is purely defense programming; it should be impossible for it to be hit.
            m = "bug -- connect_lock bug in SynchronizedString; this should never happen -- PLEASE REPORT!"
            alert_message(type:"error", message:m)
            cb(m)
        @_connect_lock = true

        @_remove_listeners()
        delete @session_uuid
        #console.log("_connect -- '#{@filename}'")
