Errors with the Babylon JS loading and the Drupal admin JS

Created on 11 April 2025, 18 days ago

Problem/Motivation

When the Viewer 3D module is enabled, Drupal core JavaScript functionality breaks across the site. This affects elements like the admin toolbar menu and other JavaScript-driven UI elements. No JavaScript errors are visible in the console, but JavaScript functionality simply stops working, rendering the admin interface difficult to use.

This issue was discovered after applying the patch from issue #3518609 πŸ› Fix Composer integration for Babylon.js libraries Active .

Steps to reproduce

  1. Install a clean Drupal site
  2. Apply the patch from issue #3518609 πŸ› Fix Composer integration for Babylon.js libraries Active
  3. Enable the Viewer 3D module
  4. Navigate to admin pages
  5. Observe that JavaScript-powered UI elements like the admin toolbar aren't working properly

Proposed resolution

After investigation, two primary issues were identified that need to be fixed:

Issue 1: Global Library Attachment

The module attaches the Babylon.js library to every page through hook_page_attachments(), regardless of whether the 3D viewer is present on the page. This causes unnecessary JavaScript loading and potential conflicts with core JavaScript.

Fix: Modify the module to only load its libraries on pages where the 3D viewer is actually used, likely by using a more specific hook or conditions.

Issue 2: Incorrect Event Listener Implementation

In viewer_3d_color.js, there's an immediate execution issue with the DOMContentLoaded event handler:

document.addEventListener("DOMContentLoaded", canvasRender());

This is calling the function immediately rather than setting it as a callback.

Fix: Correct the event listener implementation to properly defer execution until DOM is ready:

document.addEventListener("DOMContentLoaded", canvasRender);

Remaining tasks

  1. Create a patch that addresses Issue 1 (selective library loading)
  2. Create a separate patch that fixes Issue 2 (JavaScript event handling)
  3. Test both fixes to ensure they resolve the JavaScript conflicts without breaking the module's functionality

User interface changes

None

API changes

None

Data model changes

None

πŸ› Bug report
Status

Active

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States camoa

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

Comments & Activities

Production build 0.71.5 2024