fix(svelte): Update top-level route list#64272
Conversation
b8b1d61 to
a555d0e
Compare
a555d0e to
400c1dd
Compare
There was a problem hiding this comment.
Not needed anymore since we are loading the real window.context object from the origin server.
There was a problem hiding this comment.
This module/plugin now encapsulates all the proxy handling.
|
|
||
| // Additional endpoints that should be proxied to the real Sourcegraph instance. | ||
| // These are not part of the known routes, but are required for the SvelteKit app to work. | ||
| const additionalEndpoints = ['/.api/', '/.assets/', '/.auth/'] |
There was a problem hiding this comment.
Can't get rid of all the hardcoding (or I have to add route registration in even more places 🤷🏻 )
| existingValue := fromContext(ctx) | ||
| if existingValue != nil { | ||
| value.knownRoutes = append(existingValue.knownRoutes, knownRoutes...) | ||
| } | ||
| next.ServeHTTP(w, req.WithContext(context.WithValue(ctx, contextKey{}, value))) |
There was a problem hiding this comment.
This combines the list from multiple routes.
camdencheek
left a comment
There was a problem hiding this comment.
LGTM. You comfortable merging this with one day to release?
Yes. The user facing/production is rather small and straightforward. |
The core problem seems to be that we've not been `await`ing adding the initialization scripts.
| await this.page.addInitScript(() => { | ||
| window.localStorage.setItem('temporarySettings', '{"webNext.welcomeOverlay.dismissed": true}') | ||
| }) |
There was a problem hiding this comment.
@camdencheek Found out why the dialog was still showing locally. This statement needed to be moved out of the conditional.
A consequence of https://github.com/sourcegraph/sourcegraph/pull/64272 is that redirecting to the cody marketing page on dotcom didn't work. That's because `/cody` is not provided by the server as a known page. A simple fix would be to mark the link as external, but we'd have to keep in mind to do this in all places (present and future). A more "central" fix is to add this page to a hardcoded list of known pages that are not provided by the server.
There couldn't isn't a 'one step' way to start a local Sourcegraph instance with the SvelteKit app. This commit adds `sg start enterprise-sveltekit` to fix that. The changes in https://github.com/sourcegraph/sourcegraph/pull/64272 allow us to run the vite dev server in front of the Sourcegraph instance, instead of building the assets and having them served by frontend. This gives us the benefit of hot module reloading and in general seems to be a less fragile approach. It's basically the same what we do with the React app in development mode.
Fixes srch-851 A consequence of https://github.com/sourcegraph/sourcegraph/pull/64272 is that redirecting to the cody marketing page on dotcom didn't work. That's because `/cody` is not provided by the server as a known page. A simple fix would be to mark the link as external, but we'd have to keep in mind to do this in all places (present and future). A more "central" fix is to add this page to a hardcoded list of known pages that are not provided by the server. ## Test plan Manual testing
There currently isn't a 'one step' way to start a local Sourcegraph instance with the SvelteKit app. This commit adds `sg start enterprise-sveltekit` to fix that. The changes in https://github.com/sourcegraph/sourcegraph/pull/64272 allow us to run the vite dev server in front of the Sourcegraph instance, instead of building the assets and having them served by frontend. This gives us the benefit of hot module reloading and in general seems to be a less fragile approach. It's basically the same what we do with the React app in development mode. ## Test plan `sg start enterprise-sveltekit` starts the vite dev server as well as the sourcegraph instance. Navigating to `https://sourcegraph.test:3443/search` opens the Svelte app (when enabled and logged in). Making a change in a source file updates the web page immediately. `sg start web-sveltekit-standalone` still works
tl;dr: Everything is derived from
window.context.svelteKit.knownRoutesbuckle up
Context
After the new web app was enabled by default on dotcom I looked at dotcom data in Sentry to see if there was anything out of the ordinary. I noticed a high number of errors related to resolving repository information. The most common non-existing repository that was reported was
-/sign-out.Of course this shouldn't happen.
/-/sign-outis the sign out URL and shouldn't be interpreted as a repository.Currently we prevent SvelteKit from interpreting specific paths as repositories by using the
reporevparameter validator:-/sign-outwas not in that list, including others which have been added since this file was originally created.Adding it would have been the simple solution but having to maintain this list manually has always irked me. Now we have a better way...
Production changes
Client side
It turns out we are already sending a list of known routes to the client in
window.context.svelteKit.knownRoutesto basically do the same thing: test whether a given path is a page or a repository.Why do we have the
reporevvalidator andisRouteEnabled? They basically do the same thing (check whether a path is a known page or a repository) the first (reporev) is used by SvelteKit to determine which route a path corresponds to (i.e. to navigate to the repository page or whether the page doesn't exist) and the second one (isRouteEnabled) is used after the route resolution but before route loading. It's used to trigger a full page refresh to fetch the React version if necessary.Anyways, since we already have a list of known pages from the server, the parameter validator should just use it too. Except it didn't work, which made the following server side changes necessary.
Server
We register routes in multiple places. Right now
knownRoutesis populated from the router created incmd/frontend/internal/app/ui/router.go, but this does not include/-/sign-out. This route (and others) are defined incmd/frontend/internal/app/router/router.go(I don't know what the difference is). I extended the sveltekit route registration code so that's possible to register routes from multiple routers.I couldn't test it yet however because I currently can't get Sourcegraph to run locally.
Development mode changes
After the above changes, navigating to a React only page in development, e.g.
/insightswould show a 'repo not found error' becausewindow.context.svelteKit.knownRouteswas empty in development. So every non-existing page would be interpreted as missing repository.Hardcoding a list of known pages again just for development seemed to be a step backwards. So I spent quite a bit of time to find a way to extract the JS context object from the HTML page returned by the origin server and inject it into the HTML page generated by SvelteKit, similar to how we do it for the React app.
Additionally the value of
window.context.svelteKit.knownRoutesis now used to setup the proxy to non-supported pages from the server, so we don't have to maintain this regex anymore either:This means that requesting non-svelte pages will also return the corresponding React version in development.
Test plan
Manual testing.