Skip to content

refactor(frontend): remove logger-client dependency on authStore #269

@test3207

Description

@test3207

Parent Issue

Epic 3.5: Observability & Operations (#190)

Summary

Refactor logger-client.ts to remove its dependency on authStore, breaking the circular dependency and improving bundle size.

Problem

The initial logger implementation (#250) had logger-client.ts importing authStore to get userId. This caused:

  1. Circular dependency: authStore -> logger -> authStore
  2. Vite warnings during build
  3. Bundle optimization issues (dynamic imports not effective)

Solution

  • Remove authStore dependency from logger-client.ts
  • Add userId field to LogOptions interface
  • Callers pass userId via { userId: getUserId() }
  • Each store defines a simple getUserId() helper

Changes

File Change
frontend/src/lib/logger-client.ts Remove authStore import, add userId to LogOptions
frontend/src/stores/authStore.ts Pass userId in logger calls
frontend/src/stores/libraryStore.ts Add getUserId() helper, pass userId in logger calls
frontend/src/stores/playlistStore.ts Add getUserId() helper, pass userId in logger calls
frontend/src/stores/playerStore/persistence.ts Add getUserId() helper, pass userId in logger calls

Bundle Impact

Metric Before (v2.0.2-rc.5) After Delta
Main bundle 293.03 KB 301.10 KB +8.07 KB
Main gzip 91.31 KB 93.63 KB +2.32 KB

The ~8 KB increase is the total cost of the logging system (logger-client.ts + userId tracking in stores). This is acceptable for production observability.

Acceptance Criteria

  • No Vite circular dependency warnings
  • All tests pass (411 frontend tests)
  • Build succeeds without warnings
  • Logger has no business dependencies (pure utility)

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions