Skip to content

Conversation

@itsronalds
Copy link

Introduction

During the integration of the OrgChart.js library into the Odoo portal module, I encountered an Odoo alert error and a TypeError in the console related to the .slice() method inside orgchart.js.

After investigating, I discovered that the issue originated from the _resizeHandler method being executed before the viewBox value was properly initialized.

This occurred when the browser’s localStorage was empty, causing getViewBox() to return null and leading to the error on the first chart load.

Description

When OrgChart initializes with an empty localStorage or no previous state, _resizeHandler may call getViewBox().slice(0) before the SVG viewBox attribute is defined, resulting in a TypeError: Cannot read properties of undefined (reading 'slice').

This patch introduces a null check for getViewBox() before calling .slice(), ensuring _resizeHandler executes only when a valid viewBox is available.

Technical Summary

  • Added an array validation for this.getViewBox() in _resizeHandler to ensure it returns a valid array before calling .slice().
  • Prevents the console error on first load when OrgChart starts with an empty or missing localStorage state.
  • Does not alter resize, rendering, or initialization behavior.

Code Change

// Fix: prevent TypeError when getViewBox() is null during first initialization

-    if (this.isVisible && 0 != t && 0 != e)
+    if (this.getViewBox() && this.isVisible && t !== 0 && e !== 0)

@plamen-peshev
Copy link
Contributor

Added the fix in the latest version 8.21.27

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants