soulsync/webui
Broque Thomas acc5eb77ea Fix popup: anchor artist field in MB search to stop title-collision covers
`/api/musicbrainz/search_tracks` powers the Fix popup's auto-search
cascade for users on MusicBrainz as primary. When both track + artist
fields were filled, `search_tracks_with_artist` always took the bare
keyword path (`<track> <artist>` joined as one query string). MB's
recording-search scorer weights title matches far above artist matches,
so for "Coffee Break" + "Zeds Dead" the top results were Emapea / The
Vidalias / West One Orchestra's "Coffee Break" — three unrelated cover-
title collisions ahead of the canonical Zeds Dead recording. The
endpoint's `rerank_tracks` pass can't fix this when the right answer
is below the API's 50-result cutoff.

Both-fields mode now uses a strict field-scoped Lucene query first
(`recording:"<t>" AND artist:"<a>"`) which anchors the artist and
prunes title-collision covers at the source. `min_score=0` because the
field-scoped query is itself precise; rerank still does final ordering.
Bare query stays as the fallback when strict returns nothing — covers
the diacritic / alias cases the original `strict=False` path was added
for ("Bjork" query vs canonical "Björk" artist where Lucene phrase
match never hits the recording).

Single-field mode (track-only or artist-only) is unchanged: still bare-
query directly, since there's no artist value to anchor.

Also stable-sort results to prefer entries with non-zero `duration_ms`.
MB has multiple recordings per song (single release, album release,
remasters, compilations) and not every recording carries length data.
Without the preference sort, the user sees a 0:00 row first while a
sibling recording with the real 3:04 sits two rows below — matches the
report where MBID-paste lookup of the canonical recording (length 3:04)
contradicted the search-result's 0:00 row for the same song.

Tests:
- new `test_search_tracks_with_artist_strict_first_when_both_fields`
  pins the strict=True call when both fields present
- new `test_search_tracks_with_artist_falls_back_to_bare_when_strict_empty`
  pins the Björk-style fall-through path
- new `test_search_tracks_with_artist_prefers_results_with_known_length`
  pins the length-preference sort
- existing `..._keeps_low_score_for_rerank` updated to side_effect so
  the bare-fallback path is exercised; behaviour pinned identically
- existing `..._uses_bare_query_mode` renamed + repurposed for strict-
  first; old name's behaviour no longer accurate
2026-05-26 23:00:19 -07:00
..
docs/migration docs(import): align migration docs 2026-05-24 21:17:22 +03:00
src Fix Zustand shallow import 2026-05-24 14:47:29 -07:00
static Fix popup: anchor artist field in MB search to stop title-collision covers 2026-05-26 23:00:19 -07:00
tests fix(webui): preserve import tab refresh URLs 2026-05-24 21:17:20 +03:00
.gitignore Initial Vite app scaffolding & issues page impl 2026-05-13 22:24:46 +03:00
.oxfmtrc.json Split webui tooling into separate configs 2026-05-13 22:26:25 +03:00
.oxlintrc.json Split webui tooling into separate configs 2026-05-13 22:26:25 +03:00
index.html Add SoulSync Discovery tab to Sync page (Phase 1c.3) 2026-05-26 19:46:03 -07:00
package-lock.json feat(webui): migrate import route to React 2026-05-24 21:11:40 +03:00
package.json feat(webui): migrate import route to React 2026-05-24 21:11:40 +03:00
playwright.config.ts Initial Vite app scaffolding & issues page impl 2026-05-13 22:24:46 +03:00
README.md docs(webui): group migration planning docs 2026-05-23 21:22:44 +03:00
tsconfig.json Split webui tooling into separate configs 2026-05-13 22:26:25 +03:00
vite.config.ts Split webui tooling into separate configs 2026-05-13 22:26:25 +03:00
vitest.config.ts Split webui tooling into separate configs 2026-05-13 22:26:25 +03:00
vitest.setup.ts feat(webui): expose shell status in root context 2026-05-23 21:23:32 +03:00

WebUI Hybrid Rendering

SoulSync's web UI is in a transition phase:

  • most pages still render through the legacy vanilla JS shell
  • /issues is rendered by the new React app
  • a small shell bridge keeps both runtimes aware of the active page, profile context, and navigation state

How It Fits Together

