Skip to content

fix(orders): fix nullish coalescing on toString in getNFTItems#1922

Closed
Viktohblake wants to merge 3 commits intoProjectOpenSea:mainfrom
Viktohblake:fix/orders-nullish-coalescing-in-getNFTItems
Closed

fix(orders): fix nullish coalescing on toString in getNFTItems#1922
Viktohblake wants to merge 3 commits intoProjectOpenSea:mainfrom
Viktohblake:fix/orders-nullish-coalescing-in-getNFTItems

Conversation

@Viktohblake
Copy link
Contributor

Motivation

When bulk listing NFTs, if the quantities array is shorter than the nfts array, quantities[index] is undefined. Calling .toString() on undefined throws a TypeError before the ?? "1" fallback can execute — making the fallback dead code.

Solution

Fixed incorrect operator precedence in getNFTItems where quantities[index].toString() ?? "1" would crash with a TypeError instead of falling back to "1" when quantities[index] is undefined.
Applied optional chaining before .toString() so the nullish coalescing default actually triggers: quantities[index]?.toString() ?? "1".

Test

Verify bulk listing with matching quantities and nfts arrays still works as before
Verify bulk listing where quantities array is shorter than nfts gracefully defaults to "1" instead of crashing

quantities[index].toString() ?? "1" crashes with TypeError when
quantities array is shorter than nfts array, because .toString() is
called on undefined before the nullish coalescing can provide the
fallback. Move the optional chain operator before .toString() so the
?? "1" default actually works as intended.
Verify that the optional chaining fix in getNFTItems correctly defaults
the amount to "1" when quantities array index is undefined.
@ryanio
Copy link
Collaborator

ryanio commented Mar 11, 2026

Great catch @Viktohblake! The optional chaining fix is spot-on — .toString() on undefined throws before ?? can ever kick in.

We've opened #1928 which cherry-picks your code fix and tests (without the unrelated package-lock.json peer dependency changes). You're credited as co-author on the commit.

Closing in favor of #1928.

@ryanio ryanio closed this Mar 11, 2026
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.

2 participants