google is not defined

Created on 15 May 2018, about 6 years ago
Updated 11 February 2024, 5 months ago

Reproduction

Setup

  1. Install D8
  2. Install Google Map Field
  3. Install Paragraphs
  4. Create a Paragraph with a Google Map Field
  5. Create a Content Type containing that Paragraph as field
  6. Create content using the content type
  7. On the content form, try adding the paragraph

Expected

  • A paragraph containing Google Map Field appears
  • An initial map preview appears

Actual

  • No initial map preview appears on the widget (symptom)
  • "google is not defined" error appears in the console

What's happening

On Step 7, when Drupal tries to load a paragraph instance, Drupal sends down a bunch of commands to the browser (see attachment). By index item #2 (insert), Drupal appends a bunch of script tags to the page, in dependency order. By item #4 (insert), module behaviors are executed. The problem is that the Google Maps API script executes after the behaviors execute, causing references to "google" to blow up.

It might be because the scripts are appended dynamically, thus load asynchronously and execute out of order. This is not an issue when the field is loaded on page load (i.e. not using Paragraphs) since scripts are printed on HTML and will run in the correct order on page load.

Potential solution

Execute module scripts only after Google Maps API has executed by adding a callback. This ensures that it works for both synchronous and asychronously-loaded Google Maps API. See the Simple Map example.

πŸ› Bug report
Status

Closed: won't fix

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States fskreuz

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.69.0 2024