Skip to content

Fix | SummitDropdown | Type Error - null is not an object (evaluating 'this.state.summitValue.value')#203

Open
matiasperrone-exo wants to merge 8 commits intomainfrom
fix/type-error---null-is-not-an-object-evaluating-this.state.summitvalue.value
Open

Fix | SummitDropdown | Type Error - null is not an object (evaluating 'this.state.summitValue.value')#203
matiasperrone-exo wants to merge 8 commits intomainfrom
fix/type-error---null-is-not-an-object-evaluating-this.state.summitvalue.value

Conversation

@matiasperrone-exo
Copy link
Copy Markdown

@matiasperrone-exo matiasperrone-exo commented Mar 27, 2026

Task:

Ref: https://app.clickup.com/t/86b93hcm9

Chages Proposed

Enhance the SummitDropdown component to prevent errors when summitValue is null. Implement checks to ensure onClick is only executed with valid summitValue objects.

Summary by CodeRabbit

  • Bug Fixes

    • Summit dropdown now validates selections before triggering actions, preventing unintended behavior with invalid or null values.
    • Action button disable state now reliably reflects whether a valid summit is selected.
  • Tests

    • Added a comprehensive test suite covering initial state, selection handling, button enabling, and click behavior for the summit dropdown.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 27, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: ed49844d-2cd9-40f5-8ca0-6715606dca4b

📥 Commits

Reviewing files that changed from the base of the PR and between 69abb45 and 73c3f05.

📒 Files selected for processing (2)
  • package.json
  • src/components/summit-dropdown/__tests__/summit-dropdown.test.js
✅ Files skipped from review due to trivial changes (1)
  • package.json
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/components/summit-dropdown/tests/summit-dropdown.test.js

📝 Walkthrough

Walkthrough

Added a Jest test suite (React Testing Library) for SummitDropdown, tightened SummitDropdown input validation and click-guarding logic, and removed an empty top-level dependencies entry from package.json.

Changes

Cohort / File(s) Summary
SummitDropdown component
src/components/summit-dropdown/index.js
Updated handleChange to only set summitValue when summit?.value !== undefined; handleClick now checks this.state?.summitValue?.value !== undefined before calling onClick; button disabled logic uses optional chaining; sorts a shallow copy of summits instead of mutating the original.
SummitDropdown tests
src/components/summit-dropdown/__tests__/summit-dropdown.test.js
Added Jest tests (jsdom + React Testing Library style) that mock i18n-react, provide summits fixture and defaultProps, assert initial summitValue is null and button disabled, simulate selection enabling the button, exercise handleChange with valid/invalid inputs via ref, and verify handleClick only invokes onClick when a valid summit is selected.
Package metadata
package.json
Removed the empty top-level "dependencies": {} entry; no new runtime dependencies added.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I hopped through props and state with flair,
Tests tucked in my burrow, translations in air,
I only accept truths, ignore stray string noise,
I sort without touching your original toys,
Click guarded and ready — a tiny rabbit's rejoice!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main fix: adding null-safety checks to prevent the 'null is not an object' error when accessing this.state.summitValue.value.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/type-error---null-is-not-an-object-evaluating-this.state.summitvalue.value

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@matiasperrone-exo matiasperrone-exo self-assigned this Mar 27, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 27, 2026

Caution

Docstrings generation - FAILED

No docstrings were generated.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/components/summit-dropdown/__tests__/summit-dropdown.test.js (1)

46-60: Seed the invalid-input tests from a selected state.

These assertions start with summitValue === null, so they pass whether invalid input is ignored, clears the selection, or leaves a stale previous choice intact. Set a valid option first, then assert the intended post-condition.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/components/summit-dropdown/__tests__/summit-dropdown.test.js` around
lines 46 - 60, The tests currently start with summitValue null so they don't
verify that invalid inputs leave an existing selection alone; first seed a valid
selection (either by calling wrapper.instance().handleChange(validOption) or
setting wrapper.instance().state.summitValue to a valid object), then call
wrapper.instance().handleChange('not-an-object') (and similarly for null) and
assert that wrapper.instance().state.summitValue still equals the original valid
option; reference the render() helper, the component method handleChange, and
the state.summitValue field when making the change.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/components/summit-dropdown/index.js`:
- Around line 34-35: The summit option validation should require a defined
.value; update the summit-dropdown logic so handleChange, isDisabled, and any
state updates normalize invalid options to null instead of accepting any object.
Specifically, in the handleChange handler and wherever summitValue is set,
replace the current typeof-object check with a single predicate that checks
option is an object and option.value is not undefined/null (e.g., option &&
typeof option === 'object' && option.value != null) and set summitValue to that
option or null; update isDisabled to use the same predicate (disabled when
summitValue is null or option.value missing) so the button only enables for
usable options.

---

Nitpick comments:
In `@src/components/summit-dropdown/__tests__/summit-dropdown.test.js`:
- Around line 46-60: The tests currently start with summitValue null so they
don't verify that invalid inputs leave an existing selection alone; first seed a
valid selection (either by calling wrapper.instance().handleChange(validOption)
or setting wrapper.instance().state.summitValue to a valid object), then call
wrapper.instance().handleChange('not-an-object') (and similarly for null) and
assert that wrapper.instance().state.summitValue still equals the original valid
option; reference the render() helper, the component method handleChange, and
the state.summitValue field when making the change.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 18a34570-77b6-4882-8d81-3b3e2045fe75

📥 Commits

Reviewing files that changed from the base of the PR and between 0efec61 and 5ca5b7d.

📒 Files selected for processing (3)
  • src/components/summit-dropdown/__tests__/summit-dropdown.test.js
  • src/components/summit-dropdown/index.js
  • src/utils/constants.js

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
src/components/summit-dropdown/index.js (1)

56-60: Avoid sorting props.summits in place.

summits.sort() mutates the prop array during render. Clone it first so this component does not reorder parent-owned data as a side effect.

♻️ Suggested change
-        let summitOptions = summits
-            .sort(
+        let summitOptions = [...summits]
+            .sort(
                 (a, b) => (a.start_date < b.start_date ? 1 : (a.start_date > b.start_date ? -1 : 0))
             ).map(s => ({label: s.name, value: s.id}));
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/components/summit-dropdown/index.js` around lines 56 - 60, The code
mutates the incoming prop array by calling sort() directly on summits when
building summitOptions; change it to sort a cloned array instead (e.g., clone
summits with slice() or spread before calling sort) so the component does not
reorder parent-owned data, updating the summitOptions expression that currently
references summits.sort(...) to operate on the cloned array.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/components/summit-dropdown/index.js`:
- Around line 56-60: The code mutates the incoming prop array by calling sort()
directly on summits when building summitOptions; change it to sort a cloned
array instead (e.g., clone summits with slice() or spread before calling sort)
so the component does not reorder parent-owned data, updating the summitOptions
expression that currently references summits.sort(...) to operate on the cloned
array.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 0acdd9f1-feb5-4de7-81cb-8c0156101ad7

📥 Commits

Reviewing files that changed from the base of the PR and between 5ca5b7d and 988b5e2.

📒 Files selected for processing (1)
  • src/components/summit-dropdown/index.js

@matiasperrone-exo matiasperrone-exo force-pushed the fix/type-error---null-is-not-an-object-evaluating-this.state.summitvalue.value branch from 988b5e2 to 7dac5c7 Compare March 27, 2026 23:02
@matiasperrone-exo matiasperrone-exo force-pushed the fix/type-error---null-is-not-an-object-evaluating-this.state.summitvalue.value branch 3 times, most recently from 4d4bb12 to 0a7d308 Compare April 6, 2026 16:42
@matiasperrone-exo matiasperrone-exo force-pushed the fix/type-error---null-is-not-an-object-evaluating-this.state.summitvalue.value branch from 0a7d308 to bcb6dda Compare April 6, 2026 16:43
@matiasperrone-exo
Copy link
Copy Markdown
Author

src/components/summit-dropdown/index.js (1)

56-60: Avoid sorting props.summits in place.
summits.sort() mutates the prop array during render. Clone it first so this component does not reorder parent-owned data as a side effect.

Functionality added

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@package.json`:
- Around line 194-196: Move "enzyme" out of the top-level "dependencies" object
and into "devDependencies" in package.json, and add the appropriate React 17
adapter package "@wojtekmaj/enzyme-adapter-react-17" under devDependencies
(remove or replace any reference to "enzyme-adapter-react-16"); then update the
test import in src/components/summit-dropdown/__tests__/summit-dropdown.test.js
to import Adapter from '@wojtekmaj/enzyme-adapter-react-17' and ensure any setup
that calls Enzyme.configure uses that Adapter.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 75b3ba45-40d0-4d9c-b436-a2057bf85c53

📥 Commits

Reviewing files that changed from the base of the PR and between 988b5e2 and 6991619.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (3)
  • package.json
  • src/components/summit-dropdown/__tests__/summit-dropdown.test.js
  • src/components/summit-dropdown/index.js
✅ Files skipped from review due to trivial changes (1)
  • src/components/summit-dropdown/tests/summit-dropdown.test.js
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/components/summit-dropdown/index.js

@matiasperrone-exo matiasperrone-exo force-pushed the fix/type-error---null-is-not-an-object-evaluating-this.state.summitvalue.value branch from 6991619 to 7b39c70 Compare April 6, 2026 17:18
Copy link
Copy Markdown
Contributor

@santipalenque santipalenque left a comment

Choose a reason for hiding this comment

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

LGTM

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.

4 participants