Skip to content

Fix Vite HMR host config option

Stan Hu requested to merge sh-fix-vite-gdk-config into main

What does this merge request do and why?

The config option should be host, not hostname (https://vitejs.dev/config/server-options#server-hmr). This led to Content Security Policy errors because the browser attempted to load ws://localhost:3443 instead of ws://gdk.test:3443, for example.

Relates to gitlab#443737

How to set up and validate locally

With Vite enabled, run a feature spec:

bundle exec rspec './spec/features/projects/work_items/work_item_spec.rb[1:1:12:2:1]'

The test appears to fail in Vite with these errors:

     1.2) Failure/Error: raise JSConsoleError, message

          JSConsoleError:
            Unexpected browser console output:
            http://127.0.0.1:56813/vite-dev/@fs/Users/stanhu/gdk-ee/gitlab/tmp/cache/vite/deps/chunk-RGFJKCII.js?v=8165c5f8 76:16 "[@gitlab/ui] The following translations have not been given, so will fall back to their default US English strings:"
            http://127.0.0.1:56813/vite-dev/@vite/client 464 Refused to connect to 'ws://127.0.0.1:3443/vite-dev/' because it violates the following Content Security Policy directive: "connect-src 'self' http://localhost:* ws://localhost:* wss://localhost:* ws://host.docker.internal:* wss://host.docker.internal:* ws://localhost:3038 wss://localhost:3038 http://localhost:3038/vite-dev/ localhost".

            http://127.0.0.1:56813/vite-dev/@fs/Users/stanhu/gdk-ee/gitlab/tmp/cache/vite/deps/chunk-RGFJKCII.js?v=8165c5f8 76:16 "[@gitlab/ui] The following translations have not been given, so will fall back to their default US English strings:"
            http://127.0.0.1:56813/vite-dev/@vite/client 464 Refused to connect to 'ws://127.0.0.1:3443/vite-dev/' because it violates the following Content Security Policy directive: "connect-src 'self' http://localhost:* ws://localhost:* wss://localhost:* ws://host.docker.internal:* wss://host.docker.internal:* ws://localhost:3038 wss://localhost:3038 http://localhost:3038/vite-dev/ localhost"

With this change, the test still fails, but without the Content Security Policy errors.

Impacted categories

The following categories relate to this merge request:

Merge request checklist

  • This change is backward compatible. If not, please include steps to communicate to our users.
  • Tests added for new functionality. If not, please raise an issue to follow-up.
  • Documentation added/updated, if needed.
  • Announcement added, if change is notable.
  • gdk doctor test added, if needed.
  • Add the ~highlight label if this MR should be included in the CHANGELOG.md.
Edited by Stan Hu

Merge request reports