Skip to content
Snippets Groups Projects
Closed Extensions can access sourcegraph.app.activeWindow.activeViewComponent.document before the document was synced to the extension host
  • View options
  • Extensions can access sourcegraph.app.activeWindow.activeViewComponent.document before the document was synced to the extension host

  • View options
  • Closed Issue created by Warren Gifford

    Created by: felixfbecker

    We currently sync the code views and document data separately:

    https://sourcegraph.com/github.com/sourcegraph/sourcegraph@758c376ba0981d315e29314797e4bfb56c8dd7ea/-/blob/shared/src/api/client/connection.ts#L77:9-80:11

    https://sourcegraph.com/github.com/sourcegraph/sourcegraph@758c376ba0981d315e29314797e4bfb56c8dd7ea/-/blob/shared/src/api/client/connection.ts#L103-112

    Since communication with the extension host is (and always was) async, this can cause window data (i.e. the open editor) to be synced before the document that is open in that editor was synced.

    This sometimes happens and causes the git-extras extension to throw when accessing activeViewComponent.document: https://sourcegraph.com/github.com/sourcegraph/sourcegraph@758c376ba0981d315e29314797e4bfb56c8dd7ea/-/blob/shared/src/api/extension/api/documents.ts#L27:13

    To reproduce it, delay the Observable of the document data:

    @@ -107,7 +107,8 @@ export async function createExtensionHostClientConnection(
                         ({ visibleViewComponents }) =>
                             visibleViewComponents && visibleViewComponents.map(({ item }) => item)
                     ),
    -                distinctUntilChanged((a, b) => isEqual(a, b))
    +                distinctUntilChanged((a, b) => isEqual(a, b)),
    +                delay(100)
                 )
             )

    Activity

    • All activity
    • Comments only
    • History only
    • Newest first
    • Oldest first