An error occurred during the execution of the Ajax response: TypeError: Cannot read properties of undefined (reading 'style')

Created on 25 January 2024, 10 months ago
Updated 28 February 2024, 9 months ago

Problem/Motivation

Fix BE Issue, visible within LayoutBuilder

Steps to reproduce

On latest Drupal 10.2.2:
- Enable Layout Builder
- Open Layout Builder Editor (node display overwrite)
- Save
- Reopen and try to edit any configuration at Section/Blocks

Proposed resolution

- Have a look at: core/misc/dialog/off-canvas/js/off-canvas.js:323 - resetPadding where access at: Drupal.offCanvas.$mainCanvasWrapper[0].style
- Error message:

.catch((error) =>error = TypeError: Cannot read properties of undefined (reading 'style') at Object.resetPadding (http://*.vhost/core/misc/dialog/off-canvas/js/off-canvas.js?v=10.2.2:323:46) at HTMLDivElement.bodyPadding (http://*.vhost/core/misc/dialog/off-canvas/js/off-canvas.js?v=10.2.2:270:24) at HTMLDivElement.dispatch (http://*.vhost/core/assets/vendor/jquery/jquery.min.js?v=3.7.1:2:40035) at v.handle (http://*.vhost/core/assets/vendor/jquery/jquery.min.js?v=3.7.1:2:38006) at Object.trigger (http://*.vhost/core/assets/vendor/jquery/jquery.min.js?v=3.7.1:2:70124) at HTMLDivElement. (http://*.vhost/core/assets/vendor/jquery/jquery.min.js?v=3.7.1:2:70726) at Function.each (http://*.vhost/core/assets/vendor/jquery/jquery.min.js?v=3.7.1:2:3129) at ce.fn.init.each (http://*.vhost/core/assets/vendor/jquery/jquery.min.js?v=3.7.1:2:1594) at ce.fn.init.trigger (http://*.vhost/core/assets/vendor/jquery/jquery.min.js?v=3.7.1:2:70701) at resetSize (http://*.vhost/core/misc/dialog/off-canvas/js/off-canvas.js?v=10.2.2:249:10)

Merge request link

Remaining tasks

- Identify Bug

User interface changes

API changes

Data model changes

Release notes snippet

πŸ› Bug report
Status

Fixed

Version

10.2 ✨

Component
AjaxΒ  β†’

Last updated about 11 hours ago

Created by

πŸ‡©πŸ‡ͺGermany flefle

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @flefle
  • πŸ‡©πŸ‡ͺGermany flefle
  • πŸ‡¬πŸ‡§United Kingdom grahamC Oxford, UK

    I have this issue too on a customer site recently upgraded from 9.5 to 10.2.

    In the error 'Cannot read properties of undefined', the undefined is the off-canvas wrapper element ([data-off-canvas-main-canvas])

    That element was entirely missing for me... It's supposed to be put in place by a #theme_wrapper (see system_element_info_alter()) but somehow another module's theme_wrapper is preventing the off-canvas one from running...

    The offending module for me is Responsive and off-canvas menu β†’ - and commenting out the responsive_menu_preprocess_html() function fixes the issue here.

    @flefle - do you have this module also?

    The code that causes the problem is essentially as below:

    hook_preprocess_html(&$vars) {
      $vars['page']['#theme_wrappers'][] = 'responsive_menu_page_wrapper';
    }
    

    I can't yet understand what's wrong with adding a theme wrapper like this and why it causes the one from `system` to go missing, though...

  • πŸ‡¨πŸ‡­Switzerland berdir Switzerland

    In the case of @flefle, we tracked this down to an overriden off-canvas-page-wrapper.html.twig template that was missing the data attribute.

    While the reason for this error is probably always going to be in contrib/custom modules or themes, it could be argued that off-canvas.js could be more defensive about this situation and avoid a JS error either silently or by doing something like console.warning('Missing data-off-canvas-main-canvas attribute on off-canvas wrapper.

  • πŸ‡©πŸ‡ͺGermany flefle

    @grahamC as Sascha mentioned, could you please confirm if the "dialog-off-canvas-main-canvas" within /core/modules/system/templates/off-canvas-page-wrapper.html.twig present is? Was it overwritten maybe and after that the issue occurred?

    See also:
    https://www.drupal.org/forum/support/theme-development/2019-08-08/how-to... β†’

    Such cases as of: https://www.drupal.org/project/drupal/issues/3409505 πŸ› Uncaught TypeError: Cannot read properties of null (reading 'style') (toolbar.js) Needs work should be escaped but the Issue could be fixed by applying the dialog-off-canvas-main-canvas in my case.

  • Status changed to Fixed 10 months ago
  • πŸ‡©πŸ‡ͺGermany flefle
  • Automatically closed - issue fixed for 2 weeks with no activity.

  • πŸ‡ΉπŸ‡­Thailand peterbkk

    To resolve this quickly, I used this module https://www.drupal.org/project/layout_builder_admin_theme β†’ and now layout builder is using admin theme and not my main theme with responsive_menu.

Production build 0.71.5 2024