flowchart LR
    Browser["Browser parses /webui/index.html"]
    Legacy["Legacy shell scripts\n(core.js -> ... -> init.js)"]
    Bridge["shell-bridge.js\nwindow.SoulSyncWebShellBridge"]
    React["Vite React app\nsrc/app/main.tsx"]
    Router["TanStack Router\nwindow.SoulSyncWebRouter"]

    Browser --> Legacy
    Browser --> React
    Legacy --> Bridge
    React --> Router
    Router --> Bridge
    Bridge --> Legacy

Runtime Roles

  • webui/static/init.js

    • boots the legacy shell
    • selects the active profile
    • handles the legacy page loading flow
  • webui/static/shell-bridge.js

    • owns the browser-side bridge object
    • exposes window.SoulSyncWebShellBridge
    • owns the shared page chrome and route handoff helpers
  • webui/src/app/main.tsx

    • mounts the React app
    • binds window.SoulSyncWebRouter
  • webui/src/platform/shell/route-controllers.tsx

    • listens for bridge readiness
    • keeps React pages aligned with the shell

Load Order

The current order in index.html matters:

  1. legacy shell scripts load first
  2. init.js sets up the shell runtime
  3. shell-bridge.js publishes the bridge and shared chrome helpers after the shell state exists
  4. the Vite React app is injected through {{ vite_assets('body') }} and boots as a module after parsing

That order avoids load-time references to missing globals and keeps the React side able to react to bridge readiness events. The React entry can start fetching early, but the shell bridge and legacy globals are already available by the time the React runtime starts acting on them.

Notes

  • The bridge is intentionally small and browser-only.
  • This is the start of the migration, not a full replacement of the legacy shell.
  • When adding another React page, check whether it needs:
    • a route entry in webui/src/platform/shell/route-manifest.ts
    • bridge typings in webui/src/platform/shell/globals.d.ts
    • a legacy fallback path in webui/static/init.js
    • bridge glue or handoff logic in webui/static/shell-bridge.js

Folder Layout

The React webui uses a small set of predictable folders so route slices stay easy to extend, test, and understand.

webui/src/
  app/         React bootstrap, router, query client, shared API client
  components/  Shared UI primitives
  platform/    Shell bridge and browser/platform integration
  routes/      Route-local code and TanStack Router pages
  test/        Shared test utilities and setup helpers

Migration planning docs live under webui/docs/migration/.

  • keep the high-level route backlog there
  • add one route-specific sketch per migration task
  • keep migration notes close to the WebUI code rather than the repo root

Route Slices

  • Keep route-specific code inside webui/src/routes/<route>/.
  • Put the routing entry in route.tsx.
  • Put route-local UI in a -ui/ folder.
  • Prefix non-routing files with - so TanStack Router ignores them.
  • Keep the route slice small and cohesive.
  • Prefer a few files with clear responsibilities over many tiny files with overlapping names.

Example:

webui/src/routes/issues/
  route.tsx
  -issues.types.ts
  -issues.api.ts
  -issues.helpers.ts
  -issues.api.test.ts
  -issues.helpers.test.ts
  -ui/
    issues-page.tsx
    issue-detail-modal.tsx
    issue-domain-host.tsx

The initial issues slice is the model to follow:

  • -issues.api.ts holds request code and query options
  • -issues.helpers.ts holds pure normalization and formatting
  • -issues.types.ts holds shared types
  • -ui/ holds the page, modal, and legacy handoff UI

Shared Code

  • Put reusable UI in webui/src/components/.
  • Put shell integration in webui/src/platform/.
  • Put bootstrap and app-wide wiring in webui/src/app/.
  • Move code up a level only when it is genuinely shared.
  • Avoid creating new conventions that overlap with existing ones.

Testing Choices

We have a lot of testing tools available, but we do not need all of them for every feature.

  • Use plain unit tests for pure functions and small transforms.
  • Use React component or route tests when the behavior lives in the UI or router.
  • Use MSW-backed tests when request shape, response handling, or error handling matters.
  • Use Playwright when the behavior is best proven end-to-end with the server and browser together.
  • Prefer the smallest test setup that still proves the thing that can regress.

Development

The repo root now owns the full local-dev instructions. Start there for the portable launcher and backend/frontend setup:

  1. README.md for the end-to-end dev flow
  2. npm run check and npm run fix for React-side linting and formatting