fix runtime error when prop is undefined in pane.js#1164
Open
rajnisht7 wants to merge 2 commits intofossasia:masterfrom
Open
fix runtime error when prop is undefined in pane.js#1164rajnisht7 wants to merge 2 commits intofossasia:masterfrom
rajnisht7 wants to merge 2 commits intofossasia:masterfrom
Conversation
Contributor
Reviewer's guide (collapsed on small PRs)Reviewer's GuideThis PR updates the Pane React component to safely handle an undefined or null Class diagram for updated Pane component prop handlingclassDiagram
class Pane {
+id
+title
+content
+children
+widgets
+enablePropertyList
+barwidgets
+render()
}
class Props {
+id
+title
+content
+children
+widgets
+enablePropertyList
+barwidgets
}
Pane -- Props : uses
class BarwidgetsHandling {
+barwidgets
+normalizeBarwidgets(barwidgets)
}
BarwidgetsHandling <.. Pane : barwidgets = barwidgets || []
Flow diagram for barwidgets prop normalization in Paneflowchart TD
A[Pane receives props] --> B{Does props.barwidgets exist?}
B -->|Yes, not null| C[Assign barwidgets from props]
B -->|No or null or undefined| D[Set barwidgets to empty array]
C --> E[Use barwidgets safely in rendering]
D --> E[Use barwidgets safely in rendering]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Contributor
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- If the goal is to handle explicitly passed
nullas well asundefined, the default parameter invar { barwidgets = [] } = props;will not cover thenullcase, so consider normalizing it (e.g.const { barwidgets } = props; const safeBarwidgets = barwidgets || [];) at the usage site instead.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- If the goal is to handle explicitly passed `null` as well as `undefined`, the default parameter in `var { barwidgets = [] } = props;` will not cover the `null` case, so consider normalizing it (e.g. `const { barwidgets } = props; const safeBarwidgets = barwidgets || [];`) at the usage site instead.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Author
|
@sourcery-ai check now |
Contributor
|
Sure! I'm generating a new review now. |
Contributor
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- Instead of declaring
var { barwidgets } = props;and then reassigning withbarwidgets = barwidgets || [];, consider using a default value in the destructuring (e.g.const { barwidgets = [] } = props;) to make the intent clearer and avoid mutation. - You may want to merge the
barwidgetsdestructuring into the existingconst { id, title, content, children, widgets, enablePropertyList } = props;statement for consistency and to keep related props defined together.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Instead of declaring `var { barwidgets } = props;` and then reassigning with `barwidgets = barwidgets || [];`, consider using a default value in the destructuring (e.g. `const { barwidgets = [] } = props;`) to make the intent clearer and avoid mutation.
- You may want to merge the `barwidgets` destructuring into the existing `const { id, title, content, children, widgets, enablePropertyList } = props;` statement for consistency and to keep related props defined together.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Contributor
|
Hey @rajnisht7, I've posted a new review for you! |
Author
|
barwidgets is being re-assigned within the code therefore making it const will not be a good idea somewhat like this |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This Pr adds safety to
barwidgetswhen the prop is not passed or is null (or undefined)var { barwidgets } = props;Motivation and Context
if barwidgets remains undefined it can throw an error and can cause runtime error
How Has This Been Tested?
tested by explicitly passing null and verified that no error occurs also tested by passing as array, works same
Screenshots (if appropriate):
Types of changes
Checklist:
py/visdom/VERSIONaccording to Semantic VersioningSummary by Sourcery
Bug Fixes: