Map disappears on subsequent filters when attached to a View with caching and AJAX enabled

Created on 4 August 2024, 11 months ago
Updated 23 August 2024, 11 months ago

Problem/Motivation

When a View has an attachment set to a display which use Geofield Google Map formatter and has caching enabled and AJAX enabled, the map will disappear on subsequent filter applies. The first time a filter is applied, it will work and the map updates. After the first apply, other attempts will result in the map not loading when using the same filter criteria.

Steps to reproduce

  1. Install latest Drupal 10.3 and geofield_map 3.0.20
  2. Create a new node type to store map markers with 1 geofield field
  3. Add a couple of instances of the previously created node type
  4. Create a View to show the previously created node type
  5. Create 1 display as an attachment and 1 display as a page
  6. Add a filter to the view and expose it
  7. Add the geofield field and title to the view
  8. Set the attachment display to use Geofield Google Map format and use the geofield field from before
  9. Attach the previously created attachment display to the page display
  10. Enable caching and AJAX for the view
  11. Visit the page with the view and apply the filter
  12. The first time it will work. Subsequent tries will result in the map not loading

See this screen recording for an example of the issue.

Proposed resolution

  • Remove the check for an existing entry in map_data. When the filter is applied subsequently, the mapId used is the same and an entry already exists in map_data so loadMap() does not get called resulting in a missing map.
  • Remove extra check if mapId exists in drupalSettings since it happens earlier
  • The change above will cause the map to reload everytime it comes into view if lazyload is enabled. To prevent this, use once().

See recording of proposed fix.

Remaining tasks

  • Test if there are any unintended consequences. So far works well!
🐛 Bug report
Status

Fixed

Version

3.0

Component

Code

Created by

🇺🇸United States iamfil

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024