Repository navigation
fix(NavigationStack): a push or pop from rest starts when its task ends #12010
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
Changes from all commits
9ed518e
d9b5c00
6875f4a
4c98b3a
7dbac59
21e1fc5
73c1c5e
c8acf65
b78f396
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1150,6 +1150,68 @@ function blockDuringPush(page: Page, ms: number) { | |
| }); | ||
| } | ||
|
|
||
| test('a push whose commit blocks the main thread starts from its first frame', async ({ | ||
| page, | ||
| }) => { | ||
| // A heavy screen blocks the main thread in the task that pushes it (here | ||
| // for 300 ms, right after the stack mounts it). The push starts when that | ||
| // task ends, so its first frames show it near where it starts. Dated | ||
| // before the block, it would show almost all of its travel at once. The | ||
| // check reads the time since the block with the position, because an | ||
| // engine's first frames after a long task can take far longer than 16 ms. | ||
| const {driver, width} = await openStack(page, 'settings'); | ||
| await page.evaluate(() => { | ||
| const observer = new MutationObserver(() => { | ||
| if ( | ||
| document.querySelector('[data-navigation-screen="screen-General"]') == | ||
| null | ||
| ) { | ||
| return; | ||
| } | ||
| observer.disconnect(); | ||
| const until = performance.now() + 300; | ||
| while (performance.now() < until) { | ||
| // Hold the main thread, as a heavy commit does. | ||
| } | ||
| (window as Window & {blockEnd?: number}).blockEnd = performance.now(); | ||
| }); | ||
| observer.observe(document.body, {childList: true, subtree: true}); | ||
| }); | ||
| await driver.tap(await rowCenter(page, 'General')); | ||
| // The second frame after the block, and how long after the block it ran. | ||
| const {x, sinceBlock} = await page.evaluate( | ||
| () => | ||
| new Promise<{x: number; sinceBlock: number}>(resolve => { | ||
| requestAnimationFrame(() => | ||
| requestAnimationFrame(() => { | ||
| const pushed = document.querySelector( | ||
| '[data-navigation-screen="screen-General"]', | ||
| ); | ||
| const value = | ||
| pushed == null ? 'none' : getComputedStyle(pushed).translate; | ||
| const blockEnd = | ||
| (window as Window & {blockEnd?: number}).blockEnd ?? 0; | ||
|
Comment on lines
+1192
to
+1193
Contributor
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. Non-blocking (Miss): if the MutationObserver never sees const blockEnd = (window as Window & {blockEnd?: number}).blockEnd;
resolve({x, blockEnd, sinceBlock: performance.now() - (blockEnd ?? 0)});
// after page.evaluate:
expect(blockEnd).toBeDefined(); |
||
| resolve({ | ||
| x: value === 'none' ? 0 : parseFloat(value), | ||
| sinceBlock: performance.now() - blockEnd, | ||
| }); | ||
| }), | ||
| ); | ||
| }), | ||
| ); | ||
| // The push spring from the trailing edge (OMEGA, starting at | ||
| // PUSH_VELOCITY): about 70 % of the width is still to travel after 33 ms. | ||
| // The share left `ms` into the push: | ||
| const leftAt = (ms: number) => { | ||
| const s = ms / 1000; | ||
| return (1 + (OMEGA - PUSH_VELOCITY) * s) * Math.exp(-OMEGA * s); | ||
| }; | ||
| // Started at the block's end, at least half of what the spring leaves at | ||
| // that time is still to travel. Dated before the 300 ms block, almost none | ||
| // would be. | ||
| expect(Math.abs(x) / width).toBeGreaterThan(0.5 * leftAt(sinceBlock)); | ||
| }); | ||
|
|
||
| test('a push keeps advancing every frame while the main thread is blocked', async ({ | ||
| page, | ||
| browserName, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.