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;
    }
Command icon 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

just_like_good_vibes created an issue. See original summary.

just_like_good_vibes’s picture

Assigned: just_like_good_vibes » mogtofu33
Status: Active » Needs review
pdureau’s picture

Assigned: mogtofu33 » just_like_good_vibes
Status: Needs review » Needs work

Hi, following our discussion today, do you need to check something here before review?

just_like_good_vibes’s picture

Assigned: just_like_good_vibes » mogtofu33
Status: Needs work » Needs review

tested 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).

mogtofu33 made their first commit to this issue’s fork.

mogtofu33’s picture

mogtofu33’s picture

Bunch 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.

mogtofu33’s picture

Status: Needs review » Needs work
just_like_good_vibes’s picture

hello,
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?

mogtofu33’s picture

Assigned: mogtofu33 » Unassigned
Status: Needs work » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.