Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

fix(svelte): Properly load/serve version.json#63688

Merged
fkling merged 1 commit into
mainfrom
fkling-srch-700-404-error-trying-to-load-versionjson
Jul 8, 2024
Merged

fix(svelte): Properly load/serve version.json#63688
fkling merged 1 commit into
mainfrom
fkling-srch-700-404-error-trying-to-load-versionjson

Conversation

@fkling

@fkling fkling commented Jul 8, 2024

Copy link
Copy Markdown
Contributor

Fixes srch-700

In certain situations SvelteKit tries to load version.json to check whether a new version of the web app is available (see the SvelteKit docs for more information). This currently doesn't work, accessing this file throws a 404 error.

This is due to how SvelteKit generates the path to access the file. It uses the value of appDir for this, which is currently set to the default value. We put our assets in client/web/dist/_sk/*, which can then be accessed on the server via /.assets/_sk/*. To make that work properly we've been modifiying the generated index.html file to use the right file path.
This however doesn't work for fetching version.json because the path to that file is generated at runtime.

This commit aims to fix this issue by setting appDir to a value that works with the Sourcegraph server so that version.json can be properly loaded. Incidentally this also makes our "post processing" easier: Instead of changing the contents of the index.html file we instead have to move the app assets to the proper location. With appDir set to .assets/_sk/_app, SvelteKit will put the app assets into <out>/.assets/_sk/_app. But that would mean the full URL path to a file would be .assets/_sk/.assets/_sk/_app. To fix that we now move the files from <out>/.assets/_sk/_app to <out>/_app.

Test plan

Tested that pnpm dev, pnpm preview and bazel test //client/web-sveltekit:e2e_test work as expected.

In certain situations SvelteKit tries to load `version.json` to check
whether a new version of the web app is available. This currently
doesn't work, accessing this file throws a 404 error.

This is due to how SvelteKit generates the path to access the file. It
uses the value of `appDir` for this, which is currently set to the
default value. We put our assets in `client/web/dist/_sk/*`, which can
then be accessed on the server via `/.assets/_sk/*`. To make that work
properly we've been modifiying the generated `index.html` file to use
the right file path.
This however doesn't work for fetching `version.json` because the path
to that file is generated at runtime.

This commit aims to fix this issue by setting `appDir` to a value that
works with the Sourcegraph server so that `version.json` can be properly
loaded. Incidentally this also makes our "post processing" easier:
Instead of changing the contents of the `index.html` file we instead
have to move the app assets to the proper location.
With `appDir` set to `.assets/_sk/_app`, SvelteKit will put the app
assets into `<out>/.assets/_sk/_app`. But that would mean the full URL
path to a file would be `.assets/_sk/.assets/_sk/_app`. To fix that we
now move the files from `<out>/.assets/_sk/_app` to `<out>/_app`.
@fkling fkling requested a review from camdencheek July 8, 2024 14:19
@fkling fkling self-assigned this Jul 8, 2024
@cla-bot cla-bot Bot added the cla-signed label Jul 8, 2024

@camdencheek camdencheek left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to me! Thanks for the explanatory comments

@fkling fkling merged commit a6d53b5 into main Jul 8, 2024
@fkling fkling deleted the fkling-srch-700-404-error-trying-to-load-versionjson branch July 8, 2024 14:35
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants