You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
range() throws RangeError when called with single argument because stop check uses strict equality against null #23197
The comment notes that the function is extracted from underscore.js (https://github.com/jashkenas/underscore/blob/fc039f6a94fcf388d2b61ced4c02cd1ba116ecfd/underscore.js#L693-L710).
In underscore.js, range supports single-argument invocation (range(stop), such as range(4) yielding [0, 1, 2, 3]), checking if (stop == null).
In app/src/lib/range.ts:
stop is not marked optional in the signature (stop: number instead of stop?: number | null).
The condition if (stop === null) uses strict equality against null. When invoked with a single argument, stop is undefined, so stop === null evaluates to false.
Consequently, Math.ceil((stop - start) / step) computes Math.ceil((undefined - start) / 1) which is NaN.
Calling new Array<number>(NaN) throws RangeError: Array length must be a positive integer of safe magnitude.
Steps to reproduce
import{range}from'./lib/range'range(4)// Throws RangeError: Array length must be a positive integer of safe magnitude
Proposed fix
Update stop parameter type to stop?: number | null.
Change the check to if (stop == null).
Add unit tests in app/test/unit/range-test.ts covering single argument, start/stop, positive/negative steps, and empty ranges.
Triage summary: No duplicates found in a search of desktop/desktop for similar range()/RangeError reports. This is a confirmed bug, requesting bug — HIGH confidence — and priority-3 — MEDIUM confidence, since the current codebase has no call site that invokes range() with a single argument, limiting real-world impact today.
Initial hypothesis
At commit 01cde4fd4d7bb07e642bcbf330e3f1bf3180ef38, range() checks if (stop === null) to detect the single-argument call form, but when range() is called with one argument stop is undefined, not null, so the branch is never entered; stop remains undefined, Math.ceil((stop - start) / step) evaluates to NaN, and new Array<number>(NaN) throws RangeError. This matches underscore.js's original stop == null (loose equality, matching both null and undefined), which the ported version narrowed to ===, silently breaking the single-argument form while keeping the two/three-argument forms working. A search across app/src shows every current call site (app/src/ui/lib/list/list.tsx, app/src/ui/lib/list/section-list.tsx) passes both start and stop, so this is a correctness/API-contract defect in the utility rather than a currently user-visible crash; it would surface the moment any caller (new or future) uses the single-argument form. The reporter's proposed fix (stop?: number | null plus stop == null) directly addresses the root cause.
Activity
prudhvirajkonda8-bot commentedon Nov 17, 2026
A fix with comprehensive unit tests is implemented and pushed to branch:
https://github.com/prudhvirajkonda8-bot/desktop/tree/fix/range-single-argument
Changes:
stop?: number | nullif (stop === null)toif (stop == null)so omittingstopcorrectly setsstop = start || 0andstart = 0app/test/unit/range-test.tsverifyingrange(stop),range(start, stop), stepping, and null handling.desktop-triage commentedon Nov 17, 2026
Triage summary: No duplicates found in a search of
desktop/desktopfor similarrange()/RangeErrorreports. This is a confirmed bug, requestingbug— HIGH confidence — andpriority-3— MEDIUM confidence, since the current codebase has no call site that invokesrange()with a single argument, limiting real-world impact today.Initial hypothesis
At commit 01cde4fd4d7bb07e642bcbf330e3f1bf3180ef38,
range()checksif (stop === null)to detect the single-argument call form, but whenrange()is called with one argumentstopisundefined, notnull, so the branch is never entered;stopremainsundefined,Math.ceil((stop - start) / step)evaluates toNaN, andnew Array<number>(NaN)throwsRangeError. This matches underscore.js's originalstop == null(loose equality, matching bothnullandundefined), which the ported version narrowed to===, silently breaking the single-argument form while keeping the two/three-argument forms working. A search acrossapp/srcshows every current call site (app/src/ui/lib/list/list.tsx,app/src/ui/lib/list/section-list.tsx) passes bothstartandstop, so this is a correctness/API-contract defect in the utility rather than a currently user-visible crash; it would surface the moment any caller (new or future) uses the single-argument form. The reporter's proposed fix (stop?: number | nullplusstop == null) directly addresses the root cause.