Skip to content

Range() defaulting to infinite is easy to misuse and end up with a silent infinite loop #1801

Closed
@sergueif

Description

@sergueif

Hey, big fan here, long time user, first time caller. First, let me say, sharp tools can be a pleasure to use, but I also believe workplace injuries should be reported.

what happened

Someone on my team wrote an innocent-looking component with the help of Range():

const SomeComponent = ({min, max}) => {
  return <div>
    <!-- more html -->
    {Range(min, max).map(num => <option value={num}>{num}</option>)}
  </div>
}

called it some place and moved on with their day.

Later, in a different context, rendering the above component resulted in an infinite loop that took over an hour to find. The cause, of course is that Range(undefined, undefined) or without arguments is infinite. Seems it would be safer if getting an infinite range required being more explicit.

I anticipate this may get shut down, cause like "read the docs, be careful, use typescript" and what not, but has anyone else been burned by this? Am I the first to get infinite Range unintentionally?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions