Skip to content

fix runtime error when prop is undefined in pane.js#1164

Open
rajnisht7 wants to merge 2 commits intofossasia:masterfrom
rajnisht7:fix/pane-null
Open

fix runtime error when prop is undefined in pane.js#1164
rajnisht7 wants to merge 2 commits intofossasia:masterfrom
rajnisht7:fix/pane-null

Conversation

@rajnisht7
Copy link
Copy Markdown

@rajnisht7 rajnisht7 commented Apr 4, 2026

Description

This Pr adds safety to barwidgets when 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

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Code refactor or cleanup (changes to existing code for improved readability or performance)

Checklist:

  • I adapted the version number under py/visdom/VERSION according to Semantic Versioning
  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.

Summary by Sourcery

Bug Fixes:

  • Default the barwidgets prop to an empty array in Pane to avoid crashes when it is null or undefined.

@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai bot commented Apr 4, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

This PR updates the Pane React component to safely handle an undefined or null barwidgets prop by defaulting it to an empty array, preventing runtime errors when barwidgets is not provided.

Class diagram for updated Pane component prop handling

classDiagram
  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 || []
Loading

Flow diagram for barwidgets prop normalization in Pane

flowchart 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]
Loading

File-Level Changes

Change Details Files
Default barwidgets prop to an empty array in the Pane component to prevent runtime errors when the prop is missing or falsy.
  • Continue to destructure barwidgets from props instead of the main props destructuring block.
  • Add a fallback assignment that reassigns barwidgets to an empty array when its value is falsy (e.g., undefined, null).
js/panes/Pane.js

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • 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.
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.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@rajnisht7 rajnisht7 changed the title Update Pane.js fix runtime error when prop is undefined in pane.js Apr 4, 2026
@rajnisht7
Copy link
Copy Markdown
Author

@sourcery-ai check now

@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai bot commented Apr 4, 2026

Sure! I'm generating a new review now.

Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • 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.
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.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai bot commented Apr 4, 2026

Hey @rajnisht7, I've posted a new review for you!

@rajnisht7
Copy link
Copy Markdown
Author

rajnisht7 commented Apr 4, 2026

barwidgets is being re-assigned within the code therefore making it const will not be a good idea
to modify its data type to const we need to change the entire structure and have to introduce a new variable

somewhat like this

const { barwidgets } = props;
const newVar = barwidgets || [];
const allBarwidgets = enablePropertyList && content?.data
  ? [...newVar, <button/>]
  : newVar;

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.

1 participant