website icon indicating copy to clipboard operation
website copied to clipboard

Fix Svelte/Vite HMR config

Open felladrin opened this issue 2 years ago • 1 comments

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

  1. 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: image
  2. 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: image

felladrin avatar Aug 10 '22 17:08 felladrin

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. 🫤

adrienthebo avatar Aug 10 '22 18:08 adrienthebo

I've updated the solution to avoid using environment variables. Description and instructions for testing were also updated. Could you please check again?

felladrin avatar Aug 11 '22 14:08 felladrin

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 🚢

adrienthebo avatar Aug 11 '22 20:08 adrienthebo

@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.

akosyakov avatar Aug 15 '22 09:08 akosyakov