Problem/Motivation
I posted this originally within the Gin Project but have since identified that Big Pipe is causing the oddity. In short on my 9.5 Beta2 site(s) when I have both Big Pipe and Gin Admin theme active on pages that use the bulk field checkbox form (like the people view, content view, etc) that input renders double or even triple at times. I have verified that this does not take place if you go into the view and check the preview, it only happens on the actual pages themselves.
Steps to reproduce
Install 9.5 Beta 2, Gin Admin theme and add a couple users, then visit the People View.
Does anyone have any suggestions? Everything seems to work but it looks stupid and confuses a few users that I have that aren't the brightest light bulbs.
Thanks in advance.
| Comment | File | Size | Author |
|---|---|---|---|
| #18 | leaflet_better_once_3314762-18.patch | 1.4 KB | itamair |
Comments
Comment #2
cilefen commentedCan we get a screenshot? Does this happen with Claro theme?
Comment #3
cilefen commentedIt helps to relate the issues. It may have been better to have moved the issue rather than to create another one.
Comment #4
Christopher Riley commentedNo it does not happen with Claro and sorry I hadn't thought about moving or linking it.
Comment #5
cilefen commentedIs this a Big Pipe bug or does Big Pipe expose a theme bug?
Comment #6
Christopher Riley commentedThat is a good question and if anyone could point me in a direction I would more than happy to try to debug it.
Comment #7
cilefen commentedClaro not exhibiting the bug is strong evidence.
Comment #8
olivierh65 commentedI'm not sure, but I just noticed that when BigPipe is activated, the javascript function "Drupal.attachBehaviors" is executed twice.
A first time by
And a second time by
To check it, it is enough to load a page, then in the console javascript of the navigator to seek "Drupal.attachBehaviors", put a breakpoint, then reload the page with F5
Comment #9
joao sausen commentedI'm having the same issue on Drupal 10.0.0 as olivierh65.
That piece of code that runs attachBehaviors on big pipe is useless since it runs after code attachBehaviors...
Comment #10
wim leersI'm 99% certain that this is another occurrence of #3337995: Big Pipe calls attachBehaviors twice — i.e. a bug in Gin's Drupal behaviors not using
once()correctly.Comment #11
saschaeggiIs it? @Joao Sausen & oliverh65 is this happening with Gin or another theme?
If so we can close it as a duplicate in favor of #3314515: Double rendering select all checkboxes
Comment #12
olivierh65 commentedThis behavior is not Gin specific.
I think it's a big pipe problem, as I've had this problem in leaflet module.
Comment #13
saschaeggiThen let's move this back to core 😉
Comment #14
saschaeggiComment #15
wim leersIt's starting to sound like a bug in the Leaflet module then actually 😅 Can you provide concrete steps to reproduce?
It's normal that
attachBehaviorsis called multiple times. Also see the discussion in #3337995: Big Pipe calls attachBehaviors twice.Just checked https://git.drupalcode.org/project/leaflet/-/blob/10.0.x/js/leaflet.drup... and I see:
… this is definitely incorrect. It should be using
once(). It doesn't use that anywhere in the JS file.It was correctly updated in https://git.drupalcode.org/project/leaflet/-/commit/73757ffd5e5565a606f6.... Looks like there's a history of breaking this: https://www.drupal.org/project/issues/leaflet?text=attachbehaviors&statu...
Comment #16
itamair commentedThank @Wim Leers for pointing that out,
but I believe that code in the Leaflet module is correct (and at least is not wrong).
The Leaflet module js is handling all the each defined Leaflet maps for the web page, and processing those settings/Leaflet maps accordingly.
We deliberately didn't want/need to use the once() pattern there ...
The Leaflet module already faced an issue related to Big Pipe causing double attachments, here: https://www.drupal.org/project/leaflet/issues/3337537
and this following comment explained how in more details: https://www.drupal.org/project/leaflet/issues/3337537#comment-14898998
I believe that is not the Leaflet module triggering double Drupal.attachBehaviours() execution ... but it is just facing, and properly reacting to it.
I also had evidence that disabling BIG Pipe stopped the double double Drupal.attachBehaviours() calls.
Leaflet module (since its 10.0.8 version) stopped loading its maps twice with Big Pipe thanks to this commit: https://git.drupalcode.org/project/leaflet/-/commit/a3caa11cb81d736971b4...
Please send me here better evidence that all this is indeed caused by the Leaflet module (that I couldn't see yet with your comment),
otherwise I will close this as "works as designed" ... or move this back to its original location (Drupal 9.5 Core)
Comment #17
wim leersNote that none of this is BigPipe-specific. It's just the Drupal AJAX system.
Correct, it's the AJAX system, which BigPipe uses.
Leaflet is indeed invoked to attach behaviors. But it's not reacting to this properly.
Quoting
Drupal.attachBehaviorsfromcore/misc/drupal.js:👆 It's that reprocessing that Leaflet does not handle correctly.
Interesting … 🤔
#3337537-4: Big Pipe changes causes multiple map attachments says:
Well, that's true, one should never use
once()on the entire document. Then this is indeed a logical consequence:You need to use the proper selector — see https://www.npmjs.com/package/@drupal/once, which says:
So for example
Drupal.behaviors.contextualdoes this:That means
'contextual-render'is the identifier of the behavior/processing you want to do only once,'[data-contextual-id]'is the selector to find the relevant elements andcontextis the root of the tree where you want to find elements matching that selector.The patch at #3337537-2: Big Pipe changes causes multiple map attachments did this though:
… which means it was selecting the
htmlelement … which selects the entire HTML document, so it's clearly not a selector matching every individual leaflet map!Hope it makes sense now 😊
P.S.: the demo at https://www.geodemocracy.com/drupal_geofield_stack_demo/web/geoplaces-ma... is REALLY cool! 🤩
Comment #18
itamair commentedcool! ... and super thanks for your great mentoring @Wim 😊
ket me test the attached patch, on some advance Leaflet use case (multiple leaflet maps in the same page, and added through IEF) and I will commit into dev and deploy a new release with this ...
Comment #20
itamair commentedOk. I successfully tested and QAed what has been committed into dev. I am going to deploy a new Leaflet 10.0.13 release with this.
Thanks again @Wim Leers for guiding me to this, that I am confident is a proper fix for this.