Problem/Motivation
I'm seeing this error in our project CI with drupal dialogs:
Error: cannot call methods on dialog prior to initialization; attempted to call method 'option'
This happens, when opening and immediately closing a modal (very fast).
Steps to reproduce
It's quite easy to reproduce with any modal and some JS code:
- click button to open modal,
- wait for .ui-dialog element to exist/be visible,
- and immediately close modal with cancel/close button.
The MR contains a test to reproduce.
If needed here is a sample JS code:
function waitForElement(selector) {
return new Promise(resolve => {
if (document.querySelector(selector)) {
return resolve(document.querySelector(selector));
}
const observer = new MutationObserver(mutations => {
if (document.querySelector(selector)) {
observer.disconnect();
resolve(document.querySelector(selector));
}
});
observer.observe(document.body, {
childList: true,
subtree: true
});
});
}
document.querySelector('{open modal button selector}').click();
waitForElement('.ui-dialog').then((dialog) => {
dialog.querySelector('{close button selector}').click();
});Proposed resolution
It seems that in such cases, Drupal.dialog.resetSize is called from debounce after the jquery dialog instance has been destroyed. This happens within 20ms (debounce/setTimeout interval).
Add a check ensuring we have a valid jquery dialog instance at the top of Drupal.dialog.resetSize.
Remaining tasks
?
User interface changes
None
Introduced terminology
None
API changes
None
Data model changes
None
Release notes snippet
None
| Comment | File | Size | Author |
|---|---|---|---|
| #9 | 3472624-nr-bot.txt | 1.05 KB | needs-review-queue-bot |
Issue fork drupal-3472624
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
herved commentedComment #4
herved commentedComment #5
herved commentedMoving to needs review, thanks.
PS: It seems nightwatch has intermittent failures these days, phpunit as well
Comment #6
herved commentedLinking #3356667: Error: Cannot read properties of undefined (reading 'settings') with dialog.position.js as possibly related (but not quite).
Comment #7
smustgrave commentedMay be able to help decide the solution.
Comment #8
herved commentedI believe #2856047: Avoid random failures in JavascriptTestBase when testing functionality in a dialog is also related, as I mentioned in #6.
Comment #9
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #10
smustgrave commentedFalse positive
Comment #11
saidatomGreat! It looks good, moving to RTBC.
Comment #12
dxvargas commentedI just want to confirm the RTBC.
The new version of the MR, after the last two commits managed to fix the problems in the pipeline I had before.
Comment #13
claudiu.cristeaComment #14
nod_I can't seem to replicate the test failures. When I run the tests without the immediate and early return fix from the dialog.position.js file it's still green.
Comment #16
joseph.olstadWhile this patch deals with dialog
I was hoping it would also fix resizable
I'm seeing this one:
Using a theme (not claro) for a node form.
This worked up until Drupal 10.4.x
In Drupal 11 there's a js error related to the media dialog.
Comment #17
grimreaperHi,
I have the same problem on a D10.4, with CKE5 in Layout Builder offcanvas, on a text format with the drupal media and/or the icon (from ui_icons) plugins.
When I click on the media insert button or the icon insert button, the error is immediately present in the browser's console.
Comment #18
herved commented#17 Hi @grimreaper,
Yes I also noticed these errors get triggered with CKeditor: https://git.drupalcode.org/project/drupal/-/merge_requests/9440#note_398735
Is this MR here fixing your issue?
There is also #3356667: Error: Cannot read properties of undefined (reading 'settings') with dialog.position.js which relates closely to this, maybe the patch there is is the proper fix?
Comment #19
grimreaperHi @herved,
I tried the MR changes without success.
But those errors were not blocking me it was something else related to dialogs which I had not been able to identify.
Like events not triggerred or incorectly triggered (not the right element, stuff like that).
So I pass to something else for until now.
Comment #20
goz commentedHi, i have the same issue using ui_suite_bootstrap + layout_paragraphs + mercury_editor
In node edition with paragraph layout, start a new paragraph, choose a component (+ button), add your section paragraph in the first dialog, second dialog opened and error is logged in console
The MR does not solve this.
Comment #22
albeorte commentedThe current MR is not solving the problem.