-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat: Add option to render concurrent roots #507
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
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
098d967
feat: Add option to render concurrent roots
eps1lon 28706ff
Disable this for now to make build green
eps1lon be4b6c5
unmount needs to wrapped in act, rerender not
eps1lon d552d02
cleanup should unmount in sync as well
eps1lon 31d6edc
Add test for state updates
eps1lon 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
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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import React from 'react' | ||
import {act, render, cleanup} from '../' | ||
|
||
test('simple render works like legacy', () => { | ||
const {container} = render(<div>test</div>, {root: 'concurrent'}) | ||
|
||
expect(container).toHaveTextContent('test') | ||
}) | ||
|
||
test('unmounts are flushed in sync', () => { | ||
const {container, unmount} = render(<div>test</div>, {root: 'concurrent'}) | ||
|
||
unmount() | ||
|
||
expect(container.children).toHaveLength(0) | ||
}) | ||
|
||
test('rerender are flushed in sync', () => { | ||
const {container, rerender} = render(<div>foo</div>, {root: 'concurrent'}) | ||
|
||
rerender(<div>bar</div>) | ||
|
||
expect(container).toHaveTextContent('foo') | ||
}) | ||
|
||
test('cleanup unmounts in sync', () => { | ||
const {container} = render(<div>test</div>, {root: 'concurrent'}) | ||
|
||
cleanup() | ||
|
||
expect(container.children).toHaveLength(0) | ||
}) | ||
|
||
test('state updates are concurrent', () => { | ||
function TrackingButton() { | ||
const [clickCount, increment] = React.useReducer(n => n + 1, 0) | ||
|
||
return ( | ||
<button type="button" onClick={increment}> | ||
Clicked {clickCount} times. | ||
</button> | ||
) | ||
} | ||
const {getByRole} = render(<TrackingButton />, {root: 'concurrent'}) | ||
|
||
act(() => { | ||
getByRole('button').click() | ||
expect(getByRole('button')).toHaveTextContent('Clicked 0 times') | ||
}) | ||
|
||
expect(getByRole('button')).toHaveTextContent('Clicked 1 times') | ||
}) |
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 |
---|---|---|
@@ -1 +1,3 @@ | ||
import '@testing-library/jest-dom/extend-expect' | ||
// eslint-disable-next-line import/no-extraneous-dependencies | ||
jest.mock('scheduler', () => require('scheduler/unstable_mock')) | ||
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. Biggest unknown to figure out. I think we need to use this to advance time (or something like that) if we have tests scheduling work (like setState). |
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.
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.
I think that this resolves to the latest stable version. If we want to support the experimental release we have to do an exact version rather than
^
. I believe that's why tests are failing.