Make WordPress Core

Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#43005 closed defect (bug) (fixed)

JavaScript error Cannot read property 'action' of null on chrome

Reported by: manikmist09's profile manikmist09 Owned by: sergeybiryukov's profile SergeyBiryukov
Milestone: 4.9.3 Priority: normal
Severity: normal Version: 4.6
Component: Upgrade/Install Keywords: has-patch needs-refresh
Focuses: javascript Cc:

Description

I am getting the following console error (chrome v63.0.3239.84) on various admin pages because of that some buttons on those pages do not respond when clicking. I have tested with disabling all the plugins and themes and using default theme but still seeing the same error on WP version 4.9.1

Uncaught TypeError: Cannot read property 'action' of null
    at updates.js?ver=4.9.1:2443
    at dispatch (jquery.js?ver=1.12.4:3)
    at r.handle (jquery.js?ver=1.12.4:3)

Attachments (3)

#43005.diff (419 bytes) - added by manikmist09 7 years ago.
43005.1.patch (419 bytes) - added by manikmist09 7 years ago.
As the error was occurring because of var message was null and its property was checking. So, I checked if is message null before checking its property.
43005.2.diff (335 bytes) - added by manikmist09 7 years ago.
Indented using tabs and removed double space

Download all attachments as: .zip

Change History (18)

@manikmist09
7 years ago

@manikmist09
7 years ago

As the error was occurring because of var message was null and its property was checking. So, I checked if is message null before checking its property.

#1 @manikmist09
7 years ago

  • Keywords has-patch added

This ticket was mentioned in Slack in #core-js by manik. View the logs.


7 years ago

#3 @dingo_bastard
7 years ago

Are you sure you don't have Grammarly extension installed in your browser? This sounds a lot like #42815 duplicate to me.

Last edited 7 years ago by SergeyBiryukov (previous) (diff)

#4 @manikmist09
7 years ago

  • Summary changed from JavaScript error Cannot read property 'action' of null on chrome Version 63.0.3239.84 to JavaScript error Cannot read property 'action' of null on chrome

@dingo_bastard , yes I do have Grammarly extension installed and disabling that the error does not shows. But if I check whether message itself is null or not before checking its property message.action the error does not show. so the condition will be like null === message || 'undefined' === typeof message.action.

I think that's good to have in that condition so we won't see any errors for the same reason. What do you think?

#5 @dingo_bastard
7 years ago

  • Keywords 2nd-opinion dev-feedback added

I think, like in the ticket I linked that the issue is not in the WordPress but in the Grammarly extension ;)

We could apply a patch that you suggested, but what if something is actually conflicting on Grammarly's end, we wouldn't know it if we silenced the error.

#6 @ediamin
7 years ago

Hi, I can confirm this is not related to Grammarly extension. I'm using Vue js in one of my plugins and got the same error. Here is my test plugin to reproduce the error: https://github.com/ediamin/wp_action_error_reproduce_plugin

The main reason is in update.js we are listening for message event which is produced by window.postMessage(). Now, if any of the enqueued scripts has postMessage('', 'http://yourdomain.com'), then the message will be null and hence, message.action throws Cannot read property 'action' of null error.

By the way, my reproduce plugin will throw the error in some of the admin pages, like plugins.php. But typing postMessage('', 'http://yourdomain.com') will give the error in any of the admin pages.

Last edited 7 years ago by ediamin (previous) (diff)

#7 @afercia
7 years ago

  • Component changed from Administration to Upgrade/Install
  • Keywords needs-refresh added; 2nd-opinion dev-feedback removed
  • Milestone changed from Awaiting Review to 4.9.2
  • Version changed from 4.9.1 to 4.6

I have no idea what Grammarly does, and no idea why one would want to use an empty message, but checking for an object existence before checking for its properties seems a common best practice to me.

From the jQuery docs:

Prior to jQuery 1.9, $.parseJSON returned null instead of throwing an error if it was passed an empty string, null, or undefined, even though those are not valid JSON.

In other parts in core where $.parseJSON() is used, I don't see a great consistency but at least in one case there's a check for the object being truthy.

The patch would need a refresh for proper indentation (please use tabs) and to remove a double space.

Proposing for 4.9.2 consideration.

@manikmist09
7 years ago

Indented using tabs and removed double space

#8 @manikmist09
7 years ago

Hi @afercia, Thank you for considering the patch for v4.9.2, I have fixed the indentation problem using tabs and removed double space.

Last edited 7 years ago by manikmist09 (previous) (diff)

#9 @dd32
7 years ago

  • Milestone changed from 4.9.2 to 4.9.3

Bumping to 4.9.3 due to 4.9.2s release

This ticket was mentioned in Slack in #core by desrosj. View the logs.


7 years ago

#11 @SergeyBiryukov
7 years ago

  • Owner set to SergeyBiryukov
  • Resolution set to fixed
  • Status changed from new to closed

In 42604:

Upgrade/Install: In postMessage events handler, check for message object existence before checking its action property.

Props manikmist09.
Fixes #43005.

#12 @SergeyBiryukov
7 years ago

In 42605:

Upgrade/Install: In postMessage events handler, check for message object existence before checking its action property.

Props manikmist09.
Merges [42604] to the 4.9 branch.
Fixes #43005.

#13 @manikmist09
7 years ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

Thank you. I have reopened the ticket mistakenly.

Last edited 7 years ago by manikmist09 (previous) (diff)

#14 @SergeyBiryukov
7 years ago

  • Resolution set to fixed
  • Status changed from reopened to closed

This ticket was mentioned in Slack in #core by manik. View the logs.


7 years ago

Note: See TracTickets for help on using tickets.