Overview
When you click "Preview" in XB, you can see a preview of the page you're building, without the XB sidebars and canvas overlay, so you can click on the page's interactive elements. However, we disable clicking links to navigate away from the page entirely. We do this with Drupal.behaviors.xbDisableLinks.
However, Drupal behaviors only run after the page is initially loaded, and after Drupal AJAX operations complete. Drupal behaviors don't run when, for example, React components that are on the page re-render in response to a state change, such as when using the Navigation component in #3530958: Build a navigation code component.
Proposed resolution
Change xbDisableLinks from a Drupal behavior to a mutation observer (or any other technique for monitoring links that get added to the DOM). Or, keep the Drupal behavior but also add a mutation observer for catching subsequent links added outside of Drupal's AJAX operations.
User interface changes
Issue fork experience_builder-3535072
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 #2
balintbrewsComment #3
mglamanI think I hit this with a "simpler" scenario. I have a button link component within the slot of a another component. The page is then visited within the iframe. The problem does not occur if the button link is on its own and not in a slot.
Comment #4
mglamanOh, and this effects anything using dynamic code components – menus for example.
Comment #5
balintbrewsUnassigning as I'm not working on this right now, in case anyone would pick it up.
Comment #6
mglamanI've got a MutationObserver working, making MR shortly
Comment #8
mglamanComment #11
effulgentsia commentedClosed #3514481: The navigation prevention inside the preview doesn't always work for code components as a duplicate of this. That one was tagged as a stable blocker, so transferring that tag to here.
Comment #13
wim leersComment #14
bnjmnmI approved MR 1371 - it's a solid approach that doesn't require DOM vigilance. It's also more comprehensive as it covers keyboard interaction and submits. However, the issue is NR as this expanded functionality should probably get some e2e representation. You should be able to use the Cypress jQuery functionality to add a link to the preview iframe after it loads which would reproduce the scenario this fixes without having to deal with making a component do it.
jQuery('iframe[title="Page preview"]').contents().find("body").append(YOUR LINK[s] )Comment #15
mglamanTested new patch, works great
Comment #16
jessebaker commentedTest, written in Playwright, has been added now. I took the opportunity to also migrate all but one of the tests in
ui/tests/e2e/preview.cy.js. The remaining test is a bit more tricky so I've not attempted to migrate that here. I've renamed the file toui/tests/e2e/vh-units.cy.jsbecause it now specifically tests that one thing.Comment #17
wim leersComment #18
wim leersComment #19
bnjmnmThe solution I was already happy with, and the new tests look good 👍,.
Comment #20
lauriiiComment #22
jessebaker commented