sourcegraph/dev
Felix Kling cb596f4d7f
Refactor SvelteKit <-> React routing integration (#61830)
**Context**

In order for the SvelteKit app to work in production and to ensure that navigating between the React and SvelteKit app "just works" a couple of things need to happen:

- the server needs to know for which routes to serve the SvelteKit app
- when navigating to a new page, the React app needs to know whether that page should be served by the SvelteKit app or not. If it should, it performs a page refresh, which will cause the server to send the SvelteKit app.
- the same applies to the SvelteKit app, but vice versa, except that it performs a page refresh automatically for every route that it doesn't support (the SvelteKit app is a subset of the React app).

Until now this logic was controlled by the `web-next` and `web-next-rollout` feature flags.
When `web-next` is set the server will serve the SvelteKit app for all routes supported by the app.
When `web-next-rollout` is set the server will server the SvelteKit app only for a certain subset of pages.

These two sets of pages are currently maintained separately in different places on server, the React app and the SvelteKit app. Multiple steps need to be taken to make a SvelteKit page available in production and that is not easy to maintain.

**New approach**

With this new approach, making a SvelteKit page available in production is much simpler.

To make it available as "opt-in" (`web-next` feature flag):

1. Add new page as usual.
2. Run `sg generate`.

To roll it out by default on e.g. S2 (`web-next-rollout` feature flag).

1. Add `// @sg EnableRollout` to the corresponding `+page.ts` file.
2. Run `sg generate`.

**How it works**

Ultimately what the server, the React app and SvelteKit app have to do is determine whether the SvelteKit supports a given path name.

Because SvelteKit uses file based routing we can determine at build time which SvelteKit routes exist. We can also take the route IDs and convert them to regular expression, [much like SvelteKit does itself](ed8970ef74/packages/kit/src/utils/routing.js).

By adding a "meta data comment" of the form `// @sg <tag>` we can mark a page to be e.g. enabled by default via the `web-next-rollout` feature flag.

Having this list of regular expression, the server can decide whether or not to serve the SvelteKit app by running the pathname of the current request against the list.

The same list can be passed to the React and SvelteKit clients via `window.context`, and the clients can perform exactly the same tests when the user navigates to a new route. More specifically, in this current iteration the clients each get their own copy of the complete list and the server only sends the indices of the enable routes.

Overall this makes it 
- much easier to manage the availability and rollout state of SvelteKit pages
- reduces the complexity of checking whether or not SvelteKit is enabled or not on the server, React app and SvelteKit app

**Repository root handling**

What makes the whole situation more difficult is the fact that the repository root is essentially a catch all route. That means for a client to decide whether or not a target path is a page or a repository it has to know about all the existing pages. That's why the server sends a list of known routes (extracted from gorilla mux) to the clients.
2024-04-16 23:05:12 +02:00
..
auth-provider remove more ENTERPRISE=1 remnants (#57232) 2023-10-02 10:43:11 -07:00
authtest bazel: use transitions to apply cross-compile platform automatically to oci_image (#60569) 2024-02-20 13:57:56 +00:00
backcompat Feature flags: relax some constraints (#61343) 2024-03-25 10:39:01 -06:00
bkstats chore: links/ownership devx->dev-infra (#58999) 2023-12-14 15:07:20 +00:00
build-tracker build-tracker: fix nil pointer in getting commit author (#61685) 2024-04-08 13:42:35 +00:00
buildchecker Replace all traditional for-loops (#60988) 2024-03-11 16:05:47 +02:00
check searcher: remove unused dependency on dbconn pkg (#61463) 2024-03-28 17:11:41 +02:00
ci Add caddy to DeploySourcegraphDockerImages (#61911) 2024-04-16 11:45:15 +01:00
clustering Dev tool: python script for text clustering based on local embeddings (#58691) 2023-12-04 09:27:14 -05:00
codehost_testing Replace all traditional for-loops (#60988) 2024-03-11 16:05:47 +02:00
codeintel-qa chore: remove unused darwin-arm64 cross binaries for codeintel-qa (#61419) 2024-04-02 16:50:00 +02:00
db scripts: dont run subshell in for loop (#60611) 2024-02-19 14:48:33 +00:00
depgraph depgraph: Fix spurious error when no subcommand name is passed (#61871) 2024-04-15 16:10:44 +02:00
deployment-lag-notifier Chore: move dev tools out of enterprise (#57354) 2023-10-04 22:56:50 +02:00
deployment-notifier Docs: update links to point to new site (#60381) 2024-02-13 00:23:47 +00:00
dx bazel: build //enterprise (#47327) 2023-02-07 15:30:46 +01:00
go-mockgen-gazelle bazel: include //dev:go_mockgen in //dev:write_all_generated (#60963) 2024-03-11 14:23:29 +00:00
go-mockgen-transformer bazel: native go-mockgen in Bazel (#60386) 2024-02-16 13:26:48 +00:00
gqltest Search: add rev:at.time() for searching a repo at a point in time (#61513) 2024-04-12 15:14:16 -06:00
grafana chore: remove unused dev/sg/internal/loki (#61923) 2024-04-16 12:19:32 +00:00
insight-data-gen Chore: move dev tools out of enterprise (#57354) 2023-10-04 22:56:50 +02:00
internal/cmd dotcom: MockSourcegraphDotComMode requires a T for cleanup (#61172) 2024-03-14 20:27:21 +00:00
linters searcher: remove unused dependency on dbconn pkg (#61463) 2024-03-28 17:11:41 +02:00
managedservicesplatform msp/project: enable accesscontextmanager APIs (#61679) 2024-04-08 18:12:41 -04:00
nix nix: build pg-utils with nix [static edition] (#61734) 2024-04-09 20:24:19 +01:00
perforce perforce: move perforce test helpers to perforce dir (#57700) 2023-10-18 16:13:03 +02:00
phabricator add shellcheck & shfmt to pre-commit's pre-push hook (#59485) 2024-01-11 14:16:22 +00:00
pr-auditor Removed pr-auditor and left redirect notice (#59497) 2024-01-10 15:15:24 -08:00
prometheus telemetry-gateway: migrate to MSP runtime (#58814) 2023-12-08 12:14:34 -08:00
scaletesting Replace all traditional for-loops (#60988) 2024-03-11 16:05:47 +02:00
sg chore: remove unused dev/sg/internal/loki (#61923) 2024-04-16 12:19:32 +00:00
src-expose ci: re-enable race detection (#52776) 2023-06-05 20:41:47 +02:00
team bazel: native go-mockgen in Bazel (#60386) 2024-02-16 13:26:48 +00:00
tilt
tools bazel: use pgutil binaries from GCS instead of from the host (#61741) 2024-04-11 18:00:21 +01:00
update-embeddings-list reapply "switch from jest to vitest for faster, simpler tests (#57886)" (#58145) 2023-11-07 12:00:18 +02:00
zoekt gomod: update zoekt to fix several CVEs in dependencies (#60093) 2024-02-02 15:36:04 +00:00
.gitignore
add_https_domain_to_hosts.sh
bazel_buildkite_stamp_vars.sh bazel: test volatile variables with Percy (#51693) 2023-05-11 09:20:42 +00:00
bazel_stamp_vars.sh Reapply "bazel: migrate dind dockerfile to rules_oci" (#61790) (#61824) 2024-04-12 15:52:44 +00:00
BUILD.bazel Refactor SvelteKit <-> React routing integration (#61830) 2024-04-16 23:05:12 +02:00
caddy.sh fix(sg): start Caddy admin server before caddy trust (#58928) 2023-12-20 10:03:45 +02:00
Caddyfile Add an option for disabling HTTP/2 when communicating with Cody Gateway (#59668) 2024-01-17 15:36:40 +01:00
check-tokens.sh Updated pre-commit regex for new token format (#60031) 2024-02-05 13:57:56 +01:00
CLA.txt
codeinsights-db.sh
comby-install-or-upgrade.sh add shellcheck & shfmt to pre-commit's pre-push hook (#59485) 2024-01-11 14:16:22 +00:00
defs.bzl Removed unused bazel macro arg (#60996) 2024-03-11 06:36:15 -07:00
dev-sourcegraph-server.sh
docsite.sh [docsite]: bump version (#56013) 2023-08-18 12:40:44 -06:00
drop-entire-local-database-and-redis.sh
esbuild.bzl Revert "use vite for web builds (#58228)" (#59132) 2023-12-20 16:23:45 -03:00
eslint-report-test.sh Revert "revert "bazel: improve ESLint rule" (#52853)" (#52878) 2023-06-04 19:06:39 -07:00
eslint.bzl reapply "switch from jest to vitest for faster, simpler tests (#57886)" (#58145) 2023-11-07 12:00:18 +02:00
foreach-non-web-client-project.sh release: drop legacy release tooling (#61220) 2024-04-09 14:29:35 -05:00
git-stats
global-settings.json dev: revert to old search mode for local dev environment (#59129) 2023-12-20 17:02:32 +01:00
go_defs.bzl build: add buildifier check to Aspect Workflows (#58566) 2023-11-27 14:58:01 +02:00
go_mockgen_rule.bzl bump to Go 1.22.1 (#60902) 2024-03-06 17:38:43 -07:00
go_mockgen.bzl bazel: native go-mockgen in Bazel (#60386) 2024-02-16 13:26:48 +00:00
go_stringer.bzl build: upgrade to Bazel 7 pre-release (#57970) 2023-10-31 15:29:14 +02:00
go-mod-update.sh
js_lib.bzl bazel: implement custom ESLint Bazel rule (#52062) 2023-05-22 04:05:45 -07:00
licenses.sh Docs: update links to point to new site (#60381) 2024-02-13 00:23:47 +00:00
migrations.bzl bazel: use pgutil binaries from GCS instead of from the host (#61741) 2024-04-11 18:00:21 +01:00
mocha.bzl bazel: refactor percy mocha tests to js_test instead of js_run_binary + build_test (#60983) 2024-03-26 10:58:20 +00:00
msp_delivery.bzl msp_delivery: infer pipeline id from service_id and region (#61395) 2024-03-26 15:30:27 +00:00
oci_defs.bzl bazel: transition oci_image to opt/release mode for Rust (#61740) 2024-04-15 17:19:17 +00:00
oci_deps.bzl Reapply "bazel: migrate dind dockerfile to rules_oci" (#61790) (#61824) 2024-04-12 15:52:44 +00:00
p4-fusion-dev bazel: provide p4-fusion via bazel (#58893) 2023-12-11 16:06:06 +00:00
proto.bzl fix: gazelle and proto generation (continuation of #49547) (#49713) 2023-04-11 11:36:45 +02:00
prune-pick.sh
redis-postgres.yml Docs: update links to point to new site (#60381) 2024-02-13 00:23:47 +00:00
redis.conf
run-server-image.sh Remove HTTP for inter-service RPC (#59093) 2024-01-11 19:46:32 +01:00
sass.bzl Buildifier fixes (#48691) 2023-03-07 10:15:26 +01:00
schema_migrations.bzl bazel: rework schema migrations reporule without gsutil (#61295) 2024-03-25 16:17:26 +00:00
scip-ctags-dev local: fix scip-ctags install script (#57252) 2023-10-02 14:58:14 +00:00
scip-ctags-install.sh syntax-highlighter: initial ctags work (w/ musl scip-ctags) (#52643) 2023-05-30 17:19:39 -04:00
scip-syntax-dev highlighter: Rename scip-treesitter-cli -> scip-syntax (#60077) 2024-02-05 13:15:09 +01:00
scip-syntax-install.sh Syntactic indexing: add database schema and dbworker (#60055) 2024-02-08 18:00:21 +00:00
site-config.json Remove broken federation feature (#55161) 2023-07-20 17:30:32 +00:00
src-prof-services.json Add embeddings to server behind env var (#50288) 2023-04-04 16:45:50 +02:00
src-search-meta.sh
tool_deps.bzl bazel: use pgutil binaries from GCS instead of from the host (#61741) 2024-04-11 18:00:21 +01:00
tools.go Build images end-to-end using Bazel v2 (#61845) 2024-04-12 16:18:43 +01:00
universal-ctags-dev bzl: do not show full commmand line for ctags in dev (#58261) 2023-11-10 10:05:25 -05:00
write_generated_to_source_files.bzl bazel: native go-mockgen in Bazel (#60386) 2024-02-16 13:26:48 +00:00