Skip to content

Fix: Lightbox script enqueuing conflicts causing DataTables rendering failures #2450

@zackkatz

Description

@zackkatz

Summary

The lightbox provider's script enqueuing implementation was causing conflicts with DataTables rendering in certain situations. The issue stemmed from improper script registration/enqueuing patterns and direct HTML output that could interfere with other JavaScript components.

Problem Description

Root Cause

  1. Improper Enqueuing Pattern: Scripts were being enqueued during registration phase (wp_enqueue_scripts hook) instead of being registered first and enqueued when needed
  2. Direct Script Output: Using wp_print_scripts() and manual <script>/<style> tags instead of WordPress's inline script/style APIs
  3. Missing Validation: No checks for whether scripts were already enqueued, leading to potential duplicates
  4. Timing Issues: Scripts being printed at incorrect times could interfere with DataTables initialization

Impact on DataTables

In some situations, DataTables would fail to render when lightbox scripts were loaded with the following error due to improper script loading order:

[Error] TypeError: undefined is not an object (evaluating 'window.gvDTglobals[i]')

due to potential race conditions between lightbox and DataTables initialization.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions