Skip to content

Commit 5717f19

Browse files
authored
[react-dom] Enforce small gap between completed navigation and default Transition indicator (facebook#33354)
1 parent b07717d commit 5717f19

File tree

3 files changed

+45
-2
lines changed

3 files changed

+45
-2
lines changed

fixtures/flight/src/App.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import Button from './Button.js';
1212
import Form from './Form.js';
1313
import {Dynamic} from './Dynamic.js';
1414
import {Client} from './Client.js';
15+
import {Navigate} from './Navigate.js';
1516

1617
import {Note} from './cjs/Note.js';
1718

@@ -89,6 +90,7 @@ export default async function App({prerender}) {
8990
<Note />
9091
<Foo>{dedupedChild}</Foo>
9192
<Bar>{Promise.resolve([dedupedChild])}</Bar>
93+
<Navigate />
9294
</Container>
9395
</body>
9496
</html>

fixtures/flight/src/Navigate.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
'use client';
2+
3+
import * as React from 'react';
4+
import Container from './Container.js';
5+
6+
export function Navigate() {
7+
/** Repro for https://issues.chromium.org/u/1/issues/419746417 */
8+
function provokeChromeCrash() {
9+
React.startTransition(async () => {
10+
console.log('Default transition triggered');
11+
12+
await new Promise(resolve => {
13+
setTimeout(
14+
() => {
15+
history.pushState(
16+
{},
17+
'',
18+
`?chrome-crash-419746417=${performance.now()}`
19+
);
20+
},
21+
// This needs to happen before React's default transition indicator
22+
// is displayed but after it's scheduled.
23+
100 + -50
24+
);
25+
26+
setTimeout(() => {
27+
console.log('Default transition completed');
28+
resolve();
29+
}, 1000);
30+
});
31+
});
32+
}
33+
34+
return (
35+
<Container>
36+
<h2>Navigation fixture</h2>
37+
<button onClick={provokeChromeCrash}>Provoke Chrome Crash (fixed)</button>
38+
</Container>
39+
);
40+
}

packages/react-dom/src/client/ReactDOMDefaultTransitionIndicator.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ export function defaultOnDefaultTransitionIndicator(): void | (() => void) {
3838
if (!isCancelled) {
3939
// Some other navigation completed but we should still be running.
4040
// Start another fake one to keep the loading indicator going.
41-
startFakeNavigation();
41+
// There needs to be an async gap to work around https://issues.chromium.org/u/1/issues/419746417.
42+
setTimeout(startFakeNavigation, 20);
4243
}
4344
}
4445

@@ -70,7 +71,7 @@ export function defaultOnDefaultTransitionIndicator(): void | (() => void) {
7071
}
7172
}
7273

73-
// Delay the start a bit in case this is a fast navigation.
74+
// Delay the start a bit in case this is a fast Transition.
7475
setTimeout(startFakeNavigation, 100);
7576

7677
return function () {

0 commit comments

Comments
 (0)