Lazy builder attached

Created on 14 September 2023, about 1 year ago
Updated 18 September 2023, about 1 year ago

Problem/Motivation

Using #attached for library or drupalJs settings variables break the Lazy Builder. Nothing happened.

Steps to reproduce

public static function trustedCallbacks() {
    return ['LoadData'];
  }
public function LoadData($var) {
    $data = $this->dataTakeTime();
    $my_js_var = $data['specific_data'];
    $build = ['#theme' => 'custom_template', '#data' => $data];
    $build['#attached']['library'][] = 'my_module/my_library';
    $build['#attached']['drupalSettings']['myJsVar'] = $my_js_var;
    return $build;
  }

Lazy Builder is specially usefull to retreive complex data without blocking the page render.

For example, I used custom template with library and drupalSettings JS variable from slow API.

Any thought, suggestions will be very helpful !! Thank you.

πŸ’¬ Support request
Status

Active

Version

10.1 ✨

Component
RenderΒ  β†’

Last updated 7 days ago

Created by

πŸ‡«πŸ‡·France alumni

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

Comments & Activities

  • Issue created by @alumni
  • πŸ‡«πŸ‡·France alumni

    Edit : Have prefix and suffix in the build render array generate an error too.

  • πŸ‡¬πŸ‡§United Kingdom catch

    The actual render array adding the lazy builder might help here. Impossible to see what the issue is with the current code examples.

  • πŸ‡«πŸ‡·France alumni

    I need to precise that I have no problem with my others Lazy Builder.

    public static function trustedCallbacks() {
        return ['LoadData'];
      }
    
    public function LoadData($var) {
        $data = $this->dataTakeTime();
        $my_js_var = $data['specific_data'];
        $build = ['#theme' => 'custom_template', '#data' => $data];
        $build['#attached']['library'][] = 'my_module/my_library';
        $build['#attached']['drupalSettings']['myJsVar'] = $my_js_var;
        return $build;
      }
    
    //Partie DVF
      $variables['dvf'] = [
        '#create_placeholder' => TRUE,
        '#lazy_builder' => [
          Dvf::class.':LoadData',
          [$points[0]['lat'], $points[0]['lon']],
        ],
      ];
    
Production build 0.71.5 2024