Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncaught TypeError: Cannot read property 'style' of null #2662

Open
Crashillo opened this issue Nov 7, 2019 · 2 comments · Fixed by #2663 or #2684
Open

Uncaught TypeError: Cannot read property 'style' of null #2662

Crashillo opened this issue Nov 7, 2019 · 2 comments · Fixed by #2663 or #2684
Assignees
Labels

Comments

@Crashillo
Copy link
Member

View details in Rollbar: https://rollbar.com/Populate/gobierto/items/2776/


TypeError: Cannot read property 'style' of null
  File "webpack:https:///./node_modules/d3/node_modules/d3-selection/src/selection/style.js", line 33, in styleValue
      return node.style.getPropertyValue(name)
  File "webpack:https:///./node_modules/d3/node_modules/d3-selection/src/selection/style.js", line 29, in [anonymous]
          : styleValue(this.node(), name);
  File "webpack:https:///./app/javascript/lib/visualizations/modules/lines_execution.js", line 425, in VisLinesExecution._width
        return parseInt(d3.select(this.container).style('width'));
  File "webpack:https:///./app/javascript/lib/visualizations/modules/lines_execution.js", line 89, in VisLinesExecution.setScales
        this.width = this._width() - this.margin.left - this.margin.right;
  File "webpack:https:///./app/javascript/lib/visualizations/modules/lines_execution.js", line 55, in VisLinesExecution.getData
          this.setScales();
  File "webpack:https:///./node_modules/d3-request/src/request.js", line 115, in send
          if (callback != null) request.on("error", callback).on("load", function(xhr) { callback(nul...
  File "webpack:https:///./node_modules/d3-dispatch/src/dispatch.js", line 57, in call
        for (t = this._[type], i = 0, n = t.length; i < n; ++i) t[i].value.apply(that, args);
  File "webpack:https:///./node_modules/d3-request/src/request.js", line 40, in respond
          event.call("load", request, result);
@Crashillo
Copy link
Member Author

Crashillo commented Nov 11, 2019

All legacy charts with something like: d3.select(this.container).style(...) must be refactored. Provide just a fallback when this.container is null.

UPDATE
It comes up after d3.select call, therefore, the fallback must be:
d3.select(this.container).node() ? d3.select(this.container).style(...) : 0

@Crashillo
Copy link
Member Author

Crashillo commented Jan 29, 2020

I could trace this error to:

window.addEventListener("resize", _.debounce(function () {
new VisSlider('.timeline', window.budgetLevels);
visBubblesExpense.resize();
visBubblesIncome.resize();
if (window.innerWidth >= 1024) {
new VisBubbleLegend('.bubble_legend');
} else {
$('.bubble_legend svg').remove();
}
}, 250));

When the event resize is triggered, the DOM is not ready yet to call jQuery methods or the classes. This is quite common on mobile devices as you use to switch between portrait and landscape modes.

It's necessary to refactor the DOM access, to check if the node actually exists before apply any function to it.

Related issues: #2825 and #1959

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants