line 86 of contextual.js: Uncaught TypeError: Cannot read property 'top' of undefined then contextual links are useless at this point.

not sure what where why but here is a patch to fix it.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

nod_’s picture

FileSize
445 bytes

stupid EOL whitespace

jessebeach’s picture

Status: Needs review » Reviewed & tested by the community

It's a simple patch to correct a logic error in an if statement. I just ran into this bug a moment. The patch resolves it.

alexpott’s picture

Status: Reviewed & tested by the community » Needs review

Doesn't this suggest that contextual.js is being loaded on a page with no contextual links? Is this an outcome of a bigger problem?

+++ b/core/modules/contextual/contextual.jsundefined
@@ -78,7 +78,7 @@ function adjustIfNestedAndOverlapping ($contextual) {
-  if ($contextuals.length === 1) {

Admittedly this does seem brittle...

alexpott’s picture

If you look at where this has been called... initContextual adds the class contextual so I have no clue how $contextuals.length is less than 1

Can we get some instruction to recreate?

alexpott’s picture

I managed to recreate by doing this...

  • Install standard profile
  • Create an article - promoted to frontpage
  • Visit frontpage - can't contextual links

So the commit that introduced the issue was 5aced02... ie. #2004286: Defer calls to drupal_get_* functions until printed inside a template by adding a RenderWrapper class

Wim Leers’s picture

Title: Contextual links broken because of js error » Contextual links broken because of JS error, caused by #2004286
Status: Needs review » Active

#2/#3: initContextual() should not be called unless there actually *is* a contextual link, so that's no logic error, that's intentional strictness.

This happens *only* on pages with Views, where views-contextual.js is not being loaded when it should be. This does not happen on e.g. node/1.
The fact that a JS error occurs because views-contextual.js has not been loaded while it should be, is a good thing IMO.


Root cause

Debugging this indeed led to 5aced02 i.e. #2004286: Defer calls to drupal_get_* functions until printed inside a template by adding a RenderWrapper class being the cause. More specifically, as of that commit, views_preprocess_html()'s logic that adds views-contextual.js is no longer fired, because $variables['attributes']['class'] no longer includes the contextual-region class.

So this is in fact a whole cascade of things. The fact that the JS error was never noticed in #2004286 is rather puzzling, because it happens on the front page, even without creating any content. It suggests no or far too superficial manual testing was done for that patch.

Solution

I tried to find a solution.

When views_preprocess_html() gets fired, then #2004286 causes $variables['page'] to already be HTML rather than a render element, hence preventing the dynamic changing of the class attribute (because it checks for if (!empty($variables['page']['#views_contextual_links'])) {, which can't work if $variables['page'] = '<div>html here</div>'). If I change it to views_preprocess_page(), then it is able to properly detect the presence of Views' contextual links, but the changes are ignored, they never make it into the final HTML.

I tried to devise work-arounds using hook_page_build() and hook_page_alter(), but failed.

AFAICT there is no clear solution. #2004286 introduced this mess, along with an always-visible messages area: #2004286-76: Defer calls to drupal_get_* functions until printed inside a template by adding a RenderWrapper class. I think #2004286 should simply be reverted. Before it can be committed, it should first fix the problems it causes elsewhere.

catch’s picture

Status: Active » Closed (duplicate)

Alex rolled back the other patch, closing this one.

yannickoo’s picture

Issue summary: View changes
Status: Closed (duplicate) » Active

I noticed this problem in several d8 projects and the patch would fix this error :/

yannickoo’s picture

Priority: Critical » Normal
pmchristensen’s picture

Thanks to @nod_ for this patch - Updated the patch to be working with release 8.0.1.

yannickoo’s picture

Status: Active » Reviewed & tested by the community

Great!

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

@yannickoo, @pmchristensen can we get new steps to reproduce and find out why - as @Wim Leers has said in #6 this error is a sign of something else being wrong.

Wim Leers’s picture

Title: Contextual links broken because of JS error, caused by #2004286 » Contextual links broken because of JS error
Priority: Normal » Minor
Issue tags: +Needs tests, +Needs steps to reproduce, +Needs issue summary update

Yeah, this is minor at best, because nobody seems to encountering it. We need proper steps to reproduce. And the issue summary is outdated since this was repurposed in #8.

We now have JavaScriptTestBase, so now it should be possible to write a test that fails.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

jcnventura’s picture

yannickoo’s picture

Thank you for the hint @jcnventura! It's funny to compare the patches, the only difference between them:

+
+    // Prevent errors if the necessary entity markup is missing.
+    if (entityElement.length === 0) {
+      return;
+    }
+

How should we proceed with this issue now? Mark this one as duplicated and try to get the other pach from #2551373: contextual.js and quickedit.js should fail gracefully, with useful error messages, when Twig templates forget to print attributes in?

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

landsman’s picture

Path "2771361-7-do-not-attach-ajax-to-non-present-views.patch" fix my issue.
When will be merged please?

Berdir’s picture

#2551373: contextual.js and quickedit.js should fail gracefully, with useful error messages, when Twig templates forget to print attributes was committed now, I'm not sure if this isn't just a duplicate of that issue at this point.

Try to see if latest 8.4.x fixes your problem as well.

Wim Leers’s picture

Status: Needs work » Postponed (maintainer needs more info)

Agreed with Berdir!

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

pameeela’s picture

Thanks for reporting this issue. We rely on issue reports like this one to resolve bugs and improve Drupal core.

As part of the Bug Smash Initiative, we are triaging issues that are marked "Postponed (maintainer needs more info)".

Since there was no additional information provided since the issue was postponed or #2551373: contextual.js and quickedit.js should fail gracefully, with useful error messages, when Twig templates forget to print attributes was suggested as duplicate, I'm marking the issue "Closed (duplicate)". If anyone can provide information on why this issue is different, please add complete steps to reproduce the issue (starting from "Install Drupal core"), document those steps in the issue summary and set the issue status back to "Active".

Thanks!