-
Notifications
You must be signed in to change notification settings - Fork 47.5k
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
Default updates should not interrupt transitions #20771
Merged
acdlite
merged 1 commit into
facebook:master
from
acdlite:default-updates-dont-interrupt
Feb 10, 2021
+239
−4
Merged
Changes from all commits
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
There are no files selected for viewing
This file contains 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 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 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 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 |
---|---|---|
|
@@ -15,6 +15,7 @@ let ReactNoop; | |
let Scheduler; | ||
let Suspense; | ||
let useState; | ||
let useLayoutEffect; | ||
let useTransition; | ||
let startTransition; | ||
let act; | ||
|
@@ -30,6 +31,7 @@ describe('ReactTransition', () => { | |
ReactNoop = require('react-noop-renderer'); | ||
Scheduler = require('scheduler'); | ||
useState = React.useState; | ||
useLayoutEffect = React.useLayoutEffect; | ||
useTransition = React.unstable_useTransition; | ||
Suspense = React.Suspense; | ||
startTransition = React.unstable_startTransition; | ||
|
@@ -773,4 +775,204 @@ describe('ReactTransition', () => { | |
}); | ||
}, | ||
); | ||
|
||
// @gate experimental | ||
// @gate enableCache | ||
it('should render normal pri updates scheduled after transitions before transitions', async () => { | ||
let updateTransitionPri; | ||
let updateNormalPri; | ||
function App() { | ||
const [normalPri, setNormalPri] = useState(0); | ||
const [transitionPri, setTransitionPri] = useState(0); | ||
updateTransitionPri = () => | ||
startTransition(() => setTransitionPri(n => n + 1)); | ||
updateNormalPri = () => setNormalPri(n => n + 1); | ||
|
||
useLayoutEffect(() => { | ||
Scheduler.unstable_yieldValue('Commit'); | ||
}); | ||
|
||
return ( | ||
<Suspense fallback={<Text text="Loading..." />}> | ||
<Text text={'Transition pri: ' + transitionPri} /> | ||
{', '} | ||
<Text text={'Normal pri: ' + normalPri} /> | ||
</Suspense> | ||
); | ||
} | ||
|
||
const root = ReactNoop.createRoot(); | ||
await act(async () => { | ||
root.render(<App />); | ||
}); | ||
|
||
// Initial render. | ||
expect(Scheduler).toHaveYielded([ | ||
'Transition pri: 0', | ||
'Normal pri: 0', | ||
'Commit', | ||
]); | ||
expect(root).toMatchRenderedOutput('Transition pri: 0, Normal pri: 0'); | ||
|
||
await act(async () => { | ||
updateTransitionPri(); | ||
updateNormalPri(); | ||
}); | ||
|
||
expect(Scheduler).toHaveYielded([ | ||
// Normal update first. | ||
'Transition pri: 0', | ||
'Normal pri: 1', | ||
'Commit', | ||
|
||
// Then transition update. | ||
'Transition pri: 1', | ||
'Normal pri: 1', | ||
'Commit', | ||
]); | ||
expect(root).toMatchRenderedOutput('Transition pri: 1, Normal pri: 1'); | ||
}); | ||
|
||
// @gate experimental | ||
// @gate enableCache | ||
it('should render normal pri updates before transition suspense retries', async () => { | ||
let updateTransitionPri; | ||
let updateNormalPri; | ||
function App() { | ||
const [transitionPri, setTransitionPri] = useState(false); | ||
const [normalPri, setNormalPri] = useState(0); | ||
|
||
updateTransitionPri = () => startTransition(() => setTransitionPri(true)); | ||
updateNormalPri = () => setNormalPri(n => n + 1); | ||
|
||
useLayoutEffect(() => { | ||
Scheduler.unstable_yieldValue('Commit'); | ||
}); | ||
|
||
return ( | ||
<Suspense fallback={<Text text="Loading..." />}> | ||
{transitionPri ? <AsyncText text="Async" /> : <Text text="(empty)" />} | ||
{', '} | ||
<Text text={'Normal pri: ' + normalPri} /> | ||
</Suspense> | ||
); | ||
} | ||
|
||
const root = ReactNoop.createRoot(); | ||
await act(async () => { | ||
root.render(<App />); | ||
}); | ||
|
||
// Initial render. | ||
expect(Scheduler).toHaveYielded(['(empty)', 'Normal pri: 0', 'Commit']); | ||
expect(root).toMatchRenderedOutput('(empty), Normal pri: 0'); | ||
|
||
await act(async () => { | ||
updateTransitionPri(); | ||
}); | ||
|
||
expect(Scheduler).toHaveYielded([ | ||
// Suspend. | ||
'Suspend! [Async]', | ||
'Normal pri: 0', | ||
'Loading...', | ||
]); | ||
expect(root).toMatchRenderedOutput('(empty), Normal pri: 0'); | ||
|
||
await act(async () => { | ||
await resolveText('Async'); | ||
updateNormalPri(); | ||
}); | ||
|
||
expect(Scheduler).toHaveYielded([ | ||
// Normal pri update. | ||
'(empty)', | ||
'Normal pri: 1', | ||
'Commit', | ||
|
||
// Promise resolved, retry flushed. | ||
'Async', | ||
'Normal pri: 1', | ||
'Commit', | ||
]); | ||
expect(root).toMatchRenderedOutput('Async, Normal pri: 1'); | ||
}); | ||
|
||
// @gate experimental | ||
// @gate enableCache | ||
it('should not interrupt transitions with normal pri updates', async () => { | ||
let updateNormalPri; | ||
let updateTransitionPri; | ||
function App() { | ||
const [transitionPri, setTransitionPri] = useState(0); | ||
const [normalPri, setNormalPri] = useState(0); | ||
updateTransitionPri = () => | ||
startTransition(() => setTransitionPri(n => n + 1)); | ||
updateNormalPri = () => setNormalPri(n => n + 1); | ||
|
||
useLayoutEffect(() => { | ||
Scheduler.unstable_yieldValue('Commit'); | ||
}); | ||
return ( | ||
<> | ||
<Text text={'Transition pri: ' + transitionPri} /> | ||
{', '} | ||
<Text text={'Normal pri: ' + normalPri} /> | ||
</> | ||
); | ||
} | ||
|
||
const root = ReactNoop.createRoot(); | ||
await ReactNoop.act(async () => { | ||
root.render(<App />); | ||
}); | ||
expect(Scheduler).toHaveYielded([ | ||
'Transition pri: 0', | ||
'Normal pri: 0', | ||
'Commit', | ||
]); | ||
expect(root).toMatchRenderedOutput('Transition pri: 0, Normal pri: 0'); | ||
|
||
await ReactNoop.act(async () => { | ||
updateTransitionPri(); | ||
|
||
expect(Scheduler).toFlushAndYieldThrough([ | ||
// Start transition update. | ||
'Transition pri: 1', | ||
]); | ||
|
||
// Schedule normal pri update during transition update. | ||
// This should not interrupt. | ||
updateNormalPri(); | ||
}); | ||
|
||
if (gate(flags => flags.enableNonInterruptingNormalPri)) { | ||
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 nvm I see |
||
expect(Scheduler).toHaveYielded([ | ||
// Finish transition update. | ||
'Normal pri: 0', | ||
'Commit', | ||
|
||
// Normal pri update. | ||
'Transition pri: 1', | ||
'Normal pri: 1', | ||
'Commit', | ||
]); | ||
|
||
expect(root).toMatchRenderedOutput('Transition pri: 1, Normal pri: 1'); | ||
} else { | ||
expect(Scheduler).toHaveYielded([ | ||
// Interrupt! Render normal pri update. | ||
'Transition pri: 0', | ||
'Normal pri: 1', | ||
'Commit', | ||
|
||
// Restart transition update. | ||
'Transition pri: 1', | ||
'Normal pri: 1', | ||
'Commit', | ||
]); | ||
|
||
expect(root).toMatchRenderedOutput('Transition pri: 1, Normal pri: 1'); | ||
} | ||
}); | ||
}); |
This file contains 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 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 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 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 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 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 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 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 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 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.
Hmm why doesn't this require a
@gate enableNonInterruptingNormalPri
? Does it pass even before the fix?