Skip to content

Fix music-metadata-browser import resolution and lazy-load parser for build stability#12

Merged
ChrisAdamsdevelopment merged 1 commit into
codex/harden-readfilemetadata-functionfrom
codex/fix-build-failure-in-pr-#11
May 4, 2026
Merged

Fix music-metadata-browser import resolution and lazy-load parser for build stability#12
ChrisAdamsdevelopment merged 1 commit into
codex/harden-readfilemetadata-functionfrom
codex/fix-build-failure-in-pr-#11

Conversation

@ChrisAdamsdevelopment
Copy link
Copy Markdown
Owner

@ChrisAdamsdevelopment ChrisAdamsdevelopment commented May 4, 2026

Motivation

  • The Vite build can fail when music-metadata-browser export shape or bundling behavior is different between environments, so the static import { parseBlob } is brittle and caused unresolved-import build failures.
  • The change aims to reproduce the build issue and apply a minimal, safe runtime fix that preserves browser-side metadata analysis and metadata hardening behavior.

Description

  • Replaced the static parseBlob import with a lazy getParseBlob() that uses import('music-metadata-browser') and resolves mod.parseBlob || mod.default.parseBlob, throwing if the export is not found to fail fast.
  • Updated readFileMetadata() to use the lazy loader, to catch parse failures, and to include the filename in the metadata searchable content while keeping boundary-aware marker detection and short-marker protection intact.
  • Left writeMP3Metadata() behavior intact while keeping text sanitization, frame writes for title/artist/genre, returning an audio/mpeg Blob, and not triggering auto-downloads.
  • No changes were made to auth, Stripe, usage, server cleanse, browser cleanse, or queue behavior beyond the import resolution fix.

Testing

  • Ran npm install and the install completed successfully with music-metadata-browser@2.5.11 present in package.json and package-lock.json.
  • Ran npm run build and the build completed successfully, producing the application chunks and static assets without unresolved-import errors.
  • Verified the lockfile package entry for music-metadata-browser using a Node check and confirmed the version 2.5.11 was present.
  • No automated tests failed during these steps and the build artifacts were produced as expected.

Codex Task

Summary by Sourcery

Lazy-load music-metadata-browser’s parseBlob to improve build robustness and extend metadata search to include filenames when detecting AI markers.

Bug Fixes:

  • Prevent Vite build failures by resolving music-metadata-browser’s parseBlob at runtime via a dynamic import.

Enhancements:

  • Include file names in aggregated metadata strings used for AI marker detection, while preserving existing marker handling behavior.

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented May 4, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Replaces a brittle static import of music-metadata-browser’s parseBlob with a lazy dynamic loader and slightly enhances metadata collection to include the filename, while preserving existing metadata hardening and MP3 writing behavior.

Sequence diagram for lazy loading music_metadata_browser parseBlob

sequenceDiagram
  actor User
  participant App
  participant MetadataUtils
  participant MusicMetadataBrowser

  User->>App: selectFile(file)
  App->>MetadataUtils: readFileMetadata(file)
  activate MetadataUtils

  MetadataUtils->>MetadataUtils: getParseBlob()
  alt parseBlobLoader not initialized
    MetadataUtils->>MusicMetadataBrowser: import(music-metadata-browser)
    activate MusicMetadataBrowser
    MusicMetadataBrowser-->>MetadataUtils: module
    deactivate MusicMetadataBrowser
    MetadataUtils->>MetadataUtils: resolve module.parseBlob or module.default.parseBlob
    MetadataUtils-->>MetadataUtils: cache Promise in parseBlobLoader
  else parseBlobLoader already set
    MetadataUtils-->>MetadataUtils: reuse cached parseBlobLoader
  end

  MetadataUtils-->>MetadataUtils: await parseBlob
  MetadataUtils->>MusicMetadataBrowser: parseBlob(file)
  MusicMetadataBrowser-->>MetadataUtils: metadata or error

  MetadataUtils->>MetadataUtils: collectStrings(metadata, file.name)
  MetadataUtils-->>App: { format, detectedMarkers, parseError }
  deactivate MetadataUtils

  App-->>User: show metadata and AI marker detection result
Loading

Class diagram for updated metadata utilities module

classDiagram
  class MetadataUtils {
    +getParseBlob() Promise
    +escapeRegex(value) string
    +markerToRegex(marker) RegExp
    +collectStrings(metadata, fileName) string
    +readFileMetadata(file) Promise
  }

  class parseBlobLoaderHolder {
    -parseBlobLoader Promise
  }

  MetadataUtils --> parseBlobLoaderHolder : uses

  class MusicMetadataBrowserModule {
    +parseBlob(file) Promise
  }

  MetadataUtils ..> MusicMetadataBrowserModule : dynamic_import

  class readFileMetadataDetails {
    -parsed any
    -parseError Error
    +AI_MARKERS string[]
    +MARKER_REGEX_CACHE Map
  }

  MetadataUtils --> readFileMetadataDetails : maintains_state
Loading

File-Level Changes

Change Details Files
Make music-metadata-browser parseBlob import resilient via lazy dynamic loading to avoid build-time unresolved imports.
  • Remove the static named import of parseBlob from music-metadata-browser.
  • Introduce a module-level parseBlobLoader promise cache and an async getParseBlob() helper that dynamically imports music-metadata-browser.
  • Resolve parseBlob from either the module’s named export or default.parseBlob and throw an explicit error if the function is not found to fail fast at runtime.
src/utils/metadata.js
Adjust metadata string collection and readFileMetadata behavior while preserving existing marker detection and writeMP3Metadata semantics.
  • Extend collectStrings() to accept an optional fileName parameter and append it to the searchable content when present.
  • Update readFileMetadata() to await getParseBlob() before parsing the file, capturing any parse errors into parseError.
  • Pass file?.name into collectStrings() so filenames participate in marker-searchable text, while leaving AI markers list, regex caching, marker matching, and writeMP3Metadata behavior unchanged.
src/utils/metadata.js

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • In readFileMetadata, parseError is captured but never used, so consider either removing it or surfacing it (e.g., via logging or return shape) to avoid dead code and make error handling intent clearer.
  • The getParseBlob loader caches the promise, which means a transient import failure will permanently poison future calls; consider resetting parseBlobLoader on rejection or adding a retry path so the app can recover from one-off load errors.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `readFileMetadata`, `parseError` is captured but never used, so consider either removing it or surfacing it (e.g., via logging or return shape) to avoid dead code and make error handling intent clearer.
- The `getParseBlob` loader caches the promise, which means a transient import failure will permanently poison future calls; consider resetting `parseBlobLoader` on rejection or adding a retry path so the app can recover from one-off load errors.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: dc05817267

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/utils/metadata.js
Comment on lines +9 to +10
if (parseBlobLoader) return parseBlobLoader;
parseBlobLoader = import('music-metadata-browser').then((mod) => {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Clear cached loader when dynamic import rejects

If import('music-metadata-browser') fails once (for example a transient chunk/network load error), parseBlobLoader is left pointing at a rejected promise and every later readFileMetadata() call will immediately fail in the same session, even after conditions recover. This regresses resilience because the code never retries module resolution unless the page is reloaded; resetting the cache on rejection would allow a subsequent attempt to succeed.

Useful? React with 👍 / 👎.

@ChrisAdamsdevelopment ChrisAdamsdevelopment merged commit a7c14bb into codex/harden-readfilemetadata-function May 4, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant