Refactor BigPipe to use HTMX

Created on 23 May 2025, about 2 months ago

Problem/Motivation

BigPipe is a primary user of the Ajax API. To gain a common understanding of how we can use HTMX in Drupal, we will refactor BigPipe to use HTMX

Proposed resolution

TBD

Remaining tasks

TBD

User interface changes

No UI features in BigPipe.

Introduced terminology

None

API changes

TBD

Data model changes

TBD

Release notes snippet

๐Ÿ“Œ Task
Status

Active

Version

11.0 ๐Ÿ”ฅ

Component

big_pipe.module

Created by

๐Ÿ‡บ๐Ÿ‡ธUnited States fathershawn New York

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

Merge Requests

Comments & Activities

  • Issue created by @fathershawn
  • First commit to issue fork.
  • Merge request !12230Resolve #3526267 "ajax commands with htmx" โ†’ (Closed) created by nod_
  • Pipeline finished with Failed
    about 2 months ago
    Total: 586s
    #506139
  • Merge request !12255Draft: htmx.swap() placeholders โ†’ (Closed) created by fathershawn
  • Pipeline finished with Failed
    about 2 months ago
    Total: 128s
    #507788
  • Pipeline finished with Failed
    about 2 months ago
    #507816
  • Pipeline finished with Canceled
    about 2 months ago
    Total: 131s
    #507835
  • Pipeline finished with Failed
    about 2 months ago
    Total: 534s
    #507836
  • Pipeline finished with Canceled
    about 2 months ago
    Total: 97s
    #508139
  • Pipeline finished with Failed
    about 2 months ago
    Total: 487s
    #508140
  • Pipeline finished with Canceled
    about 2 months ago
    Total: 299s
    #508187
  • Pipeline finished with Success
    about 2 months ago
    Total: 537s
    #508193
  • Pipeline finished with Canceled
    about 2 months ago
    #508265
  • Pipeline finished with Success
    about 2 months ago
    #508277
  • Pipeline finished with Failed
    about 2 months ago
    #508304
  • Pipeline finished with Failed
    about 2 months ago
    #508327
  • Pipeline finished with Success
    about 2 months ago
    #508342
  • ๐Ÿ‡ซ๐Ÿ‡ทFrance nod_ Lille

    It's green:)

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States fathershawn New York

    All green is super - nice work! This is direction really simplifies the changes in big_pipe.js and thatโ€™s a real plus.

    Because bigPipe as we have it re-uses existing javascript from the ajax system, to remove the ajax system we need to replace that.
    @nod_ had this list in a Slack discussion:

    We need the equivalent of those 3 commands to implement bigpipe

    • use Drupal\Core\Ajax\MessageCommand;
    • use Drupal\Core\Ajax\RedirectCommand;
    • use Drupal\Core\Ajax\ReplaceCommand;
    • Add_css/add_js and the settings but thatโ€™s mostly available already

    I think we need to identify the pieces of this list that htmx is not going to do, and implement those in general scope. Then the items that htmx does just fine in an ajax context, we need to have as helper methods in big_pipe.js and leverage the htmx api where we can.

    I'm going to take them in order.

    MessageCommand
    In the ajax context, I would have implimented this in HTMX using a header and a custom event handler that calls our Drupal.Message function. This is actually the example in the trigger headers documentation.

    HX-Trigger: {"showMessage":{"level" : "info", "message" : "Here Is A Message"}}
    

    One thing that Drupal.Message does client-side is determine the selector for the message container. If there is a way to do that server-side then this could also be implemented as an extra out-of-band swap on the response without any additional javascript.

    We do need a helper method for this that we can use in big_pipe though.

    RedirectCommand
    HTMX has both the HX-Redirect and HX-Location response headers. We don't have a response so we need a function for that in bigPipe.

    ReplaceCommand
    We also just need the bigPipe use case for bigPipe. This is one of the core competencies of htmx in an ajax request context.

    addCSS and addJS
    In the ajax context using htmx, these feel like out of band swaps as well.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States fathershawn New York

    fathershawn โ†’ changed the visibility of the branch 3526267-bigpipe-with-htmx to hidden.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States fathershawn New York
  • Pipeline finished with Failed
    about 2 months ago
    Total: 143s
    #509289
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States fathershawn New York

    Here's an MR into @nod_'s branch moving the bigPipe command JS into bigPipe scope. It looks like the test setup scripts don't like MR's into a feature branch. The tests generally pass locally - 2 failures involving noJS exceptions. Not sure if that's a false negative as all of these changes are in JS.

    If this is an acceptable direction then I think the next level of refactoring is to create the needed bigPipe Command classes to replace the AjaxCommands and update BigPipe.php to work without the Ajax API classes.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States fathershawn New York
  • Merge request !12295Htmx swap placeholders from templates โ†’ (Closed) created by fathershawn
  • Pipeline finished with Failed
    about 1 month ago
    Total: 138s
    #511431
  • Pipeline finished with Failed
    about 1 month ago
    Total: 632s
    #511506
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States fathershawn New York

    I still need to deal with Messages and Redirects, but this approach is simpler and over a 10 request sample results in a mean time of Load of 178.6 ms compared to 185.4 ms for the existing 11.x branch.

  • Pipeline finished with Failed
    about 1 month ago
    Total: 510s
    #512200
  • Pipeline finished with Success
    about 1 month ago
    Total: 7471s
    #512133
  • Pipeline finished with Failed
    about 1 month ago
    Total: 231s
    #515961
  • Pipeline finished with Failed
    about 1 month ago
    Total: 228s
    #517051
  • Pipeline finished with Failed
    about 1 month ago
    Total: 643s
    #517073
  • Pipeline finished with Failed
    about 1 month ago
    Total: 481s
    #518845
  • Pipeline finished with Failed
    about 1 month ago
    Total: 760s
    #519126
  • Pipeline finished with Failed
    about 1 month ago
    Total: 1132s
    #519558
  • ๐Ÿ‡ซ๐Ÿ‡ทFrance nod_ Lille

    I'll close my branch that replace commands execution code with a htmx-powered code. This issue is way too late for 11.2 so let's try to do it properly for 11.3 :)

  • Pipeline finished with Failed
    about 1 month ago
    Total: 456s
    #519581
  • Pipeline finished with Failed
    about 1 month ago
    Total: 432s
    #519593
  • Pipeline finished with Failed
    about 1 month ago
    Total: 98s
    #519597
  • Pipeline finished with Failed
    about 1 month ago
    Total: 635s
    #519602
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States fathershawn New York
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States fathershawn New York
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States fathershawn New York
  • Pipeline finished with Failed
    about 1 month ago
    #521719
  • Pipeline finished with Failed
    about 1 month ago
    #521909
  • Pipeline finished with Failed
    about 1 month ago
    #521912
  • Pipeline finished with Failed
    about 1 month ago
    #521916
  • Pipeline finished with Canceled
    29 days ago
    Total: 407s
    #522800
  • Pipeline finished with Failed
    29 days ago
    Total: 514s
    #522803
  • Pipeline finished with Failed
    29 days ago
    Total: 604s
    #522811
  • Pipeline finished with Failed
    28 days ago
    Total: 224s
    #523430
  • Pipeline finished with Failed
    28 days ago
    #523436
  • Pipeline finished with Canceled
    28 days ago
    #523455
  • Pipeline finished with Failed
    28 days ago
    #523456
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States fathershawn New York

    `BigPipeRegressionTest::testMessages_2712935` is now passing

  • Pipeline finished with Running
    28 days ago
    #523765
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States fathershawn New York

    BigPipeRegressionTest is now completely passing.

  • Pipeline finished with Failed
    28 days ago
    Total: 535s
    #523787
  • Pipeline finished with Failed
    28 days ago
    Total: 703s
    #523797
  • Pipeline finished with Canceled
    28 days ago
    Total: 267s
    #523804
  • Pipeline finished with Success
    28 days ago
    Total: 535s
    #523809
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States fathershawn New York

    All tests green!

    If this approach is good we should open an issue to theme individual messages to provide a server side way for themes to specify message markup

  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom catch

    Haven't reviewed the MR yet but there's a longstanding existing issue with AJAX messages here ๐Ÿ› AJAX MessageCommand markup and styling differs from Theme default Active where either a drupalSettings or template approach is being looked at to allow server-side rendering of the markup. BigPipe is currently the most common way that messages get added to the page by MesssagesCommand (since 10.3) which caught out a lot of themes that weren't theming js messages ( ๐Ÿ› 10.3 upgrade now missing status-message theme sugestions Active ).

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States fathershawn New York

    Thanks for the issue link in #22 @catch! I'll go there and chime in!

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States fathershawn New York

    Please add credit for @jrockowitz and @richgerdes who collaborated on test refactoring at the DrupalNYC Contribution Day

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States jrockowitz Brooklyn, NY
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States richgerdes New Jersey, USA
  • ๐Ÿ‡ซ๐Ÿ‡ทFrance nod_ Lille

    credit

  • Pipeline finished with Failed
    27 days ago
    Total: 183s
    #524577
  • Pipeline finished with Failed
    27 days ago
    Total: 607s
    #524590
  • Pipeline finished with Failed
    27 days ago
    Total: 791s
    #524781
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States fathershawn New York

    I posted in ๐Ÿ› AJAX MessageCommand markup and styling differs from Theme default Active and ๐Ÿ› 10.3 upgrade now missing status-message theme sugestions Active proposals that would simplify the work in this issue.

  • Pipeline finished with Failed
    26 days ago
    Total: 561s
    #525342
  • Pipeline finished with Failed
    26 days ago
    Total: 956s
    #525584
  • Pipeline finished with Failed
    26 days ago
    Total: 601s
    #525597
  • Pipeline finished with Canceled
    26 days ago
    Total: 306s
    #525605
  • Pipeline finished with Failed
    26 days ago
    Total: 778s
    #525608
  • Pipeline finished with Failed
    25 days ago
    Total: 175s
    #526227
  • Pipeline finished with Failed
    25 days ago
    Total: 868s
    #526268
  • Pipeline finished with Failed
    25 days ago
    Total: 520s
    #526284
  • Pipeline finished with Failed
    24 days ago
    Total: 575s
    #527516
  • Pipeline finished with Failed
    24 days ago
    Total: 429s
    #527527
  • Pipeline finished with Failed
    23 days ago
    Total: 535s
    #528054
  • Pipeline finished with Failed
    23 days ago
    Total: 615s
    #528070
  • Pipeline finished with Failed
    23 days ago
    Total: 1135s
    #528153
  • Pipeline finished with Canceled
    23 days ago
    Total: 559s
    #528180
  • Pipeline finished with Failed
    23 days ago
    Total: 487s
    #528187
  • Pipeline finished with Failed
    22 days ago
    Total: 633s
    #528456
  • Pipeline finished with Success
    21 days ago
    Total: 4032s
    #529518
  • Pipeline finished with Failed
    21 days ago
    Total: 207s
    #529575
  • Pipeline finished with Failed
    21 days ago
    Total: 269s
    #529600
  • Pipeline finished with Failed
    21 days ago
    Total: 101s
    #529609
  • Pipeline finished with Failed
    21 days ago
    Total: 653s
    #529612
  • Pipeline finished with Success
    20 days ago
    Total: 617s
    #530102
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States fathershawn New York
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States fathershawn New York

    I think the only unresolved feedback relates to message theming and swapping. I would propose that those are handled in the related issues on message theming.

  • ๐Ÿ‡ฆ๐Ÿ‡บAustralia larowlan ๐Ÿ‡ฆ๐Ÿ‡บ๐Ÿ.au GMT+10

    I took a look at the current MR here, and also MR 12295. With the current MR, I'm concerned about the number of changes needed in the BigPipe PHP code, but also the need to recreate the message handling.
    Looking at MR 12295 it looks much more isolated to just the handling of AJAX commands.

    Is it an option to split this work into smaller, more-reviewable chunks? And if so could we start by re-opening12295 and getting that in? I think that reduces the amount of changes needed and increases our chances of moving forward here.

    Thanks for working on this

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States fathershawn New York

    fathershawn โ†’ changed the visibility of the branch htmx-swap-placeholders2 to hidden.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States fathershawn New York

    fathershawn โ†’ changed the visibility of the branch 3526267-big-pipe-scope to hidden.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States fathershawn New York

    @larowan I've updated the issue summary to give an overview of how we got to where we are and the scope of MR-12295, which is our current MR. This MR combines work that @nod_ and I each did.

    \Drupal\big_pipe\Render\BigPipe and clientside code are strongly connected so it is difficult to tease this apart. However, there is strong test coverage for BigPipe and we went through iterations to pass the tests.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States fathershawn New York
  • Merge request !12576Resolve #3526267 "Htmx ajax framework" โ†’ (Open) created by nod_
  • Pipeline finished with Failed
    13 days ago
    Total: 475s
    #536538
  • Pipeline finished with Success
    13 days ago
    Total: 706s
    #536544
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States fathershawn New York

    MR-12476 communicates to me that I did not understand the limited scope of this issue. I understood that our goal here was remove the dependency between BigPipe and the existing Ajax API. @larowan has stated that to be too much change and @nod_ proposes to leave the dependencies between BigPipe and the four Ajax classes.

    My question then is what is the plan and time line to remove these dependencies?

  • Pipeline finished with Failed
    12 days ago
    Total: 494s
    #537242
  • My question then is what is the plan and time line to remove these dependencies?

    I haven't been following this issue closely, but speaking generally: often in situations like this, remaining work gets split off into follow ups. Reducing scope in individual issues makes the diffs smaller, easier to review, and more likely to be committed.

  • Pipeline finished with Failed
    12 days ago
    Total: 608s
    #537259
  • ๐Ÿ‡ซ๐Ÿ‡ทFrance nod_ Lille

    @fathershawn you didn't misunderstand, I think I didn't explained it clearly enough.

    My initial plan was quick and dirty: do the replacement of the ajax commands only so we can get that done quickly and move on. When you added your MR that went with a more HTMX way of doing it, it looked interesting: changing ajax commands for a meta header and raw HTML looked like a great improvement, and you were really involved in making it work so I though it'd be good to try it out. It started to get hard with asset handling and messages. To make it work in that new way the changes and compromises started to become too much for comfort. After chatting with larolwan and catch we figured the less user-disrupting way to go about it was to do the initial quick and dirty implementation. That way if something breaks, we know it comes from a mismatch between what we expect and how htmx does things, because it's the only thing we changed.

    Bigpipe is not broken, if we change the data format, how the data is sent or processed we risk breaking it in ways that are not obvious. Check out the history on the big_pipe.js file, there has been many fixes after we moved to the mutation observer handling, it took many years to find the bugs and fix them. I don't want to add more work on this area when there are other things broken we could work on.

    Dealing with how messages are handled is going to be easier and less stressful when the change is by itself, not blocking a big feature MR. I second @godotislate assessment the smaller the diff the more likely it is to get committed quickly.

  • Pipeline finished with Success
    12 days ago
    Total: 384s
    #537292
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States fathershawn New York

    Thanks @nod_ for the clear explanation. :)

    I'm happy to have learned about the internals of our BigPipe implementation. It was also worthwhile to understand how to remove the dependencies on the PHP side and that if we are to move to an HTML based approach, we need a way of rendering individual messages.

    +1 for removing the ajax dependency on the client-side. I'm going to update the issue summary with some of what you wrote and change the issue title to reflect the scope.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States fathershawn New York
  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom catch

    We should open an explicit follow-up to un-AJAXify the PHP side. I think ๐Ÿ› AJAX MessageCommand markup and styling differs from Theme default Active might cover the messages issue, but does that need an HTMX equivalent or should try to fix that for AJAX and then use the same technique for HTMX?

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States fathershawn New York

    Follow-up issue to "un-AJAXify the PHP side" created and linked in the sidebar

  • The Needs Review Queue Bot โ†’ tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

    This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

    Consult the Drupal Contributor Guide โ†’ to find step-by-step guides for working with issues.

  • ๐Ÿ‡ซ๐Ÿ‡ทFrance nod_ Lille
  • Pipeline finished with Failed
    2 days ago
    Total: 502s
    #545827
Production build 0.71.5 2024