-
Notifications
You must be signed in to change notification settings - Fork 50.6k
Adds React event component and React event target support to SSR renderer #15242
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
Merged
trueadm
merged 3 commits into
facebook:master
from
trueadm:add-react-event-types-to-ssr
Mar 28, 2019
Merged
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
Adds React event component and React event target support to SSR rend…
…erer
- Loading branch information
commit 48b26e41092e01470efc191bbd4e789ee6662ef4
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,7 +5,6 @@ | |
| * LICENSE file in the root directory of this source tree. | ||
| * | ||
| * @emails react-core | ||
| * @jest-environment node | ||
|
Contributor
Author
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. This existed from a copy and paste from a previous test file. We don't want it here as we want Jest to give the JSDOM for |
||
| */ | ||
|
|
||
| 'use strict'; | ||
|
|
@@ -16,6 +15,8 @@ let Scheduler; | |
| let ReactFeatureFlags; | ||
| let EventComponent; | ||
| let ReactTestRenderer; | ||
| let ReactDOM; | ||
| let ReactDOMServer; | ||
| let EventTarget; | ||
| let ReactEvents; | ||
|
|
||
|
|
@@ -51,6 +52,16 @@ function initTestRenderer() { | |
| ReactTestRenderer = require('react-test-renderer'); | ||
| } | ||
|
|
||
| function initReactDOM() { | ||
| init(); | ||
| ReactDOM = require('react-dom'); | ||
| } | ||
|
|
||
| function initReactDOMServer() { | ||
| init(); | ||
| ReactDOMServer = require('react-dom/server'); | ||
| } | ||
|
|
||
| // This is a new feature in Fiber so I put it in its own test file. It could | ||
| // probably move to one of the other test files once it is official. | ||
| describe('ReactFiberEvents', () => { | ||
|
|
@@ -358,4 +369,213 @@ describe('ReactFiberEvents', () => { | |
| ); | ||
| }); | ||
| }); | ||
|
|
||
| describe('ReactDOM', () => { | ||
| beforeEach(() => { | ||
| initReactDOM(); | ||
| EventComponent = createReactEventComponent(); | ||
| EventTarget = ReactEvents.TouchHitTarget; | ||
| }); | ||
|
|
||
| it('should render a simple event component with a single child', () => { | ||
| const Test = () => ( | ||
| <EventComponent> | ||
| <div>Hello world</div> | ||
| </EventComponent> | ||
| ); | ||
| const container = document.createElement('div'); | ||
| ReactDOM.render(<Test />, container); | ||
| expect(Scheduler).toFlushWithoutYielding(); | ||
| expect(container.innerHTML).toBe('<div>Hello world</div>'); | ||
| }); | ||
|
|
||
| it('should warn when an event component has a direct text child', () => { | ||
| const Test = () => <EventComponent>Hello world</EventComponent>; | ||
|
|
||
| expect(() => { | ||
| const container = document.createElement('div'); | ||
| ReactDOM.render(<Test />, container); | ||
| expect(Scheduler).toFlushWithoutYielding(); | ||
| }).toWarnDev( | ||
| 'Warning: validateDOMNesting: React event components cannot have text DOM nodes as children. ' + | ||
| 'Wrap the child text "Hello world" in an element.', | ||
| ); | ||
| }); | ||
|
|
||
| it('should warn when an event component has a direct text child #2', () => { | ||
| const ChildWrapper = () => 'Hello world'; | ||
| const Test = () => ( | ||
| <EventComponent> | ||
| <ChildWrapper /> | ||
| </EventComponent> | ||
| ); | ||
|
|
||
| expect(() => { | ||
| const container = document.createElement('div'); | ||
| ReactDOM.render(<Test />, container); | ||
| expect(Scheduler).toFlushWithoutYielding(); | ||
| }).toWarnDev( | ||
| 'Warning: validateDOMNesting: React event components cannot have text DOM nodes as children. ' + | ||
| 'Wrap the child text "Hello world" in an element.', | ||
| ); | ||
| }); | ||
|
|
||
| it('should render a simple event component with a single event target', () => { | ||
| const Test = () => ( | ||
| <EventComponent> | ||
| <EventTarget> | ||
| <div>Hello world</div> | ||
| </EventTarget> | ||
| </EventComponent> | ||
| ); | ||
|
|
||
| const container = document.createElement('div'); | ||
| ReactDOM.render(<Test />, container); | ||
| expect(Scheduler).toFlushWithoutYielding(); | ||
| expect(container.innerHTML).toBe('<div>Hello world</div>'); | ||
|
|
||
| const Test2 = () => ( | ||
| <EventComponent> | ||
| <EventTarget> | ||
| <span>I am now a span</span> | ||
| </EventTarget> | ||
| </EventComponent> | ||
| ); | ||
|
|
||
| ReactDOM.render(<Test2 />, container); | ||
| expect(Scheduler).toFlushWithoutYielding(); | ||
| expect(container.innerHTML).toBe('<span>I am now a span</span>'); | ||
| }); | ||
|
|
||
| it('should warn when an event target has a direct text child', () => { | ||
| const Test = () => ( | ||
| <EventComponent> | ||
| <EventTarget>Hello world</EventTarget> | ||
| </EventComponent> | ||
| ); | ||
|
|
||
| expect(() => { | ||
| const container = document.createElement('div'); | ||
| ReactDOM.render(<Test />, container); | ||
| expect(Scheduler).toFlushWithoutYielding(); | ||
| }).toWarnDev([ | ||
| 'Warning: validateDOMNesting: React event targets cannot have text DOM nodes as children. ' + | ||
| 'Wrap the child text "Hello world" in an element.', | ||
| 'Warning: <TouchHitTarget> must have a single DOM element as a child. Found no children.', | ||
| ]); | ||
| }); | ||
|
|
||
| it('should warn when an event target has a direct text child #2', () => { | ||
| const ChildWrapper = () => 'Hello world'; | ||
| const Test = () => ( | ||
| <EventComponent> | ||
| <EventTarget> | ||
| <ChildWrapper /> | ||
| </EventTarget> | ||
| </EventComponent> | ||
| ); | ||
|
|
||
| expect(() => { | ||
| const container = document.createElement('div'); | ||
| ReactDOM.render(<Test />, container); | ||
| expect(Scheduler).toFlushWithoutYielding(); | ||
| }).toWarnDev([ | ||
| 'Warning: validateDOMNesting: React event targets cannot have text DOM nodes as children. ' + | ||
| 'Wrap the child text "Hello world" in an element.', | ||
| 'Warning: <TouchHitTarget> must have a single DOM element as a child. Found no children.', | ||
| ]); | ||
| }); | ||
|
|
||
| it('should warn when an event target has more than one child', () => { | ||
| const Test = () => ( | ||
| <EventComponent> | ||
| <EventTarget> | ||
| <span>Child 1</span> | ||
| <span>Child 2</span> | ||
| </EventTarget> | ||
| </EventComponent> | ||
| ); | ||
|
|
||
| const container = document.createElement('div'); | ||
| expect(() => { | ||
| ReactDOM.render(<Test />, container); | ||
| expect(Scheduler).toFlushWithoutYielding(); | ||
| }).toWarnDev( | ||
| 'Warning: <TouchHitTarget> must only have a single DOM element as a child. Found many children.', | ||
| ); | ||
| // This should not fire a warning, as this is now valid. | ||
| const Test2 = () => ( | ||
| <EventComponent> | ||
| <EventTarget> | ||
| <span>Child 1</span> | ||
| </EventTarget> | ||
| </EventComponent> | ||
| ); | ||
| ReactDOM.render(<Test2 />, container); | ||
| expect(Scheduler).toFlushWithoutYielding(); | ||
| expect(container.innerHTML).toBe('<span>Child 1</span>'); | ||
| }); | ||
|
|
||
| it('should warn if an event target is not a direct child of an event component', () => { | ||
| const Test = () => ( | ||
| <EventComponent> | ||
| <div> | ||
| <EventTarget> | ||
| <span>Child 1</span> | ||
| </EventTarget> | ||
| </div> | ||
| </EventComponent> | ||
| ); | ||
|
|
||
| expect(() => { | ||
| const container = document.createElement('div'); | ||
| ReactDOM.render(<Test />, container); | ||
| expect(Scheduler).toFlushWithoutYielding(); | ||
| }).toWarnDev( | ||
| 'Warning: validateDOMNesting: React event targets must be direct children of event components.', | ||
| ); | ||
| }); | ||
| }); | ||
|
|
||
| describe('ReactDOMServer', () => { | ||
| beforeEach(() => { | ||
| initReactDOMServer(); | ||
| EventComponent = createReactEventComponent(); | ||
| EventTarget = ReactEvents.TouchHitTarget; | ||
| }); | ||
|
|
||
| it('should render a simple event component with a single child', () => { | ||
| const Test = () => ( | ||
| <EventComponent> | ||
| <div>Hello world</div> | ||
| </EventComponent> | ||
| ); | ||
| const output = ReactDOMServer.renderToString(<Test />); | ||
| expect(output).toBe('<div>Hello world</div>'); | ||
| }); | ||
|
|
||
| it('should render a simple event component with a single event target', () => { | ||
| const Test = () => ( | ||
| <EventComponent> | ||
| <EventTarget> | ||
| <div>Hello world</div> | ||
| </EventTarget> | ||
| </EventComponent> | ||
| ); | ||
|
|
||
| let output = ReactDOMServer.renderToString(<Test />); | ||
| expect(output).toBe('<div>Hello world</div>'); | ||
|
|
||
| const Test2 = () => ( | ||
| <EventComponent> | ||
| <EventTarget> | ||
| <span>I am now a span</span> | ||
| </EventTarget> | ||
| </EventComponent> | ||
| ); | ||
|
|
||
| output = ReactDOMServer.renderToString(<Test2 />); | ||
| expect(output).toBe('<span>I am now a span</span>'); | ||
| }); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.