Problem/Motivation

Since #3252978: Large modal exceeds viewport height without scrollbar = actions unreachable, a setInterval() checks every 500ms if a dialog goes below the bottom of the window. If it does, it makes the dialog smaller and moves it to the center. So when a form gets bigger, the dialog moves up to 500ms later. A click at the moment the dialog moves can hit the overlay instead.

This makes our Behat tests fail at random: about 1 in 200 clicks on the dialog's Save button was lost (which made this issue very hard to trace).

Also, once the dialog is made smaller, it keeps that fixed height. jQuery UI ignores maxHeight when height is a number, so core's resizing no longer applies.

modal-height.cy.js does not find this problem. It waits 500ms, and should('be.visible') does not check the window. The test passes even with repositioning disabled.

Steps to reproduce

- Use a window that is not very tall.
- Open a component form and make it grow until the dialog goes below the bottom of the window, for example by expanding the Behaviors details element (present when the paragraph type has behavior plugins) or by letting CKEditor load.
- Part of the dialog stays off-screen. Up to 500ms later, the dialog jumps up.

Proposed resolution

- Use a ResizeObserver to move the dialog when its size changes, with no polling.
- Limit the height with maxHeight instead of a fixed height, so core can still resize the dialog.
- Update modal-height.cy.js so it fails without the fix.

Remaining tasks

Review.

User interface changes

None.

API changes

None.

Data model changes

None.

---
Debug and report assisted with the help of an LLM.

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

herved created an issue. See original summary.

herved’s picture

Status: Active » Needs review
alorenc’s picture

Some of our Layout Paragraphs dialogs have a lot of content and grow taller than the viewport, so they get resized. Rarely (about 1 in 100+ runs), one of our Behat tests failed because the dialog was repositioned by the 500ms interval just as the test clicked a checkbox inside it. With the patch, repositioning happens right after the resize instead of on a timer, and the failure no longer reproduces.

End users should not notice any difference: dialogs are still resized and re-centred as before.

alorenc’s picture

Status: Needs review » Reviewed & tested by the community

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

  • justin2pin committed acbf5a28 on 3.0.x authored by herved
    Issue #3629707: Reposition dialogs when their size changes instead of...
justin2pin’s picture

Status: Reviewed & tested by the community » 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.

justin2pin’s picture

Status: Fixed » Needs review

Re-opened an MR to add a small check to make sure the widget exists, since this fix will only apply to jQuery dialogs and will throw an error on non-jQuery implementations.

  • justin2pin committed 6cd47a11 on 3.0.x
    Issue #3629707: Reposition dialogs when their size changes instead of...
justin2pin’s picture

Status: Needs review » 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.