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:
- Navigate to a Layout Builder page (e.g., /node/123/layout)
- Click "Add component" and select "Image" (or any Entity Browser component)
- In the Entity Browser modal, enter a search term that returns no results
- Clear or modify the search text and press enter
- 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_idexists 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
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
Comment #4
akash_deep commentedSubmitted 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.
Comment #5
webbywe commentedPatch 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.
Comment #6
daceej commentedConfirming that the patch applies to 2.0.10 and appears to resolve the issue.