AJAX pager in content block rendered through layout builder not working

Created on 11 July 2024, 6 months ago
Updated 17 July 2024, 5 months ago

Problem/Motivation

When rendering an AJAX view through a custom content block (not an inline block) in a Layout Builder layout, the AJAX functionality does not work.
The view container is missing the data-once="ajax-pager" attribute.
Rendering the same block through any other method (in a region, through Twig Tweak using {{ drupal_entity("block_content", id) }}, etc) works as intended. The only failing case is through Layout Builder.

Steps to reproduce

  1. Install Block, Block Content, Taxonomy, Views, Views Reference Field, and Layout Builder
  2. Create a view with AJAX enabled and a full pager
  3. Create a custom block type with a Views Reference Field
  4. Add a custom block using the custom block type with the Views Reference Field and reference the AJAX view
  5. Create a vocabulary and add a term
  6. Enable Layout Builder for the vocabulary
  7. Edit the layout and add the custom block referencing the view with the AJAX pager
  8. Try to use the pager and observe the AJAX not working
πŸ› Bug report
Status

Closed: works as designed

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States FrankieD3

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

Comments & Activities

  • Issue created by @FrankieD3
  • πŸ‡¬πŸ‡§United Kingdom scott_euser

    Can I check if you are on the 8.x-2.x dev branch and you have https://www.drupal.org/project/viewsreference/issues/3396530 ✨ Views reference results in 414 if many options set and ajax used Needs review in your code? I think it might be related, spotted the regression, test coverage not good enough, just working on solution now.

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

    If so I think πŸ› Regression introduced in "Views reference results in 414 if many options set and ajax used" Active might solve it for you. Just improve test coverage for that.

  • πŸ‡ΊπŸ‡ΈUnited States FrankieD3

    I am on the suggested 8.x-2.0-beta8 branch. I've given the patch a try, but as expected, it didI am on the suggested 8.x-2.0-beta8 branch. I've given the patch a try, but as expected, it did not apply. not apply.

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

    I just tried to reproduce this and my pager seems to work fine. Any JS console errors or anything in /admin/reports/dblog for example?

  • πŸ‡ΊπŸ‡ΈUnited States FrankieD3

    No, none! It's a strange case. I can render the same block containing the view on a page multiple times through multiple methods, and the only one NOT to receive the AJAX behavior is the one rendered through Layout Builder.
    I'm not sure what else I can provide, but I will gladly give any information I can. Perhaps this is a core issue, or an issue elsewhere?
    All I can glean from this is that the Once call for ajax-pager isn't running on that specific view. Apologies for not having much else to go on!

  • πŸ‡ΊπŸ‡ΈUnited States FrankieD3

    Revisiting my issue this week, I believe it goes deeper than this module.
    I'm a bit befuddled, especially given you can't reproduce it. It seems that any view I attempt to render through a content block placed with Layout Builder does not attach the associated data needed within #attached.
    Since you can't reproduce the issue, where do you suggest I go from here?

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

    For anyone to be able to take action you'd need to show doing it in a clean drupal 10.3 or 11 install with the latest version of the module(s) in question. Would suggest you start with e.g. just Core and this to limit any side effects. Others won't be able to narrow down your issue otherwise.

    If you are able to code yourself, if you are confident it's this module, try comparing the viewsreference data in layout builder vs not layout builder in the viewsreference.module file's pre render and pre view methods e.g. with devel to see if you can spot the difference. Try also the two field formatters provided, maybe seeing if one or the other formatter solves (e.g. swapping in manage display), and again you could check whether the data there differs between working and not working.

  • πŸ‡ΊπŸ‡ΈUnited States FrankieD3

    I was able to reliably reproduce the issue through a fresh ddev install. Hopefully this will be a bit clearer than my first attempt.

    Leaving out the standard steps to create a new ddev Drupal install, I spun it up with the following config:

    ddev config --project-type=drupal --php-version=8.3 --docroot=web
    ddev composer create drupal/recommended-project:^10
    ddev composer require drush/drush drupal/viewsreference:^2.0@beta
    

    Most of what I had mentioned in the IS was pre-installed, so that cuts down on installs.

    1. Install Layout Builder and Views Reference Field
    2. Create four Article nodes, only populating the title fields
    3. Create a content view with no filters, enable a full pager with two items per page, and enable AJAX
    4. Create a block type and add a Views Reference Field, leaving the default settings
    5. Navigate to /admin/content/block and add a content block, referencing the previously created AJAX view
    6. Create a new vocabulary and enabled Layout Builder for the default display
    7. Manage the layout of the vocabulary, adding a new section containing the previously created block
    8. Add a term to the vocabulary, only populating the title
    9. Navigate to the new term and use the rendered view's pager

    The view uses the standard non-AJAX pager, loading a new page with the page query parameter appended to the URL.

    Following these steps I was able to reliably reproduce the issue multiple times.

    My next step will be digging through the hooks you mentioned in viewsreference.module.

    Thank you for your patience!

  • Status changed to Closed: works as designed 5 months ago
  • πŸ‡ΊπŸ‡ΈUnited States FrankieD3

    This does appear to be a core issue. It just so happens that Views Reference Field is what exposed it. Continuing in #3461890 πŸ› AJAX views pager not working when rendered through layout builder Active Thanks!

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

    Interesting one, good sleuthing! Will follow that issue as I'm curious where it leads.

Production build 0.71.5 2024