-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat: Use concurrent React when available #937
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
eps1lon
merged 22 commits into
testing-library:alpha
from
eps1lon:feat/concurrent-render
Sep 13, 2021
+210
−83
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
f684fdc
React 18 compat
eps1lon 9858181
concurrent: false -> legacyRoot: true
eps1lon b3a8858
fix logic for default of used root implementation
eps1lon e6991a2
Add links to reactwg discussions
eps1lon 7cff132
fix waitFor* in concurrent Reat
eps1lon 1444268
cleanup
eps1lon bf22542
Let full matrix build
eps1lon 59d28b6
Ignore coverage for now
eps1lon cea49ef
Mark scheduler mocking as TODO
eps1lon aa0a890
Merge codecov reports across react versions
eps1lon 994e43c
Exclude internal bugs from coverage
eps1lon c54df93
Add failing tests for waitFor and findBy
eps1lon c83a9a4
{ hydrate: true } -> hydrateRoot
eps1lon 7887030
Revert "test: Ignore React 18 legacy root deprecation warnings (#929)"
eps1lon 2138e2f
Update minimal coverage
eps1lon f59f162
Use isomorphic act if available
eps1lon 78eaa06
Inline waitFor from dtl
eps1lon a2a9d4a
fix wait-for
eps1lon 60395b4
Use advanceTimersWrapper
eps1lon e9f188c
Use latest DTL version
eps1lon b0fd654
Merge branch 'alpha' into feat/concurrent-render
eps1lon f9c851e
Document expected "missing act"
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,15 @@ | ||
const {jest: jestConfig} = require('kcd-scripts/config') | ||
|
||
module.exports = Object.assign(jestConfig, { | ||
coverageThreshold: { | ||
...jestConfig.coverageThreshold, | ||
// full coverage across the build matrix (React 17, 18) but not in a single job | ||
'./src/pure': { | ||
// minimum coverage of jobs using React 17 and 18 | ||
branches: 80, | ||
functions: 78, | ||
lines: 84, | ||
statements: 84, | ||
}, | ||
}, | ||
}) |
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
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
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
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
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 |
---|---|---|
|
@@ -2,8 +2,9 @@ import * as React from 'react' | |
import ReactDOM from 'react-dom' | ||
import * as testUtils from 'react-dom/test-utils' | ||
|
||
const reactAct = testUtils.act | ||
const actSupported = reactAct !== undefined | ||
const isomorphicAct = React.unstable_act | ||
const domAct = testUtils.act | ||
const actSupported = domAct !== undefined | ||
|
||
// act is supported [email protected] | ||
// so for versions that don't have act from test utils | ||
|
@@ -14,7 +15,7 @@ function actPolyfill(cb) { | |
ReactDOM.render(<div />, document.createElement('div')) | ||
} | ||
|
||
const act = reactAct || actPolyfill | ||
const act = isomorphicAct || domAct || actPolyfill | ||
|
||
let youHaveBeenWarned = false | ||
let isAsyncActSupported = null | ||
|
@@ -50,7 +51,7 @@ function asyncAct(cb) { | |
} | ||
let cbReturn, result | ||
try { | ||
result = reactAct(() => { | ||
result = domAct(() => { | ||
cbReturn = cb() | ||
return cbReturn | ||
}) | ||
|
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,20 +1 @@ | ||
import '@testing-library/jest-dom/extend-expect' | ||
|
||
let consoleErrorMock | ||
|
||
beforeEach(() => { | ||
const originalConsoleError = console.error | ||
consoleErrorMock = jest | ||
.spyOn(console, 'error') | ||
.mockImplementation((message, ...optionalParams) => { | ||
// Ignore ReactDOM.render/ReactDOM.hydrate deprecation warning | ||
if (message.indexOf('Use createRoot instead.') !== -1) { | ||
return | ||
} | ||
originalConsoleError(message, ...optionalParams) | ||
}) | ||
}) | ||
|
||
afterEach(() => { | ||
consoleErrorMock.mockRestore() | ||
}) |
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
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.
Is this necessary to configure?
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.
TL;DR: I misunderstood the question. I think we don't need to configure that because it's the default. I still leave my original long winded explainer for future reference and because it made me realize I still don't fully understand why
act()
behaves the way it does.So let's say we have
and the button would only appear after two intervals. This would previously translate to
The problem is that React only flushes effects when exiting the
act
call. SocheckCallback
could not assert on any effect scheduled due to timers being advanced.If we just configure
unstable_advanceTimersWrapper
to useact
we would now haveThe problem now is that React only flushes scheduled effects in the outermost act so we need to remove that.
I think I good question is why only the outermost
act
is considered.Uh oh!
There was an error while loading. Please reload this page.
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 need to double check something though. React 17 will no longer have
act
as theasyncWrapper
but somehow our React 17 tests are still passing. So either our tests are incomplete or this was dead code.Uh oh!
There was an error while loading. Please reload this page.
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.
Did you mean React 18? If so, following this comment I'm not sure it won't work, it's just not needed anymore, isn't it?
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.
No, 17. I was reffering to our usage though. I changed the behavior for React 17 as well but no tests started failing.
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.
Tests are incomplete due to usage of class components. Backported the new tests with a function component in #962 that should ensure
asyncWrapper
is still present in React 17.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.
Prevented mild disaster since the new tests also uncovered silly lines such as
typeof React.startTransition !== undefined
. It's eitherReact.startTransition !== undefined
ortypeof React.startTransition !== 'undefined'
.Also uncovered that the "configure wrapper" approach is not compatible with supporting different timers across multiple versions of react.
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.
Going to leave this a bit until the next WG meeting. Unclear what the timeline is for work on act. Feels like the core team already moved on but there are still glaring holes in the behavior of act().
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.
Though I'm personally fine with shipping this as an alpha to test integration. We haven't solved all problems yet for the alpha but neither has React itself. I'm fine with shipping this in an incomplete state since I can just blame React about all the missing parts 😎
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.
Sounds fine to me 👍