Skip to content
This repository was archived by the owner on Nov 19, 2025. It is now read-only.

Comments

fix(hub-common): modified getProp() logic#2116

Merged
knbhagat merged 3 commits intomasterfrom
b/14633-console-error-on-gallery-card-selection
Nov 14, 2025
Merged

fix(hub-common): modified getProp() logic#2116
knbhagat merged 3 commits intomasterfrom
b/14633-console-error-on-gallery-card-selection

Conversation

@knbhagat
Copy link
Contributor

@knbhagat knbhagat commented Nov 10, 2025

  1. Description: Modified getProp() logic
  • If hey is undefined, then accessing hey.hello[0] should return undefined instead of throwing an error.
  • If hey.hello exists and the array element at index 0 contains a falsy value (e.g., null, 0, '', false), then return that actual value.
    • Only return undefined when the path truly doesn’t exist. Otherwise, return the actual value, even if it’s falsy.
  1. Instructions for testing:

  2. Updated meaningful TSDoc to methods including Parameters and Returns, see Documentation Guide

  3. Either ran npm run changeset or this change does not require a release.

  4. These changes have been verified by QA using a ?uiVersion that includes a PR-Preview of this branch and the v_req label has been applied to the issue.

  5. OD-UI E2E tests pass against these changes using a ?uiVersion that includes a PR-Preview of this branch

@changeset-bot
Copy link

changeset-bot bot commented Nov 10, 2025

🦋 Changeset detected

Latest commit: d17b6d4

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@esri/hub-common Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@knbhagat knbhagat requested a review from Copilot November 10, 2025 21:25
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes the getProp() function to properly handle falsy values in arrays and undefined paths. Previously, the function would throw errors when accessing properties on undefined objects and would incorrectly return undefined for falsy array elements like null, 0, false, or empty strings.

Key Changes:

  • Added an early return guard to prevent errors when accessing properties on undefined objects
  • Changed array element existence check from truthiness check to proper in operator to distinguish between missing elements and falsy values

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
packages/common/src/objects/get-prop.ts Modified the core logic to handle undefined paths safely and properly return falsy array values
packages/common/test/objects/get-prop.spec.ts Added comprehensive test coverage for falsy array elements and undefined path scenarios

Copy link
Contributor

@sonofflynn89 sonofflynn89 left a comment

Choose a reason for hiding this comment

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

Should be good as long as all tests are passing! Just one test comment

Copy link
Member

@tomwayson tomwayson left a comment

Choose a reason for hiding this comment

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

nice work!

@knbhagat knbhagat merged commit 70d866f into master Nov 14, 2025
3 checks passed
@knbhagat knbhagat deleted the b/14633-console-error-on-gallery-card-selection branch November 14, 2025 14:24
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants