-
Notifications
You must be signed in to change notification settings - Fork 48.8k
Detect subscriptions wrapped in startTransition #22271
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
salazarm
merged 23 commits into
facebook:main
from
salazarm:detectSubscriptionsWrappedInStartTransition
Sep 8, 2021
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
8189470
Detect subscriptions wrapped in startTransition
salazarm 9209762
const
salazarm 6e2c361
replace fork
salazarm 411c6cb
prettier
salazarm 7e04c6a
flow fixes
salazarm 1b4adbb
flow fixes
salazarm 1601ab9
prettier again... :c
salazarm e592eef
feature flag + warning function
salazarm ac18db1
more feature flag gating
salazarm d30dfba
remove comment
salazarm fe3cebd
add warnOnSubscriptionInsideStartTransition in www feature flags too
salazarm bec49fc
update warning message
salazarm 57dd9a9
try exporting warning through ReactSharedInternals?
salazarm 437782d
inline warning
salazarm 9525752
and replace-fork
salazarm d3f123d
add flag to native test renderer too
salazarm 8a396d7
add back import... weird caching in vs code :c
salazarm 00d2a86
revert reaction version file after testing build script
salazarm b19a8cd
export flag from dynamic feature flags and use @gate
salazarm c42a125
update gating
salazarm 1252fa8
remove console.logs from testing
salazarm 251fd3c
Merge branch 'main' into detectSubscriptionsWrappedInStartTransition
salazarm 10734d2
pretty
salazarm 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
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 |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @emails react-core | ||
*/ | ||
|
||
'use strict'; | ||
|
||
let React; | ||
let ReactTestRenderer; | ||
let act; | ||
let useState; | ||
let useTransition; | ||
|
||
const SUSPICIOUS_NUMBER_OF_FIBERS_UPDATED = 10; | ||
|
||
describe('ReactStartTransition', () => { | ||
beforeEach(() => { | ||
jest.resetModules(); | ||
React = require('react'); | ||
ReactTestRenderer = require('react-test-renderer'); | ||
act = require('jest-react').act; | ||
useState = React.useState; | ||
useTransition = React.useTransition; | ||
}); | ||
|
||
// @gate warnOnSubscriptionInsideStartTransition || !__DEV__ | ||
it('Warns if a suspicious number of fibers are updated inside startTransition', () => { | ||
salazarm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const subs = new Set(); | ||
const useUserSpaceSubscription = () => { | ||
const setState = useState(0)[1]; | ||
subs.add(setState); | ||
}; | ||
|
||
let triggerHookTransition; | ||
|
||
const Component = ({level}) => { | ||
useUserSpaceSubscription(); | ||
if (level === 0) { | ||
triggerHookTransition = useTransition()[1]; | ||
} | ||
if (level < SUSPICIOUS_NUMBER_OF_FIBERS_UPDATED) { | ||
return <Component level={level + 1} />; | ||
} | ||
return null; | ||
}; | ||
|
||
act(() => { | ||
ReactTestRenderer.create(<Component level={0} />, { | ||
unstable_isConcurrent: true, | ||
}); | ||
}); | ||
|
||
expect(() => { | ||
act(() => { | ||
React.startTransition(() => { | ||
subs.forEach(setState => { | ||
setState(state => state + 1); | ||
}); | ||
}); | ||
}); | ||
}).toWarnDev( | ||
[ | ||
'Detected a large number of updates inside startTransition. ' + | ||
'If this is due to a subscription please re-write it to use React provided hooks. ' + | ||
'Otherwise concurrent mode guarantees are off the table.', | ||
], | ||
{withoutStack: true}, | ||
); | ||
|
||
expect(() => { | ||
act(() => { | ||
triggerHookTransition(() => { | ||
subs.forEach(setState => { | ||
setState(state => state + 1); | ||
}); | ||
}); | ||
}); | ||
}).toWarnDev( | ||
[ | ||
'Detected a large number of updates inside startTransition. ' + | ||
'If this is due to a subscription please re-write it to use React provided hooks. ' + | ||
'Otherwise concurrent mode guarantees are off the table.', | ||
], | ||
{withoutStack: true}, | ||
); | ||
}); | ||
}); |
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
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.
Uh oh!
There was an error while loading. Please reload this page.