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

TypeError: Cannot read property 'getTotalLength' of null #618

Open
vinayakvivek opened this issue Apr 22, 2020 · 6 comments
Open

TypeError: Cannot read property 'getTotalLength' of null #618

vinayakvivek opened this issue Apr 22, 2020 · 6 comments

Comments

@vinayakvivek
Copy link

I was trying out one of the demos. This error appears whenever I use a link label. Nodes and links get rendered with no issues, if I don't use any link label.

Detailed error:
In LabelWidget.findPathAndRelativePositionToRenderLabel

  8194 | this.findPathAndRelativePositionToRenderLabel = index => {
  8195 |   // an array to hold all path lengths, making sure we hit the DOM only once to fetch this information
  8196 |   const link = this.props.label.getParent();
> 8197 |   const lengths = link.getRenderedPath().map(path => path.getTotalLength()); // calculate the point where we want to display the label
  8198 |                                                           ^  
  8199 |   let labelPosition = lengths.reduce((previousValue, currentValue) => previousValue + currentValue, 0) * (index / (link.getLabels().length + 1)); // find the path where the label will be rendered and calculate the relative position
  8200 | 

If anyone could point out why this is happening and a solution for the same, it'd be really helpful.

@renato-bohler
Copy link
Contributor

Seems like duplicate of #598, which is closed... maybe we should reopen it?

Beep @pierre-moire

@janaka
Copy link

janaka commented Dec 21, 2020

In case somebody else misses the workaround mentioned in #598

Had to remove <React.StrictMode> to get around this error.

@AndrewKirkovski
Copy link

So I tracked down root of this issue:

https://github.com/projectstorm/react-diagrams/blob/master/packages/react-diagrams-defaults/src/link/DefaultLinkWidget.tsx#L112

this.refPaths = []; in render method resets every time DefaultLinkWidget re-renders

Link segments, however, do not re-render as many times as DefaultLinkWidget. I.e. I tracked down in React.Strict + dev mode render of DefaultLinkWidget actually happens twice, but link segments are not re-rendered second time, so refs are lost in previous instance of this.refPaths = []; and never are getting to new one

Since I have custom Widgets in own project, I changed my CustomLinkWidget to only have one ref to g element like ref: React.RefObject<SVGGElement>; and am collecting needed path elements with querySelectorAll by special data attribute used in CustomLinkSegmentWidget

Not sure what proper solution would be for that

@AdrianLsk
Copy link

AdrianLsk commented Jul 10, 2022

@AndrewKirkovski HUGE thank you for sharing the workaround.

@sovetski
Copy link

I have the same problem...

@marian2js
Copy link
Contributor

I made a PR that fixes this issue: #1014

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

No branches or pull requests

7 participants