-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Element: Fix serializer handling of multiple distinct contexts #21156
Changes from all commits
6313fad
90dacf0
014e884
947a58f
c64b80a
621789b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -317,6 +317,75 @@ describe( 'renderElement()', () => { | |
expect( result ).toBe( 'inner provided|outer provided' ); | ||
} ); | ||
|
||
it( 'renders Context gracefully', () => { | ||
const Context = createContext( 'Default' ); | ||
|
||
const result = renderElement( | ||
<Context>{ ( value ) => value }</Context> | ||
); | ||
|
||
expect( result ).toBe( 'Default' ); | ||
} ); | ||
|
||
it( 'renders proper value through Context API when nested, distinct providers present', () => { | ||
const { | ||
Consumer: FirstConsumer, | ||
Provider: FirstProvider, | ||
} = createContext(); | ||
const { | ||
Consumer: SecondConsumer, | ||
Provider: SecondProvider, | ||
} = createContext(); | ||
|
||
const result = renderElement( | ||
<FirstProvider value="First"> | ||
<FirstConsumer> | ||
{ ( first ) => ( | ||
<SecondProvider value="Second"> | ||
<SecondConsumer> | ||
{ ( second ) => | ||
`First: ${ first }, Second: ${ second }` | ||
} | ||
</SecondConsumer> | ||
</SecondProvider> | ||
) } | ||
</FirstConsumer> | ||
</FirstProvider> | ||
); | ||
|
||
expect( result ).toBe( 'First: First, Second: Second' ); | ||
} ); | ||
|
||
it( 'renders proper value through Context API when nested, distinct providers present (mixed order)', () => { | ||
const { | ||
Consumer: FirstConsumer, | ||
Provider: FirstProvider, | ||
} = createContext(); | ||
const { | ||
Consumer: SecondConsumer, | ||
Provider: SecondProvider, | ||
} = createContext(); | ||
|
||
const result = renderElement( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see that e2e tests fail for blocks that have nesting. I'm wondering if there should be another unit tests that replicate how <FirstProvider value="First">
<FirstConsumer>
{ ( first ) => (
<SecondProvider value="Second">
<SecondConsumer>
{ ( second ) => `First: { first }, Second: ${ second }` }
</SecondConsumer>
</SecondProvider>
) }
</FirstConsumer>
</FirstProvider> Although, I don't see any reason why it would make any difference. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not really sure what's going on with the end-to-end tests, to be honest. I've not been able to reproduce those same failures in my local environment. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added a test case for this in 90dacf0 for good measure. It passes, as expected. Still struggling with the end-to-end tests in Travis. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've just realized that we use one shared context for <Provider value="outer">
<Consumer>
{ ( outter ) => (
< Provider value="inner">
<Consumer>
{ ( inner ) => `Outer: { outer }, Inner: ${ inner }` }
</Consumer>
</Provider>
) }
</Consumer>
</Provider> I don't think it's much different from a similar existing test though. I can't think of any reason why it fails on Travis :( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh no :( |
||
<FirstProvider value="First"> | ||
<SecondProvider value="Second"> | ||
<FirstConsumer> | ||
{ ( first ) => ( | ||
<> | ||
First: { first }, Second:{ ' ' } | ||
<SecondConsumer> | ||
{ ( second ) => second } | ||
</SecondConsumer> | ||
</> | ||
) } | ||
</FirstConsumer> | ||
</SecondProvider> | ||
</FirstProvider> | ||
); | ||
|
||
expect( result ).toBe( 'First: First, Second: Second' ); | ||
} ); | ||
|
||
it( 'renders RawHTML as its unescaped children', () => { | ||
const result = renderElement( <RawHTML>{ '<img/>' }</RawHTML> ); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason why we use this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's meant to be temporary, an experiment to see if it would fix the previously-observed issue to use a very predictable implementation.