Problem/Motivation
When htmx swaps content, triggerDrupalBehaviorsFromHtmxEvent() looks for a
.display-builder ancestor and gives up when there is none. The side panels
live outside .display-builder in the DOM, so their content never gets
Drupal.attachBehaviors(). Any JavaScript behavior in a panel may never run:
an ajax button falls back to a native submit and the browser leaves the page
to /api/display-builder/..., dialogs never open. It looks intermittent
because another attach pass can still bind core ajax by element id.
This hits the new source selector from the ui_patterns issue #3528205: Performance: On-demand lazy-loading source selector: each prop has a button that opens a
dialog, both driven by behaviors. In the panel, the button triggers a navigation to the url instead of opening the dialog. But the bug is not specific to it: any behavior-based JavaScript in the panels seem affected.
Steps to reproduce
use code from ui patterns issue #3528205: Performance: On-demand lazy-loading source selector,
- Clear caches, open the display builder, select a component.
- In the right panel, click the button of a prop.
- The browser goes to /api/display-builder/... instead of staying on the page.
Proposed resolution
When the swap target has no .display-builder ancestor, still attach
behaviors, on the swapped element only:
if (!root) {
if (htmxLoadEvent.detail.elt) {
Drupal.attachBehaviors(htmxLoadEvent.detail.elt, drupalSettings);
}
return;
}
Issue fork display_builder-3622023
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
just_like_good_vibesComment #4
pdureau commentedHi, following our discussion today, do you need to check something here before review?
Comment #5
just_like_good_vibestested again, and seems better. Pierre, you had the bug because probably your island was the last one to load and the buttons never got their behavior attached at load, (the small actions you were making to restore the good behavior were provoking the behavior to be attached).
Comment #7
mogtofu33 commentedComment #8
mogtofu33 commentedBunch of bugs with the dialog, some small fixes on this MR, added issues for UI Patterns, with an opt-out issue for the dialog as this behavior is not UX friendly in Display Builder.
Comment #9
mogtofu33 commentedComment #10
just_like_good_vibeshello,
That issue and the MR i originally opened are pinpointing a missing piece inside display builder, about the triggering of behaviors, and this was independent of ui_patterns but triggered unfortunately by ui_patterns.
i don't understand why now the MR is becoming bigger and out of the initial scope?
what is the relation to "Bunch of bugs with the dialog", i don't understand?
Comment #13
mogtofu33 commented