Skip to content

fix(utils): keep falsy non-nullish values in asArray - #1114

Open
Kernel-Hunter wants to merge 1 commit into
solidjs-community:mainfrom
Kernel-Hunter:utils-as-array-falsy
Open

Kernel-Hunter wants to merge 1 commit into
solidjs-community:mainfrom
Kernel-Hunter:utils-as-array-falsy

Conversation

@Kernel-Hunter

@Kernel-Hunter Kernel-Hunter commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

asArray is typed to return NonNullable<T> items, so only null and undefined should become []. The check was value ? [value] : [], which also dropped 0, "" and false: asArray(0) returned [].

Changed it to value != null. Tests for wrapping, arrays, falsy values and nullish values are in packages/utils/test/index.test.ts; the falsy one fails on main and passes now. The tests of the packages that use asArray pass too, and eslint and prettier are clean. Changeset included.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed asArray so values such as 0, false, and empty strings are wrapped in arrays instead of being discarded. Arrays remain unchanged, while null and undefined still return an empty array.

@changeset-bot

changeset-bot Bot commented Nov 16, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: ce7d81a

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

This PR includes changesets to release 1 package
Name Type
@solid-primitives/utils 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

@coderabbitai

coderabbitai Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

asArray now wraps falsy non-nullish values in an array. Tests cover scalar values, existing arrays, null, and undefined. A patch Changeset documents the fix.

Changes: asArray behavior

Layer / File(s) Summary
Update and validate asArray behavior
packages/utils/src/index.ts, packages/utils/test/index.test.ts, .changeset/utils-as-array-falsy.md
asArray now wraps non-nullish scalars, including 0, "", and false. Tests check these values, array identity, and empty-array results for null and undefined. A patch Changeset documents the change.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Low

Suggested labels: bug

Suggested reviewers: thetarnav

Merge Risk: Minimal · up to ce7d8

asArray now keeps 0, empty strings and false instead of returning an empty array. This fixes the reported bug. Callers that relied on falsy values being dropped would see different results, but no such caller has been identified. The change is small, tested, and easy to revert.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: asArray now keeps falsy non-nullish values (0, "", false) by checking value != null instead of truthiness. The raw summary and PR objectives both describe this same ch…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: asArray now keeps falsy non-nullish values (0, "", false) by checking value != null instead of truthiness. The raw summary and PR objectives both describe this same change to packages/utils/src/index.ts, its tests, and the changeset. The title is specific and accurate, and it follows the conventional commit style.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 8d1bae3f-a32f-4fd5-8b3a-c84faae0fe7b
Commits

Reviewing files that changed from the base of the PR and between e936941 and ce7d81a.

Files selected for processing: 3

  • .changeset/utils-as-array-falsy.md
  • packages/utils/src/index.ts
  • packages/utils/test/index.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

This branch has not been deployed

No deployments
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