Skip to content

Search results page crashes when an Image result has no mime_type (getImageType: undefined.match) #128

Description

@reekitconcept

Symptom

The whole search results page crashes with the Volto error page:

TypeError: Cannot read properties of undefined (reading 'match')
    at ImageResultItem

Reproduced on the demo site (main, 3.0.0a2 code) with /search?SearchableText=Labor — the default All tab includes Image results, and one of them has no mime_type in the Solr response.

Root cause

frontend/packages/volto-solr/src/components/theme/SolrSearch/resultItems/helpers/ImageType.jsx:

export const getImageType = (mimeType) => {
  const matchImage = mimeType.match(/image\/(.*)/);   // ← no guard

ImageResultItem calls it twice with a possibly-undefined value whenever the item has a date:

if2={getImageType(item?.extras?.mime_type)}
...
<ImageType mimeType={item?.extras?.mime_type} />

The optional chaining on the caller's side passes undefined straight into .match().

Impact

One badly indexed Image takes down the entire results page (not just its own tile). More visible since images are included in default suggestions/results (#126) — a user can navigate into the crash from the search dialog.

Suggested fix

Guard in getImageType: if (!mimeType) return null; — consistent with its existing null return path for non-image mime types; the footer then simply omits the type label. Optionally also investigate why an Image can be indexed without mime_type (demo-site content import), but the frontend must tolerate it regardless.

Found while taking screenshots of the demo site; the crash predates #126 (present for any Image result on the results page).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions