sourcegraph / sourcegraph-public-snapshot

Code AI platform with Code Search & Cody
https://sourcegraph.com
Other
10.12k stars 1.29k forks source link

Temporary settings: Fetch initial authenticated settings on the server rather than the client #25840

Open umpox opened 3 years ago

umpox commented 3 years ago

Motivation

More context: https://github.com/sourcegraph/sourcegraph/pull/25692#pullrequestreview-774097800

We currently fetch temporary settings on the client, but that means we have to wait for the user to download all JavaScript, parse it and execute before the request is triggered. This can be slow, especially on slower connections. It can also mean that some elements that rely on these settings can appear after the page has loaded, resulting in a cumulative layout shift

Solution

We should aim to fetch authenticated settings on the server, and return the result as part of the rendered HTML. This is similar to how we implement jsContext: https://sourcegraph.com/github.com/sourcegraph/sourcegraph@tr/nps-survey-dismiss-temporary-settings/-/blob/cmd/frontend/internal/app/jscontext/jscontext.go#L41:2

If this works successfully, we should consider implementing this strategy with other common queries, like FeatureFlags and ViewerSettings

cc: @limitedmage

github-actions[bot] commented 3 years ago

Heads up @alicjasuska @umpox @valerybugakov @5h1ru @pdubroy - the "team/frontend-platform" label was applied to this issue.