Uncaught ReferenceError: L is not defined
-
I’m using the GeneratePress theme which lets you create blocks outside of the standard page editor and then use them across the site, for example a footer.
See https://docs.generatepress.com/article/block-element-overview/
Your plugin works correctly in the editor but does not render on the frontend due to the following error: Uncaught ReferenceError: L is not defined
I can only guess that because the block that contains the map is part of an Element for GeneratePress (rather than on a proper page) then the Leaflet library isn’t loaded.
Looking at your plugin’s code it looks like the part with
is_singular
andhas_block( 'map-block-leaflet/map-block-leaflet' )
— because the block is not part of the page but rather part of an element then it does not load the JS/CSS.I understand this is an edge case but there might be other block editors where your map element is loaded “outside” of a page and your hook to load the frontend scripts won’t trigger, so just a heads up ??
I’ve managed to fix it by editing your plugin and calling
map_block_leaflet_enqueue_external_assets
insideleaflet_map_block_frontend_scripts
without any conditional logic.
- The topic ‘Uncaught ReferenceError: L is not defined’ is closed to new replies.