Axaj popups not working for anonymous users

Created on 14 June 2025, 11 days ago

Problem/Motivation

It has been reported before, and it was marked as solved, but instead of reopening those bugs I chose to create a new one as the older ones were marked as resolved, so this might be a different issue.

On the newest stable Drupal (11.1.8) and newest leaflet (both 10.2.48 and 10.3.0), creating a view that loads the popups through ajax (page or block), for an anonymous user will fail to display the popup with a browser console error:

Uncaught TypeError: Drupal.ajax is not a function.

Steps to reproduce

  1. Clean install of drupal 11.1.8 with leaflet and Geofield.
  2. Add a geofield to the article content type
  3. Add one article with a value for the geofield
  4. Add a page leaflet view, with the popup source: node entity via ajax, popup source view mode: teaser.
  5. Try to visualize the page in another browser/container so that the user is anonymous and click on the map pin.

Proposed resolution

A quick fix is to add a library dependency to core/drupal.ajax in the leaflet module. Eg. in the leaflet.libraries.yml file

leaflet-drupal:
  js:
    js/leaflet.drupal.js: {}
  dependencies:
    - core/jquery
    - core/once
    - core/drupal
    - core/drupal.ajax
    - leaflet/leaflet

But this is not a recommended fix, since it will load the javascript library even if it is not needed.

Another quick fix is to change the popup source from node entity via ajax to node entity, but for maps with a large number of pins it will slow down the loading time and it will unnecessary load a lot of potentially unneeded information.

I have attached the potentially related issues.

🐛 Bug report
Status

Active

Version

10.3

Component

Code

Created by

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

Comments & Activities

  • Issue created by @devarch
  • 🇮🇹Italy itamair

    thanks @devarch for reporting this and providing all your details

    BUT I cannot reproduce your issues, and Leaflet Popus load nicely with Ajax (as expected) in all the following combination that I (just) tested out on this purpose:

    - Drupal Core 10.4.8 & 11.1.7
    - Drupal Leaflet 10.2.48 & 10.3.0

    More specifically:

    1. Check this Leaflet Demo page: https://www.geodemocracy.com/drupal_geofield_stack_demo/web/geoplaces-ma...
    that at the moment loads (nicely) Leaflet Popups via Ajax, with Drupal Leaflet 10.3.0 and Drupal Core 10.4.8

    2. I tested the new Drupal CMS 1.1.1 with this Drupal Geoimages Recipe ( https://www.drupal.org/project/drupal_cms_geo_images )
    implementing Drupal Core 11.1.7 and Drupal Leaflet 10.3.0 ... and all looking good also there, on Leaflet Popups via Ajax.
    I am attaching screenshots of this test case of mine ...

    SO please, try to replicate this valuable General Test Case autonomously,
    simply reproducing that Recipe Instructions (with its Step 1, 2 and 3)
    and eventually upgrade the Drupal Leaflet module at its very end, with:
    ddev composer require 'drupal/leaflet:^10.3'

    I have the strong feeling that your specific Drupal instance setup is breaking somehow the JS workflow, and somehow not properly loading / requiring the core/drupal.ajax library.
    It looks that you already checked the Js console ... but you should also inspect why that is happening.

    It looks still you are the one (among thousand of Leaflet module adoptions and adopters) reporting this issue ...
    Thus I am closing this for now as "Cannot reproduce".
    BUT feel free to re-open this if you find (and can provide objective) strong evidence of a more general use case of the issue that you report.

    Regards

  • Itamair I don't know why the examples that you have verified do not show this error, maybe they have the core/drupal.ajax dependency already loaded from other modules or themes.

    BUT I would not have reported this bug if I wouldn't have verified that it really happens. It happens on the sites that I am developing and at first I thought it was due to some local misconfiguration. This is why I have tested several combinations of simplytest.me, on a clean drupal an only the two needed modules: geofield and leaflet.

    I have just checked again on simplytest.me using Drupal 11.1.8 and the two needed modules: geofield and leaflet and these are the steps to reproduce:

    I have enabled the leaflet view submodule, added the geofiled to the article node type and added two articles with geo info.

    Then I went to views and I added a new page using the leaflet. I must say that the preview in the views definition works OK, most probably since the drupal.ajax library is necessary for views and of course already loaded.

    Saving the view and going to the actual page there are two javascript errors, one for the logged in user:

    Uncaught TypeError: Node.appendChild: Argument 1 does not implement interface Node.

    And one for the anonymous user, as stated before:

    Uncaught TypeError: Drupal.ajax is not a function.

    In BOTH cases the popup will NOT load. Also I have done this test on two computers, three browsers.

    Please see the screenshots of everything that I have stated above.

    If I am doing something wrong please tell me, but the view is defined OK since it works in the preview (admin theme). It does NOT work however on the default Olivero theme, at least on simplytest.me.

  • 🇮🇹Italy itamair

    @devarch I checked your screenshots and read your last report,
    so I was persuaded to further test all this, and try to reproduce your very clean Drupal 11 use case.

    thus I simply replicated this basic Drupal 11 installation process:
    https://www.drupal.org/docs/getting-started/installing-drupal/install-dr...

    and I only enabled the Leaflet module (with Geofield dependency of course)
    then I created a Geoplace content type with only a Geofield, etc.
    then generated a Leaflet View and set Leaflet Popup on Geoplace Default view with Ajax ...
    and everything still looking (and loading) good on Leaflet Ajax based Popups, and even showing nested Leaflet Formatter Maps,
    as you can see in the newly attached screenshot of mine (that doesn't report any js console error/alert, nothing ...).

    Indeed the core/drupal.ajax library is (still) loaded with this very basic Drupal 11 clean setup, indeed without any other contrib module or theme added and enabled, just Olivero 11.1.8 (default theme) ...

    Sorry, I am not going to spend further checking time on this (as this is al free time from me), and also if still nobody else is going to step in here and confirm your issue.
    Thus please, rather than with SimpleTest, etc. try to replicate what I just did and described, with this basic Drupal 11 installation process
    and come back here with evidence of the bug source you could find.

Production build 0.71.5 2024