website
website copied to clipboard
Fix Svelte/Vite HMR config
Description
There's an issue preventing us from working with this repository out of the box using VS Code Desktop: the website enters into an endless refreshing loop. (Internal discussion)
This PR allows it to correctly work on:
- VS Code Browser, where the WebSocket port needs to be 443 due to the
wss
protocol. - Desktop IDEs, where ports are automatically forwarded, and we access the website via
http://localhost:<port>
.
We set the fields to undefined
when we don't need to overwrite them, so they will use the value from other config parameters. Here are their type definition:
HmrOptions.clientPort?: number | undefined
HmrOptions.host?: string | undefined
Note: code
is the 'IDE Alias' for VS Code Browser.
How to test
- Go to Gitpod.io Preferences, select
VS Code Browser
as Editor, and start a workspace using this URL: https://gitpod.io/#https://github.com/gitpod-io/website/pull/2562 - Then confirm on Network Tab if the WebSocket connection is using the Gitpod URL: - Go to Gitpod.io Preferences, select
VS Code (Desktop)
as Editor, and start a workspace using this URL: https://gitpod.io/#https://github.com/gitpod-io/website/pull/2562 - Then confirm on Network Tab if the WebSocket connection is using the localhost URL:
I've verified this on the desktop and it works great, but I think that fixing it on the desktop might have broken the browser IDE. Doing more testing to verify this.
Edit: My default IDE is VS Code Desktop, but when I open up the VS Code browser I get the following environment variable setting: GITPOD_IDE_ALIAS=code-desktop
. Because opening the same workspace in the browser and desktop have shared shell environments GITPOD_IDE_ALIAS
might not provide enough information to detect the appropriate HMR configuration. 🫤
I've updated the solution to avoid using environment variables. Description and instructions for testing were also updated. Could you please check again?
Tested with vs code desktop and browser in parallel; navigating the site was extremely fast and page updates only occurred on file changes. This worked perfectly! LGTM 🚢
@felladrin it is a right solution 👍 We should do https://github.com/gitpod-io/gitpod/issues/11849 at some point to make it more reliable.