-
Notifications
You must be signed in to change notification settings - Fork 233
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
Error re-rendering Graph when no config
prop is set
#81
Comments
Hey there @LonelyPrincess, nice report, you identified with good precision the issue. Regarding the solution for this, Fell free to submit a PR for this, nice job! Thanks! |
No prob! I'm glad to be of assistance! 😊 I've just uploaded two commits addressing this same issue in my fork repo:
Could you tell me which of them you like better, @danielcaldas? I'll submit the PR for the solution you choose. 👍 |
I prefer the first one, it is cleaner than the second one, the performance gain with the second option is not substantial since we check for empty object with Nice one 👍 |
When the user didn't add the 'config' prop to the 'Graph' component (which should be possible, as it's an optional field), the graph failed to render whenever its data changed. The component would work the first time around, but when it received new data, it threw an error as described [in this issue](#81) and the view would not update. The root of the problem was located in the `componentWillReceiveProps` method of the `Graph` component. When defining the constants `configUpdated` and `transform`, the case in which `newProps.config` was set to either null or undefined was not being considered. This caused errors when calling `isDeepEqual` and also when trying to get the `panAndZoom` property during `transform` initialization.
Fixed with #84 |
I was stuck with this error for a while, until I finally found out what was causing it. Details on the error and the current workaround are listed bellow, just in case it can be of use to someone else who's struggling with the same problem.
Problem description
By the time I got the error, my
Graph
component was looking like this:When I run the application for the first time, the graph would render perfectly on the screen. However, when I updated its data in my component state and the graph was to be rendered for a second time, I got the following error message:
Workaround
After hours trying to figure it out, I finally discovered that adding the
config
prop to theGraph
component prevented the error from happening.Since I wasn't overriding anything in the default config, I just hadn't considered adding it before. In order to solve this issue, I was forced to pass down an empty object in the
config
prop.After doing so, the graph would always successfully render whenever there was a change in the data.
Steps to reproduce the issue:
This issue can be easily reproduced in the sandbox example bundled with this project.
Sandbox.jsx
file, remove / comment theconfig
property in the constantgraphProps
defined in therender
method (currently, line 295).Open the updated sandbox example in a browser.
Click any of the buttons to dynamically add or remove a node (the
+
and-
buttons above of the graph). This action will trigger the error immediatly.Additional notes
The project
README
file mentions that onlyid
anddata
are required, and that bothconfig
and any of the callback methods are entirely optional. This is true for the first time the graph is rendered, but right now it seems that theconfig
object must be present to update the view later on.The solution for this issue would be to initialize the
config
value in the component state to an empty object, which will be used by default in case noconfig
prop has been passed down to theGraph
component.The
componentWillReceiveProps
handler seems to be a good place to start. If you'd like, @danielcaldas, I can take a closer look at this later and submit a pull request.For the time being, users must explicitly set a
config
prop even if they're not overriding any of the default settings.The text was updated successfully, but these errors were encountered: