Skip to content

Experimental reference panel: undo revert after fixing pagination for references/implementations

Warren Gifford requested to merge mrn/unrevert-ref-panel into main

Created by: mrnugget

This fixes #30971 (closed)

This reverts the revert in f4a4c975731041c99517110dc7b9015dc067edee and restores the ref panel pagination added in https://github.com/sourcegraph/sourcegraph/pull/31403.

Reviewers: review by commit! First commit is the revert-of-revert so it's long. Other commits then include the fix.

Why we had to revert in the first place: Apollo, our GraphQL client, uses its cache under the hood to do pagination. Since the GraphQL entities we request for the reference panel (GitBlob and Location) don't have an id field that Apollo can use for caching we had to use the url field. But due to https://github.com/apollographql/apollo-client/issues/5711 that means every GraphQL query has to request the url field, otherwise the request breaks at runtime. That's what happened and why we had to revert: the symbols sidebar also queries GitBlob and Location but without url and the queries broke.

How @umpox and I (but mainly @umpox) fixed it: we turned the Apollo cache off and managed the state with useState. That, it turns out, leads to a simpler solution even. Instead of using useQuery & fetchMore we use a single useQuery on first render to get the initial data and then useLazyQuery to create two callbacks that can be used to load references and pagination independently.

Test plan

  • Uploaded LSIF data to local instance, opened ref panel, made sure that
    • loading more references uses only one additional request
    • loading more implementations uses only one additional request
    • clicking through references/implementations works and doesn't reload data
    • clicking on different token resets panel

Merge request reports

Loading