Repository navigation
Allow returning null as host context - #9278
Conversation
|
Circle failed |
|
I saw. Fixed now. :) |
| 'Expected host context to exist. This error is likely caused by a bug ' + | ||
| 'in React. Please file an issue.', | ||
| ); | ||
| return (c: any); |
There was a problem hiding this comment.
Why do you need this cast?
There was a problem hiding this comment.
Proof it isn't NoContextT.
There was a problem hiding this comment.
Flow doesn't know NO_CONTEXT is the only possible inhabitant.
| var React; | ||
| var ReactFiberReconciler; | ||
|
|
||
| describe('ReactCoroutine', () => { |
| ReactFiberReconciler = require('ReactFiberReconciler'); | ||
| }); | ||
|
|
||
| it('works with null host context', () => { |
There was a problem hiding this comment.
Instead of a separate test for an internal, maybe we can change ReactNoop to return null instead? It's not using the context anyway.
There was a problem hiding this comment.
This is public-ish renderer API. I'd rather have a test just for this so we don't change it later accidentally.
| ? contextStackCursor.current | ||
| : emptyObject; | ||
| const rootInstance = requiredContext(rootInstanceStackCursor.current); | ||
| const context = requiredContext(contextStackCursor.current); |
There was a problem hiding this comment.
This didn't use to be required. Does it matter? I don't remember why I didn't check it.
There was a problem hiding this comment.
It used to be emptyObject if missing which seems wrong.
There was a problem hiding this comment.
At the very least, it was inconsistent with our declared type signatures for the host config (but emptyObject isn't typed so).
If your renderer doesn't use host context, you might prefer to return null. This used to give an error: > Invariant Violation: Expected host context to exist. This error is likely caused by a bug in React. Please file an issue. I use a sentinel value instead now. The code in ReactFiberHostContext is a little complicated now. We could probably also just remove the invariants.
If your renderer doesn't use host context, you might prefer to return null. This used to give an error: > Invariant Violation: Expected host context to exist. This error is likely caused by a bug in React. Please file an issue. I use a sentinel value instead now. The code in ReactFiberHostContext is a little complicated now. We could probably also just remove the invariants.
If your renderer doesn't use host context, you might prefer to return null. This used to give an error:
I use a sentinel value instead now.
The code in ReactFiberHostContext is a little complicated now. We could probably also just remove the invariants.