diff --git a/js/leaflet.drupal.js b/js/leaflet.drupal.js index e4e14e0..6e2e3e2 100644 --- a/js/leaflet.drupal.js +++ b/js/leaflet.drupal.js @@ -122,9 +122,21 @@ const url = content.data('leaflet-ajax-popup'); Drupal.ajax({url: url}).execute() .done(function(data) { + // The response may contain add_css/add_js/settings + // commands ahead of the actual content, so locate the + // insert command instead of assuming it's data[0]. + // https://www.drupal.org/project/leaflet/issues/3456692 + const insert_command = Array.isArray(data) ? + data.find(function(command) { return command.command === 'insert'; }) : + null; + if (!insert_command) { + e.popup.close(); + return; + } + // Copy the html we received via AJAX to the popup, so we won't - // have to make another AJAX call (#see 3258780). - e.popup.setContent(data[0].data); + // have to make another AJAX call. + e.popup.setContent(insert_command.data); // Attach drupal behaviors on new content. Drupal.attachBehaviors(element, drupalSettings);