Problem/Motivation

When using Layout Builder with Entity Browser for media selection (such as the Image component), a JavaScript error occurs that prevents proper search functionality in modal contexts:

Uncaught TypeError: Cannot read properties of undefined (reading 'facets_summary_id')
    at updateFacetsBlocks (facets-views-ajax.js:242)

Steps to reproduce:

  1. Navigate to a Layout Builder page (e.g., /node/123/layout)
  2. Click "Add component" and select "Image" (or any Entity Browser component)
  3. In the Entity Browser modal, enter a search term that returns no results
  4. Clear or modify the search text and press enter
  5. JavaScript error occurs and search functionality breaks

Proposed resolution

Add defensive programming checks in facets-views-ajax.js to handle cases where Entity Browser contexts don't have facets summary configuration. The fix prevents accessing undefined properties while maintaining normal facets functionality.

Two areas need updating:

  • updateFacetsBlocks function: Check if settings.facets_views_ajax.facets_summary_ajax.facets_summary_id exists before accessing it
  • updateFacetsSummaryBlock function: Add null checks for the nested object structure

Remaining tasks

  • Review patch
  • Test in Entity Browser contexts
  • Verify normal facets functionality remains intact
  • Consider automated test coverage

User interface changes

None - this is a JavaScript bug fix that maintains existing functionality.

API changes

None - internal JavaScript defensive programming only.

Data model changes

None.

Release notes snippet

Fixed JavaScript error in Entity Browser contexts when facets summary configuration is not present, improving Layout Builder media selection reliability.

Issue fork facets-3586391

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

webbywe created an issue. See original summary.

akash_deep made their first commit to this issue’s fork.

akash_deep’s picture

Status: Active » Needs review

Submitted MR !372 with the defensive checks. Added the guard in updateFacetsSummaryBlock so it checks facets_views_ajax exists before touching facets_summary_ajax, and in updateFacetsBlocks I added the full chain check plus a wrapper on the DOM lookup since .attr('id') returns undefined when the element isnt there and that was what caused the indexOf crash. Normal facets behavior stays the same when settings are present.

webbywe’s picture

Patch applies to 2.0.10 and tested to resolved the "Steps to reproduce:". The defensive measure appear acceptable. Review of PR failures appear to be unrelated along with lint issues.

daceej’s picture

Status: Needs review » Reviewed & tested by the community

Confirming that the patch applies to 2.0.10 and appears to resolve the issue.