Problem/Motivation

When using with Leaflet More Maps, Leaflet Demo page does not show maps. Upon inspection, in Console leaflet.drupal.js:829:7 throws Uncaught TypeError: can't access property "className", feature.icon is undefined

Steps to reproduce

Activate Leaflet, Leaflet More Maps and Leaflet Demo modules and visit the demo page at /admin/config/system/leaflet-more-maps/demo

Proposed resolution

The issue is in leaflet.drupal.js at line 829 - create_geometry_base_options is trying to read className.

className: feature.icon.className ? feature.icon.className.replaceAll(",", "") : '',

This crashes when feature.icon is undefined. The guard if (feature.icon) only happens after create_geometry_base_options is called (line 860), but create_geometry_base_options itself unconditionally accesses feature.icon.className at line 829.

The fix is a simple guard — change line 829 from:

className: feature.icon.className ? feature.icon.className.replaceAll(",", "") : '',

to:

className: feature.icon && feature.icon.className ? feature.icon.className.replaceAll(",", "") : '',

Comments

macmladen created an issue. See original summary.

macmladen’s picture

This patch solves the issue.

itamair’s picture

Status: Active » Closed (cannot reproduce)
StatusFileSize
new855.69 KB
new595.02 KB

Thanks @macmladen for reporting this,
BUT I can't reproduce your use case, though I tried.

With the following relevant stack:
Drupal Version: 11.3.2
PHP Version: 8.3
Leaflet module: 10.4.2
Leaflet More Maps module: 2.2.3

the Leaflet More Maps / Leaflet Demo demo page (at /admin/config/system/leaflet-more-maps/demo) renders correctly showing up the most of expected Leaflet Map (and Icons),
BUT those that cannot be loaded due to missing API Keys (such for MapBox, HERE, etc.).

See the attached screenshots.

It is right that the feature.icon is (could be) undefined at line 829, but that doesn't crash and is not a blocker for the consequent Js workflow: the options.className property is simply oncoming as empty string, and that's it.

I am this closing this as "Cannot Reproduce" (that also means "Works as designed").

Please reopen this eventually only if you can provide more (clearer) evidence of your js console logs and the block they determine, in JS workflow. Some screenshot would eventually help in providing that evidence ...

MBR

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

macmladen’s picture

Status: Closed (cannot reproduce) » Active
StatusFileSize
new92.46 KB

Ah @itamair my bad: I was rushing to share.

Try this configuration:
Drupal 10.6.3 (latest 10.x)
(everything else the same)

I just enabled More Maps

composer require drupal/leaflet_more_maps

installed Drupal and enabled modules

drush site:install --account-name=admin --account-pass=admin -y
drush en -y leaflet_demo leaflet_more_maps

After that, just visit the page /admin/config/system/leaflet-more-maps/dem and you get the picture I attached

D10 Leaflet Demo but no maps

macmladen’s picture

I just upgraded to Drupal 11, and I still get the same error.

I turned off aggregation, and I still get the error.

I cleared the browser cache and drush cr to no avail.

I am using Firefox, but I get the same (D11, aggregation off) with both the latest Chrome and Safari.

  • itamair committed 35ec1702 on 10.4.x
    fix: #3573817 Uncaught TypeError: can't access property "className",...
itamair’s picture

Status: Active » Fixed

ok @macmladen thanks again. You convinced me, also because I was finally able to reproduce it.
Your fix was committed (https://git.drupalcode.org/project/leaflet/-/commit/35ec17020d4c05219311...) into 10.4.x dev branch.
It is going to be part of new incoming 10.4.3 Leaflet module release.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.