Skip to content

Why are environment checks done before warning(), but not invariant()? #6080

@joshwcomeau

Description

@joshwcomeau

While going through the lib source of React, after an NPM install, I noticed some blocks like this:

// EventPropagators.js, line 41
if (process.env.NODE_ENV !== 'production') {
  process.env.NODE_ENV !== 'production' ? warning(domID, 'Dispatching id must not be null') : undefined;
}

All calls to warning() feature their own ternary environment check, so wrapping it in an environment conditional seems unnecessary.

I've already gone through and found/replaced most of the instances, but I wanted to see if there was a philosophical reason for this before submitting a PR.

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions