Problem/Motivation
Error accessing property of undefined, when resizing page with a dialog opened.
caught TypeError: Cannot read properties of undefined (reading 'settings')
at HTMLDocument.resetSize (dialog.position.js?v=10.0.8:85:32)
at later (debounce.js?v=10.0.8:37:23)
Steps to reproduce
- Open a page and open a dialog: in my case, I use Layout Builder and can reproduce this problem when configuring a block in page node layout
- With the dialog opened, resize the window
- Error shows up in console


Proposed resolution
By looking into the function resetSize(event) {… }
So it looks like the events parameter passed in this function are not the same. When resizing, they can be of type resize or type drupalViewportOffsetChange (called by debounce.js).
And if event is of type drupalViewportOffsetChange, data attribute is undefined, causing the error accessing event.data.settings

Remaining tasks
Confirm that this occurs on 11.x.
Update the MR to the fix that is to be reviewed.
User interface changes
N/A
API changes
N/A
Data model changes
N/A
Release notes snippet
| Comment | File | Size | Author |
|---|
Issue fork drupal-3356667
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
robert ngoComment #3
robert ngoComment #4
robert ngoComment #5
robert ngoComment #6
smustgrave commentedThanks for reporting.
As a bug it will need a test case showing the issue. Believe core has method for testing console errors.
Comment #7
anybodyJust ran into the same issue when uploading a file in a media within a modal. The result is a broken widget, which isn't usable anymore.
The ui-widget-overlay ui-front is blocking the UI.
Comment #8
anybodyIncreasing priority as of #7, but I'm wondering why we're the second ones experiencing this, might be caused by contrib.
Already removed all other patches to ensure it's not a patch braking this.
If it helps: This seems to happen since the upgrade to Drupal 10.1.1 and before this issue I see #3351600: ckeditor5.dialog.fix.js throws "Uncaught TypeError: event.target.classList is undefined" in Firefox in Drupal 10 with the editor in a modal in the console, which *might* be (un)related.
Changing the admin theme doesn't fix it. I use Gin and also tried Claro, but with the same results.
Comment #9
anybodyInteresting, just with disabling CSS / JS cache, clearing caches and coming back, the error in the console is gone, but I still see the
ui-widget-overlay ui-frontoverlay above the modals, blocking all editing, once a second modal is opened. So maybe this is unrelated? Super strange things going on...Comment #10
anybodyOkay in the end it turned out, that it was this issue for us: #3371179: Overlay blocking image upload modal in Drupal 10.1 still I dont know why this error in the console disappeared in #9. -.-
Comment #11
liquidcms commentedI am occasionally getting this on a D9.5.3 site. It was consistently working for many months but has recently been broken. Originally i thought it was only admin users using Firefox as it seemed to always work in Chrome or for non-admins. But just now i see the issue for a non-admin in Chrome.
This patch does not apply. Will try manual patch.
Comment #12
liquidcms commentedwith a very small sample size of testing (since it wasn't consistently occurring); this seems to have fixed the issue.
Comment #15
liquidcms commentedspoke too soon. With the fix from #2, i still see this issue.
Comment #17
vselivanovI had this issue with undefined and also similar with null with Drupal 10.1.5.
Added null check to the patch #2 and created MR.
But we still need a tests.
Comment #18
tim-dielsI'm also experiencing this when using AJAX requests in modals on Drupal 10.1.6.
But looking at the solutions provided in #2 and the MR it only masks the problem and does not solves it.
My use case:
Comment #19
3liSame as tim-diels I found that #2 & MR are simply ignoring the error and not solving the problem.
The issue I was finding is that the error is caused by failing to pass data over to the
resetSizefunction.I found if I removed the
debouncemethod the error went away and also for me the auto resizing of modal/dialog was happening upon load.I'm not totally sure how we can write tests for this though.
Comment #20
leksat commentedI don't understand why 😂 but #19 works 🎉
Comment #21
sundharI've reviewed patch #19, but unfortunately, it's not working for me. I made a few changes based on the guidance provided in this Stack Overflow answer.
Comment #22
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 #23
sundharBot changes updated in this patch.
Comment #24
smustgrave commentedMR appears to have failures.
Comment #26
catchJust had this reported on a site that's on 10.1. This is using the media widget on a media field (on a comment, not that this would matter) and only happens very intermittently.
Given the intermittent nature of the bug, I'm removing the 'needs tests' tag - we should double check we have test coverage for the media widget, but getting consistent steps to reproduce with core, that are then reproducible with functional javascript testing may not be possible here.
Rebased the MR so that it gets passed cspell, but it's now failing the tabbable shim nightwatch test which either indicates a bug or may need updating: https://git.drupalcode.org/project/drupal/-/jobs/1270916
Bumping back to major because this renders the media widget unusable with no workarounds and appears to be affecting other areas like layout builder too.
Comment #27
awearring commentedRe-rolled patch from #23 for D10.3
Comment #28
mutasim al-shoura commentedRe-rolled patch from #23 for D10.1
Comment #29
carlitus commentedI've tried with #27 with drupal 10.3 but doesnt work.
Comment #30
jesss commented#27 works for me on 10.3 in terms of resolving the console error and allowing other processes to run, but now the dialog modal is aligned right instead of centered. If I resize the browser window, it snaps back to being centered.
(I was running into this issue using the Footnotes plugin with CKEditor 5. The Footnotes modal would open, but the Link button within the Footnotes modal's WYSIWYG would not launch its dialog without this patch.)
Comment #35
carlitus commentedI've made a MR to change to put this:
Because with the old value the balloon was under and invisible. I'm using layout paragraphs, by the way, and now i can see the balloon when i click in the link button of ckeditor.
Comment #39
grevil commentedI don't quite get, why we have multiple MRs open here. MR !8892 is on current 11.x and ALMOST similar to MR !5266, but the most important change (removing the debounce call) is missing.
Since "MR !8892" is on current 11.x I'll just readd the changes of the old MR, and we get a working solution. :)
Comment #41
grevil commentedAlright, tests are failing. I asked in Slack, if the changes suggested here are going in the right direction. Let's wait for some feedback from them and overhaul the tests after a confirming feedback! 👍
Comment #44
grevil commentedAlright, "3356667-undefined-settings-dialog-position-simple-fix" contains a simple fix using the JS optional operator. Thanks to @_nod for pointing it out over @ Slack!
Works great and without much fuzz! Tests should also succeed. Please review!
Comment #45
anybodyGreat work all, thanks @Grevil! I just reviewed the changes and tested them, fix works as expected.
Should we add a comment to explain situations when
event.datacan be empty?Another option I would have liked code-wise is to return early, if
event.datais null and not execute theevent.data-related code at all. Setting this RTBC now for final discussions.Comment #47
grevil commentedJust had a look at the comments here and found out, that there was already a patch in #2 by @Robert Ngo, which has the same logic as the current MR !9070. It fixes the issue in our use case, but reading #18 and #19, it might not be enough for all use cases?
Should we create a follow-up issue regarding the withstanding issue described in #18 and #19? Or should we try and make their suggested changes (now part of MR !8892) get merged in core?
Unsure how to proceed here. Both patches work as a fix for our use case, but tests are failing for MR !8892 and the changes there are quite more drastic, then the ones in MR !9070.
Comment #48
nod_I need to look more closely at what's going on
Comment #49
grevil commentedThanks @nod_! 🙂
Comment #50
aolvera commentedI have tried all the patches and MRs of this issue and none of them work in Drupal 9.5.11.
I will try to investigate what I can in case I can shed some light :).
Comment #51
adiazRe-rolled patch from MR! 8892 for Drupal 10.2.x
Comment #52
jrockowitz commentedHere is patch for the latest MR.
Comment #53
smustgrave commentedNot sure which MR is to be reviewed now and there is a mix of patches now. Should be cleaned up some.
Comment #55
scott_euser commentedComment #56
scott_euser commentedBit of clean-up:
Comment #57
catchComment #58
grevil commentedThere is still no proper explanation on how simply removing the `debounce()` call (with some other minor changes) fixes this issue.
But it might be the correct approach! Let's see, what @_nod has to say.
(After feedback, we should put this back to NW, regarding the currently failing tests).
Comment #59
emircan erkul commented#19 for D9.5.11
Comment #60
nod_I'm struggling to reproduce this, any other cases where this happens?
Comment #61
grevil commented@nod_ you could reproduce it through #3465484: [Info] Upstream core: Uncaught TypeError: Cannot read properties of undefined (reading 'settings') when confirmation opens, if setting up commerce isn't too much effort! 👍
Comment #62
ajaysinh commentedUpdated patch for Drupal 10
Comment #63
ajaysinh commentedComment #64
mauhg commentedUpdated patch from #62 to Drupal 10.2
Comment #65
mauhg commentedComment #66
nikolay khomich commentedRe-rolled patch from #64 for D10.3
Comment #67
smustgrave commentedFixes should be in MRs
Comment #68
herved commentedI just encountered a somewhat related error in our project in CI: ...
Happens when (very) rapidly closing a dialog.
Edit: I created a dedicated issue #3472624: Error: cannot call methods on dialog prior to initialization; attempted to call method 'option' as I think it is different.
I'm surprized to see the debounce removed here though, aren't we loosing the repositioning/resizing of the dialog?
Comment #69
naveenvalechaHere's the patch rerolled based on #19 for Drupal core 10.3.5 site
Attaching it here if anyone needs it
Comment #70
vladimiraus#69 works for D10.3! thanks for the patch!
MR !8892 is ready for review for D11
Comment #71
letrollpoilu commentedSame here the patch works well for me on D10.3
Comment #72
shaxa commentedPatch from https://www.drupal.org/project/drupal/issues/3356667#comment-15753938 works for me on D10.2.8.
Comment #73
smustgrave commentedPer #67
Comment #74
ammaletu commentedIf anybody is trying to reproduce it: For me this error happens when I am in the webforms admin page and click on "Add a webform". A modal is opened. If I now resize the window (e.g. by pressing F12 and opening the developer tools), the JavaScript error occurs. Drupal 10.4.5 and current Firefox.
Comment #75
jessey commentedComment #76
bbralaEdited because LSEP character in title is no fun to handle when using the API and import the data into a neo4j database.
Comment #77
quietone commented@jessey, can you explain why you changed the version to 10.4.x? In Drupal core changes are made on on 11.x (our main development branch) first, and are then back ported as needed according to the Core change policies. Also mentioned on the version section of the list of issue fields documentation.
I am restoring the version and hiding all the patches.
The remaining tasks in the issue summary has 'none'. That is definitely not true. I remind everyone to keep the issue summary up to date to help everyone who is working on an issue. I updated it to say that there should be a check that this still occurs on 11.x, because most comments say this happens on D10, and then MR needs an update.
Comment #78
igorgoncalves commented#52 works great into our Drupal 10.5.2 project.
Comment #79
idiaz.ronceroIn my case, for this to work completely (i have the jquery UI set to height: "auto") I need to keep the debounce() for the first listener and remove it for the second one:
It is a complex project and I have many layers interfering so I do not know if this applies to a core Drupal but it would be worth to check.
- I had height set to auto
- With the patch, the first page load collapsed the dialog height - subsequent resizes or viewport changes corrected it.
Maybe that's why the 20ms debounce was introduced in the first place??
Comment #81
luongosb commentedI'm still having the issue in 11.3.2. The error still appears in the console, and in order to get the modal to display correctly, I need to resize the browser window. After doing that, the modal for the media library is positioned correctly. I am able to replicate this issue with using paragraphs that have a media library field and the form field widget set to use the media library modal. I believe that the paragraphs subform is causing a shift in the layout when the subform opens, then the media library modal is triggered. I believe the dialog position logic needs to run after AJAX has had a chance to run in case of any layout shifts. I'm doing updates to the dialog.position.js in my local environment to watch for DOM changes before the resizing events occur.
Comment #83
graber commentedI had the same issue when CKEditor was in a modal (#3577227: Fix CKEditor dialogs when displayed in a modal). The CKEditor link dialog was displayed below the modal and not visible. Somehow this caused the console error described here.
When I updated the default z-index of CKEditor, the console error went away so I don't even have to apply this patch.
Check the visibility of the elements on your projects, I know probably this may not be the only cause of the error but I hope this will help someone at least.