0

I have a custom module, filter_component, that provides a form. In the form I have:

$form['#attached']['library'][] = 'filter_component/filter-component';

In filter_component.libraries.yml I have:

filter-component:
  version: 1.x
  js:
    js/filter_component.js: {}
  dependencies:
    - core/jquery
    - core/jquery.once

filter_component.js begins with:

(function ($, Drupal) {
    Drupal.behaviors.filterComponent = {
        attach: function (context, settings) {
            $('.block-filter-component', context).once('filterComponent').each(function() {

Everything works fine, but only if big_pipe is disabled. When it is enabled, the code is not attached and the js file is not listed in page source or in browser tools as a source.

9
  • Try to remove the .once part.
    – user72672
    Dec 19, 2019 at 23:35
  • 1
    The content of the library doesn't matter. If you see the form and not the library then there is something wrong with how the form was rendered, for example too early.
    – 4uk4
    Dec 20, 2019 at 13:25
  • Yes. What I would like to know is why big pipe is the variable in that happening.
    – JAyenGreen
    Dec 20, 2019 at 14:39
  • FWIW I tried adding scope:footer to the js entry in libraries, no difference.
    – JAyenGreen
    Dec 20, 2019 at 15:00
  • You don't tell how you render the form.
    – 4uk4
    Dec 20, 2019 at 17:04

1 Answer 1

0

So it turns out that it was big pipe, but unrelated to my module. Elsewhere on the page a profile image is loaded to appear next to the user name, and if the user has none, a default image. It seems that if a 404 is returned (in this case because part of the oath did not yet exist to match the path supplied for the image), when big pipe goes to load it and gets the 404, downstream js is not loaded.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.