Skip to content

[Fiber] Replace throw new Error with invariant module - #8926

Merged
acdlite merged 3 commits into
react:masterfrom
acdlite:fiberuseinvariant
Feb 6, 2017
Merged

acdlite merged 3 commits into
react:masterfrom
acdlite:fiberuseinvariant

Conversation

@acdlite

@acdlite acdlite commented Feb 3, 2017 •

Copy link
Copy Markdown
Collaborator

The umbrella task says they should have "sensible messages." Does this include internal invariants (ones that only throw if there's a bug in React)?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't a behavior change in your PR, but we shouldn't have any DEV-only exceptions. Can we make this a warning (either here in a new PR)?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. There's an identical non-dev check that happens below. I'll refactor so there's only one check.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, we (necessarily) call the iterator twice right? We tried to avoid that before and the code was super super messy.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking if there's no iterator in DEV, skip the key warning and go straight to the prod invariant, which will throw.

@gaearon

gaearon commented Feb 4, 2017

Copy link
Copy Markdown
Collaborator

The umbrella task says they should have "sensible messages." Does this include internal invariants (ones that only throw if there's a bug in React)?

I meant that we should make sure any internal variants clearly explain this is a bug in React and ask to file an issue.

@gaearon gaearon left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add "This is likely a bug in React." to all internal messages?

@acdlite

acdlite commented Feb 6, 2017

Copy link
Copy Markdown
Collaborator Author

@gaearon Updated

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will count against the byte size, is this intentional?
It doesn’t matter that much in the grand scheme of things, just wondering if this was intended or not.
If you just hardcoded it everywhere then it would get stripped out.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hrrm, didn't think about that. Don't think it makes a substantial difference but we can change later.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer we do it now so it (or similar patterns) don't keep spreading.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Me too, let's inline please.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes plz.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure we can count this as an internal error? The object is supplied by the user code.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, my bad

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is correct because if it's not an iterator then we shouldn't have reached this code path.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless user specified code returns something different the second time we read @@iterator, no?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could be a getter.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That check doesn't check the type of the iterator.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also internal.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe worth checking for undefined too here and above? != null

@acdlite acdlite Feb 6, 2017 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I'll loosen those up. Should do a pass at some point and change all our maybe types to null unions. Though props is currently an any, which is worse.

The message tells users that the error is likely due to a bug in React,
and that they should file an issue.
@acdlite
acdlite merged commit a2c49f4 into react:master Feb 6, 2017
@gaearon

gaearon commented Feb 6, 2017

Copy link
Copy Markdown
Collaborator

Would you inline in a follow up?

mrizwanashiq pushed a commit to mrizwanashiq/react that referenced this pull request Jun 25, 2026
[Fiber] Replace `throw new Error` with invariant module
hanzo-dev pushed a commit to hanzoai/react that referenced this pull request Sep 9, 2026
[Fiber] Replace `throw new Error` with invariant module
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants