Skip to content

fix(socketclient): respect basePath when importing Socket.IO client - #4353

Merged
KristjanESPERANTO merged 1 commit into
MagicMirrorOrg:developfrom
TINGyu123644:fix/basepath-socketio-client-url
Nov 28, 2026
Merged

KristjanESPERANTO merged 1 commit into
MagicMirrorOrg:developfrom
TINGyu123644:fix/basepath-socketio-client-url

Conversation

@TINGyu123644

@TINGyu123644 TINGyu123644 commented Nov 27, 2026 •

Copy link
Copy Markdown

Fixes #4352

What this changes

  • js/socketclient.js imported the Socket.IO ES module from the hardcoded absolute URL /socket.io/socket.io.esm.min.js, ignoring a configured basePath. Under a sub-path deployment (e.g. /dashboard/ behind a reverse proxy) the dynamic import failed and the page never started.
  • The URL is now resolved inline from globalThis.config.basePath (generated from the active config by config/basepath.js), with / as the fallback — the same value already used for the socket connection path.
  • Added a Playwright e2e test that emulates a reverse proxy mounting MagicMirror at /dashboard/ and checks the browser actually loads the client module from the prefixed URL. The default / base path is covered as well.

Verification

  • npx vitest run tests/e2e/socketclient_basepath_spec.js — 2/2 pass; the /dashboard/ case times out against the old hardcoded URL (fail-before / pass-after).
  • npx eslint with --max-warnings=0 and npx prettier --check on all changed files — clean.
  • Full unit suite still has the two pre-existing weather date-fixture failures (weathergov_spec.js, yr_spec.js), unrelated to this change.
  • No visual changes.

AI disclosure

This change and its tests were drafted with an AI coding agent. I reviewed the logic, reproduced the failure end to end, ran the targeted tests, ESLint and Prettier locally, and take full responsibility for the contribution.

@KristjanESPERANTO

Copy link
Copy Markdown
Collaborator

Thanks for the fix! It looks good! 🙂

The separate socketIoClientUrl.js file feels a bit excessive, since the calculation is only one line and is used exclusively here. Could we keep it inline in socketclient.js?

const basePath = globalThis.config?.basePath ?? "/";
const socketIo = await import(
    /* @vite-ignore */ `${basePath}socket.io/socket.io.esm.min.js`
);

The CodeQL findings look like false positives to me, since all calls execute successfully in the tests.

I’d prefer covering this with an end-to-end test, since the important behavior is that the Socket.IO client actually loads when MagicMirror is served under a configured basePath. If that test also confirms that the default basePath: "/" still works, I don’t think we need the separate helper or its unit tests. This would keep the change smaller and test the real behavior rather than just the string concatenation.

Follow up on review: keep the one-line URL calculation in socketclient.js
instead of a dedicated helper, and cover the real behavior end to end.

The browser client imported the Socket.IO ES module from a hardcoded
absolute /socket.io/... URL. When MagicMirror is served under a configured
basePath (e.g. /dashboard/ behind a reverse proxy), the browser requested
the module from the site root instead and the page never started.

Resolve the module URL from globalThis.config.basePath, generated from the
active config by config/basepath.js, with a "/" fallback. Add a Playwright
e2e test that emulates a reverse proxy mounting MagicMirror at /dashboard/
and checks that the client module actually loads; the default "/" basePath
is covered as well.

Fixes MagicMirrorOrg#4352

AI-assisted: change and tests were drafted with an AI coding agent and
verified locally (fail-before/pass-after e2e, ESLint, Prettier).

Signed-off-by: TINGyu123644 <TINGyu123644@users.noreply.github.com>
@TINGyu123644
TINGyu123644 force-pushed the fix/basepath-socketio-client-url branch from 6a0df55 to 33af682 Compare November 28, 2026 03:18
@TINGyu123644

Copy link
Copy Markdown
Author

@KristjanESPERANTO Thanks for the review and the concrete suggestion — agreed the helper was overkill. I pushed 33af682:

  • the basePath lookup is now inline in socketclient.js, and the helper plus its unit test are gone;
  • added a Playwright e2e test that emulates a reverse proxy mounting MagicMirror at /dashboard/. It verifies the browser actually requests /dashboard/socket.io/socket.io.esm.min.js and that globalThis.io becomes callable; the default / case is covered too;
  • I checked the test fails against the old hardcoded URL (sub-path case timed out) and passes with the fix. ESLint and Prettier are clean on the changed files. Full unit suite still has the two pre-existing weather date-fixture failures.

Agreed the CodeQL findings look like false positives — the URL uses the same config-generated basePath value the socket connection path already relies on.

@KristjanESPERANTO
KristjanESPERANTO merged commit 4214ea4 into MagicMirrorOrg:develop Nov 28, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants