-
Notifications
You must be signed in to change notification settings - Fork 46.9k
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
Clean up enableSyncDefaultUpdates flag a bit #26858
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
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
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 |
---|---|---|
|
@@ -125,7 +125,22 @@ describe('ReactExpiration', () => { | |
} | ||
|
||
it('increases priority of updates as time progresses', async () => { | ||
if (gate(flags => flags.enableSyncDefaultUpdates)) { | ||
if (gate(flags => flags.forceConcurrentByDefaultForTesting)) { | ||
ReactNoop.render(<span prop="done" />); | ||
expect(ReactNoop).toMatchRenderedOutput(null); | ||
|
||
// Nothing has expired yet because time hasn't advanced. | ||
flushNextRenderIfExpired(); | ||
expect(ReactNoop).toMatchRenderedOutput(null); | ||
// Advance time a bit, but not enough to expire the low pri update. | ||
ReactNoop.expire(4500); | ||
flushNextRenderIfExpired(); | ||
expect(ReactNoop).toMatchRenderedOutput(null); | ||
// Advance by another second. Now the update should expire and flush. | ||
ReactNoop.expire(500); | ||
flushNextRenderIfExpired(); | ||
expect(ReactNoop).toMatchRenderedOutput(<span prop="done" />); | ||
} else { | ||
ReactNoop.render(<Text text="Step 1" />); | ||
React.startTransition(() => { | ||
ReactNoop.render(<Text text="Step 2" />); | ||
|
@@ -147,21 +162,6 @@ describe('ReactExpiration', () => { | |
ReactNoop.expire(500); | ||
await unstable_waitForExpired(['Step 2']); | ||
expect(ReactNoop).toMatchRenderedOutput('Step 2'); | ||
} else { | ||
ReactNoop.render(<span prop="done" />); | ||
expect(ReactNoop).toMatchRenderedOutput(null); | ||
|
||
// Nothing has expired yet because time hasn't advanced. | ||
flushNextRenderIfExpired(); | ||
expect(ReactNoop).toMatchRenderedOutput(null); | ||
// Advance time a bit, but not enough to expire the low pri update. | ||
ReactNoop.expire(4500); | ||
flushNextRenderIfExpired(); | ||
expect(ReactNoop).toMatchRenderedOutput(null); | ||
// Advance by another second. Now the update should expire and flush. | ||
ReactNoop.expire(500); | ||
flushNextRenderIfExpired(); | ||
expect(ReactNoop).toMatchRenderedOutput(<span prop="done" />); | ||
} | ||
}); | ||
|
||
|
@@ -187,13 +187,9 @@ describe('ReactExpiration', () => { | |
|
||
// First, show what happens for updates in two separate events. | ||
// Schedule an update. | ||
if (gate(flags => flags.enableSyncDefaultUpdates)) { | ||
React.startTransition(() => { | ||
ReactNoop.render(<TextClass text="A" />); | ||
}); | ||
} else { | ||
React.startTransition(() => { | ||
ReactNoop.render(<TextClass text="A" />); | ||
} | ||
}); | ||
// Advance the timer. | ||
Scheduler.unstable_advanceTime(2000); | ||
// Partially flush the first update, then interrupt it. | ||
|
@@ -248,13 +244,10 @@ describe('ReactExpiration', () => { | |
|
||
// First, show what happens for updates in two separate events. | ||
// Schedule an update. | ||
if (gate(flags => flags.enableSyncDefaultUpdates)) { | ||
React.startTransition(() => { | ||
ReactNoop.render(<TextClass text="A" />); | ||
}); | ||
} else { | ||
React.startTransition(() => { | ||
ReactNoop.render(<TextClass text="A" />); | ||
} | ||
}); | ||
|
||
// Advance the timer. | ||
Scheduler.unstable_advanceTime(2000); | ||
// Partially flush the first update, then interrupt it. | ||
|
@@ -320,13 +313,10 @@ describe('ReactExpiration', () => { | |
} | ||
|
||
// Initial mount | ||
if (gate(flags => flags.enableSyncDefaultUpdates)) { | ||
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. Most of these gate checks just switch to use transitions if we're sync by default. But we can just always use transitions, since that what we'll need to do long term to do these tests anyway. |
||
React.startTransition(() => { | ||
ReactNoop.render(<App />); | ||
}); | ||
} else { | ||
React.startTransition(() => { | ||
ReactNoop.render(<App />); | ||
} | ||
}); | ||
|
||
await waitForAll([ | ||
'initial [A] [render]', | ||
'initial [B] [render]', | ||
|
@@ -339,13 +329,10 @@ describe('ReactExpiration', () => { | |
]); | ||
|
||
// Partial update | ||
if (gate(flags => flags.enableSyncDefaultUpdates)) { | ||
React.startTransition(() => { | ||
subscribers.forEach(s => s.setState({text: '1'})); | ||
}); | ||
} else { | ||
React.startTransition(() => { | ||
subscribers.forEach(s => s.setState({text: '1'})); | ||
} | ||
}); | ||
|
||
await waitFor(['1 [A] [render]', '1 [B] [render]']); | ||
|
||
// Before the update can finish, update again. Even though no time has | ||
|
@@ -371,13 +358,9 @@ describe('ReactExpiration', () => { | |
); | ||
} | ||
|
||
if (gate(flags => flags.enableSyncDefaultUpdates)) { | ||
React.startTransition(() => { | ||
root.render(<App />); | ||
}); | ||
} else { | ||
React.startTransition(() => { | ||
root.render(<App />); | ||
} | ||
}); | ||
|
||
await waitFor(['A']); | ||
await waitFor(['B']); | ||
|
@@ -404,13 +387,9 @@ describe('ReactExpiration', () => { | |
</> | ||
); | ||
} | ||
if (gate(flags => flags.enableSyncDefaultUpdates)) { | ||
React.startTransition(() => { | ||
root.render(<App />); | ||
}); | ||
} else { | ||
React.startTransition(() => { | ||
root.render(<App />); | ||
} | ||
}); | ||
|
||
await waitFor(['A']); | ||
await waitFor(['B']); | ||
|
@@ -429,7 +408,26 @@ describe('ReactExpiration', () => { | |
jest.resetModules(); | ||
Scheduler = require('scheduler'); | ||
|
||
if (gate(flags => flags.enableSyncDefaultUpdates)) { | ||
if (gate(flags => flags.forceConcurrentByDefaultForTesting)) { | ||
// Before importing the renderer, advance the current time by a number | ||
// larger than the maximum allowed for bitwise operations. | ||
const maxSigned31BitInt = 1073741823; | ||
Scheduler.unstable_advanceTime(maxSigned31BitInt * 100); | ||
// Now import the renderer. On module initialization, it will read the | ||
// current time. | ||
ReactNoop = require('react-noop-renderer'); | ||
ReactNoop.render('Hi'); | ||
|
||
// The update should not have expired yet. | ||
flushNextRenderIfExpired(); | ||
await waitFor([]); | ||
expect(ReactNoop).toMatchRenderedOutput(null); | ||
// Advance the time some more to expire the update. | ||
Scheduler.unstable_advanceTime(10000); | ||
flushNextRenderIfExpired(); | ||
await waitFor([]); | ||
expect(ReactNoop).toMatchRenderedOutput('Hi'); | ||
} else { | ||
const InternalTestUtils = require('internal-test-utils'); | ||
waitFor = InternalTestUtils.waitFor; | ||
assertLog = InternalTestUtils.assertLog; | ||
|
@@ -446,14 +444,10 @@ describe('ReactExpiration', () => { | |
React = require('react'); | ||
|
||
ReactNoop.render(<Text text="Step 1" />); | ||
if (gate(flags => flags.enableSyncDefaultUpdates)) { | ||
React.startTransition(() => { | ||
ReactNoop.render(<Text text="Step 2" />); | ||
}); | ||
await waitFor(['Step 1']); | ||
} else { | ||
ReactNoop.render('Hi'); | ||
} | ||
React.startTransition(() => { | ||
ReactNoop.render(<Text text="Step 2" />); | ||
}); | ||
await waitFor(['Step 1']); | ||
|
||
// The update should not have expired yet. | ||
await unstable_waitForExpired([]); | ||
|
@@ -464,25 +458,6 @@ describe('ReactExpiration', () => { | |
Scheduler.unstable_advanceTime(10000); | ||
await unstable_waitForExpired(['Step 2']); | ||
expect(ReactNoop).toMatchRenderedOutput('Step 2'); | ||
} else { | ||
// Before importing the renderer, advance the current time by a number | ||
// larger than the maximum allowed for bitwise operations. | ||
const maxSigned31BitInt = 1073741823; | ||
Scheduler.unstable_advanceTime(maxSigned31BitInt * 100); | ||
// Now import the renderer. On module initialization, it will read the | ||
// current time. | ||
ReactNoop = require('react-noop-renderer'); | ||
ReactNoop.render('Hi'); | ||
|
||
// The update should not have expired yet. | ||
flushNextRenderIfExpired(); | ||
await waitFor([]); | ||
expect(ReactNoop).toMatchRenderedOutput(null); | ||
// Advance the time some more to expire the update. | ||
Scheduler.unstable_advanceTime(10000); | ||
flushNextRenderIfExpired(); | ||
await waitFor([]); | ||
expect(ReactNoop).toMatchRenderedOutput('Hi'); | ||
} | ||
}); | ||
|
||
|
@@ -494,13 +469,10 @@ describe('ReactExpiration', () => { | |
// Before scheduling an update, advance the current time. | ||
Scheduler.unstable_advanceTime(10000); | ||
|
||
if (gate(flags => flags.enableSyncDefaultUpdates)) { | ||
React.startTransition(() => { | ||
ReactNoop.render('Hi'); | ||
}); | ||
} else { | ||
React.startTransition(() => { | ||
ReactNoop.render('Hi'); | ||
} | ||
}); | ||
|
||
await unstable_waitForExpired([]); | ||
expect(ReactNoop).toMatchRenderedOutput(null); | ||
|
||
|
@@ -541,13 +513,9 @@ describe('ReactExpiration', () => { | |
|
||
// First demonstrate what happens when there's no starvation | ||
await act(async () => { | ||
if (gate(flags => flags.enableSyncDefaultUpdates)) { | ||
React.startTransition(() => { | ||
updateNormalPri(); | ||
}); | ||
} else { | ||
React.startTransition(() => { | ||
updateNormalPri(); | ||
} | ||
}); | ||
await waitFor(['Sync pri: 0']); | ||
updateSyncPri(); | ||
assertLog(['Sync pri: 1', 'Normal pri: 0']); | ||
|
@@ -565,13 +533,9 @@ describe('ReactExpiration', () => { | |
|
||
// Do the same thing, but starve the first update | ||
await act(async () => { | ||
if (gate(flags => flags.enableSyncDefaultUpdates)) { | ||
React.startTransition(() => { | ||
updateNormalPri(); | ||
}); | ||
} else { | ||
React.startTransition(() => { | ||
updateNormalPri(); | ||
} | ||
}); | ||
await waitFor(['Sync pri: 1']); | ||
|
||
// This time, a lot of time has elapsed since the normal pri update | ||
|
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
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.
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 don't know why i wrote this clowny ass code this way before