Skip to content

Commit f567431

Browse files
committed
Revert "Synchronously flush the transition lane scheduled in a popstate event (facebook#26025)"
This reverts commit d121c67.
1 parent 0fe1bfa commit f567431

File tree

11 files changed

+9
-196
lines changed

11 files changed

+9
-196
lines changed

packages/react-art/src/ReactFiberConfigART.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -346,10 +346,6 @@ export function getCurrentEventPriority() {
346346
return DefaultEventPriority;
347347
}
348348

349-
export function shouldAttemptEagerTransition() {
350-
return false;
351-
}
352-
353349
// The ART renderer is secondary to the React DOM renderer.
354350
export const isPrimaryRenderer = false;
355351

packages/react-dom-bindings/src/client/ReactFiberConfigDOM.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -527,10 +527,6 @@ export function getCurrentEventPriority(): EventPriority {
527527
return getEventPriority(currentEvent.type);
528528
}
529529

530-
export function shouldAttemptEagerTransition(): boolean {
531-
return window.event && window.event.type === 'popstate';
532-
}
533-
534530
export const isPrimaryRenderer = true;
535531
export const warnsIfNotActing = true;
536532
// This initialization code may run even on server environments

packages/react-dom/src/__tests__/ReactDOMFiberAsync-test.js

Lines changed: 1 addition & 136 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ describe('ReactDOMFiberAsync', () => {
2727
let container;
2828

2929
beforeEach(() => {
30+
jest.resetModules();
3031
container = document.createElement('div');
3132
React = require('react');
3233
ReactDOM = require('react-dom');
@@ -39,7 +40,6 @@ describe('ReactDOMFiberAsync', () => {
3940
assertLog = InternalTestUtils.assertLog;
4041

4142
document.body.appendChild(container);
42-
window.event = undefined;
4343
});
4444

4545
afterEach(() => {
@@ -566,139 +566,4 @@ describe('ReactDOMFiberAsync', () => {
566566

567567
expect(container.textContent).toBe('new');
568568
});
569-
570-
it('should synchronously render the transition lane scheduled in a popState', async () => {
571-
function App() {
572-
const [syncState, setSyncState] = React.useState(false);
573-
const [hasNavigated, setHasNavigated] = React.useState(false);
574-
function onPopstate() {
575-
Scheduler.log(`popState`);
576-
React.startTransition(() => {
577-
setHasNavigated(true);
578-
});
579-
setSyncState(true);
580-
}
581-
React.useEffect(() => {
582-
window.addEventListener('popstate', onPopstate);
583-
return () => {
584-
window.removeEventListener('popstate', onPopstate);
585-
};
586-
}, []);
587-
Scheduler.log(`render:${hasNavigated}/${syncState}`);
588-
return null;
589-
}
590-
const root = ReactDOMClient.createRoot(container);
591-
await act(async () => {
592-
root.render(<App />);
593-
});
594-
assertLog(['render:false/false']);
595-
596-
await act(async () => {
597-
const popStateEvent = new Event('popstate');
598-
// Jest is not emulating window.event correctly in the microtask
599-
window.event = popStateEvent;
600-
window.dispatchEvent(popStateEvent);
601-
queueMicrotask(() => {
602-
window.event = undefined;
603-
});
604-
});
605-
606-
assertLog(['popState', 'render:true/true']);
607-
await act(() => {
608-
root.unmount();
609-
});
610-
});
611-
612-
it('Should not flush transition lanes if there is no transition scheduled in popState', async () => {
613-
let setHasNavigated;
614-
function App() {
615-
const [syncState, setSyncState] = React.useState(false);
616-
const [hasNavigated, _setHasNavigated] = React.useState(false);
617-
setHasNavigated = _setHasNavigated;
618-
function onPopstate() {
619-
setSyncState(true);
620-
}
621-
622-
React.useEffect(() => {
623-
window.addEventListener('popstate', onPopstate);
624-
return () => {
625-
window.removeEventListener('popstate', onPopstate);
626-
};
627-
}, []);
628-
629-
Scheduler.log(`render:${hasNavigated}/${syncState}`);
630-
return null;
631-
}
632-
const root = ReactDOMClient.createRoot(container);
633-
await act(async () => {
634-
root.render(<App />);
635-
});
636-
assertLog(['render:false/false']);
637-
638-
React.startTransition(() => {
639-
setHasNavigated(true);
640-
});
641-
await act(async () => {
642-
const popStateEvent = new Event('popstate');
643-
// Jest is not emulating window.event correctly in the microtask
644-
window.event = popStateEvent;
645-
window.dispatchEvent(popStateEvent);
646-
queueMicrotask(() => {
647-
window.event = undefined;
648-
});
649-
});
650-
assertLog(['render:false/true', 'render:true/true']);
651-
await act(() => {
652-
root.unmount();
653-
});
654-
});
655-
656-
it('transition lane in popState should yield if it suspends', async () => {
657-
const never = {then() {}};
658-
let _setText;
659-
660-
function App() {
661-
const [shouldSuspend, setShouldSuspend] = React.useState(false);
662-
const [text, setText] = React.useState('0');
663-
_setText = setText;
664-
if (shouldSuspend) {
665-
Scheduler.log('Suspend!');
666-
throw never;
667-
}
668-
function onPopstate() {
669-
React.startTransition(() => {
670-
setShouldSuspend(val => !val);
671-
});
672-
}
673-
React.useEffect(() => {
674-
window.addEventListener('popstate', onPopstate);
675-
return () => window.removeEventListener('popstate', onPopstate);
676-
}, []);
677-
Scheduler.log(`Child:${shouldSuspend}/${text}`);
678-
return text;
679-
}
680-
681-
const root = ReactDOMClient.createRoot(container);
682-
await act(async () => {
683-
root.render(<App />);
684-
});
685-
assertLog(['Child:false/0']);
686-
687-
await act(() => {
688-
const popStateEvent = new Event('popstate');
689-
window.event = popStateEvent;
690-
window.dispatchEvent(popStateEvent);
691-
queueMicrotask(() => {
692-
window.event = undefined;
693-
});
694-
});
695-
assertLog(['Suspend!']);
696-
697-
await act(async () => {
698-
_setText('1');
699-
});
700-
assertLog(['Child:false/1', 'Suspend!']);
701-
702-
root.unmount();
703-
});
704569
});

packages/react-native-renderer/src/ReactFiberConfigFabric.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -334,10 +334,6 @@ export function getCurrentEventPriority(): * {
334334
return DefaultEventPriority;
335335
}
336336

337-
export function shouldAttemptEagerTransition(): boolean {
338-
return false;
339-
}
340-
341337
// The Fabric renderer is secondary to the existing React Native renderer.
342338
export const isPrimaryRenderer = false;
343339

packages/react-native-renderer/src/ReactFiberConfigNative.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -265,10 +265,6 @@ export function getCurrentEventPriority(): * {
265265
return DefaultEventPriority;
266266
}
267267

268-
export function shouldAttemptEagerTransition(): boolean {
269-
return false;
270-
}
271-
272268
// -------------------
273269
// Mutation
274270
// -------------------

packages/react-noop-renderer/src/createReactNoop.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -526,10 +526,6 @@ function createReactNoop(reconciler: Function, useMutation: boolean) {
526526
return currentEventPriority;
527527
},
528528

529-
shouldAttemptEagerTransition(): boolean {
530-
return false;
531-
},
532-
533529
now: Scheduler.unstable_now,
534530

535531
isPrimaryRenderer: true,

packages/react-reconciler/src/ReactFiberRootScheduler.js

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ import {
2020
getNextLanes,
2121
includesSyncLane,
2222
markStarvedLanesAsExpired,
23-
markRootEntangled,
24-
mergeLanes,
2523
} from './ReactFiberLane';
2624
import {
2725
CommitContext,
@@ -51,11 +49,7 @@ import {
5149
IdleEventPriority,
5250
lanesToEventPriority,
5351
} from './ReactEventPriorities';
54-
import {
55-
supportsMicrotasks,
56-
scheduleMicrotask,
57-
shouldAttemptEagerTransition,
58-
} from './ReactFiberConfig';
52+
import {supportsMicrotasks, scheduleMicrotask} from './ReactFiberConfig';
5953

6054
import ReactSharedInternals from 'shared/ReactSharedInternals';
6155
const {ReactCurrentActQueue} = ReactSharedInternals;
@@ -78,8 +72,6 @@ let mightHavePendingSyncWork: boolean = false;
7872

7973
let isFlushingWork: boolean = false;
8074

81-
let currentEventTransitionLane: Lane = NoLanes;
82-
8375
export function ensureRootIsScheduled(root: FiberRoot): void {
8476
// This function is called whenever a root receives an update. It does two
8577
// things 1) it ensures the root is in the root schedule, and 2) it ensures
@@ -246,14 +238,6 @@ function processRootScheduleInMicrotask() {
246238
let root = firstScheduledRoot;
247239
while (root !== null) {
248240
const next = root.next;
249-
250-
if (
251-
currentEventTransitionLane !== NoLane &&
252-
shouldAttemptEagerTransition()
253-
) {
254-
markRootEntangled(root, mergeLanes(currentEventTransitionLane, SyncLane));
255-
}
256-
257241
const nextLanes = scheduleTaskForRootDuringMicrotask(root, currentTime);
258242
if (nextLanes === NoLane) {
259243
// This root has no more pending work. Remove it from the schedule. To
@@ -283,8 +267,6 @@ function processRootScheduleInMicrotask() {
283267
root = next;
284268
}
285269

286-
currentEventTransitionLane = NoLane;
287-
288270
// At the end of the microtask, flush any pending synchronous work. This has
289271
// to come at the end, because it does actual rendering work that might throw.
290272
flushSyncWorkOnAllRoots();
@@ -490,11 +472,3 @@ function scheduleImmediateTask(cb: () => mixed) {
490472
Scheduler_scheduleCallback(ImmediateSchedulerPriority, cb);
491473
}
492474
}
493-
494-
export function getCurrentEventTransitionLane(): Lane {
495-
return currentEventTransitionLane;
496-
}
497-
498-
export function setCurrentEventTransitionLane(lane: Lane): void {
499-
currentEventTransitionLane = lane;
500-
}

packages/react-reconciler/src/ReactFiberWorkLoop.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -278,8 +278,6 @@ import {
278278
flushSyncWorkOnAllRoots,
279279
flushSyncWorkOnLegacyRootsOnly,
280280
getContinuationForRoot,
281-
getCurrentEventTransitionLane,
282-
setCurrentEventTransitionLane,
283281
} from './ReactFiberRootScheduler';
284282
import {getMaskedContext, getUnmaskedContext} from './ReactFiberContext';
285283

@@ -584,6 +582,8 @@ const NESTED_PASSIVE_UPDATE_LIMIT = 50;
584582
let nestedPassiveUpdateCount: number = 0;
585583
let rootWithPassiveNestedUpdates: FiberRoot | null = null;
586584

585+
let currentEventTransitionLane: Lanes = NoLanes;
586+
587587
let isRunningInsertionEffect = false;
588588

589589
export function getWorkInProgressRoot(): FiberRoot | null {
@@ -640,11 +640,11 @@ export function requestUpdateLane(fiber: Fiber): Lane {
640640
// The trick we use is to cache the first of each of these inputs within an
641641
// event. Then reset the cached values once we can be sure the event is
642642
// over. Our heuristic for that is whenever we enter a concurrent work loop.
643-
if (getCurrentEventTransitionLane() === NoLane) {
643+
if (currentEventTransitionLane === NoLane) {
644644
// All transitions within the same event are assigned the same lane.
645-
setCurrentEventTransitionLane(claimNextTransitionLane());
645+
currentEventTransitionLane = claimNextTransitionLane();
646646
}
647-
return getCurrentEventTransitionLane();
647+
return currentEventTransitionLane;
648648
}
649649

650650
// Updates originating inside certain React methods, like flushSync, have
@@ -848,6 +848,8 @@ export function performConcurrentWorkOnRoot(
848848
resetNestedUpdateFlag();
849849
}
850850

851+
currentEventTransitionLane = NoLanes;
852+
851853
if ((executionContext & (RenderContext | CommitContext)) !== NoContext) {
852854
throw new Error('Should not already be working.');
853855
}

packages/react-reconciler/src/__tests__/ReactFiberHostContext-test.internal.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,6 @@ describe('ReactFiberHostContext', () => {
7070
getCurrentEventPriority: function () {
7171
return DefaultEventPriority;
7272
},
73-
shouldAttemptEagerTransition() {
74-
return false;
75-
},
7673
requestPostPaintCallback: function () {},
7774
maySuspendCommit(type, props) {
7875
return false;

packages/react-reconciler/src/forks/ReactFiberConfig.custom.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,6 @@ export const preparePortalMount = $$$config.preparePortalMount;
6666
export const prepareScopeUpdate = $$$config.prepareScopeUpdate;
6767
export const getInstanceFromScope = $$$config.getInstanceFromScope;
6868
export const getCurrentEventPriority = $$$config.getCurrentEventPriority;
69-
export const shouldAttemptEagerTransition =
70-
$$$config.shouldAttemptEagerTransition;
7169
export const detachDeletedInstance = $$$config.detachDeletedInstance;
7270
export const requestPostPaintCallback = $$$config.requestPostPaintCallback;
7371
export const maySuspendCommit = $$$config.maySuspendCommit;

0 commit comments

Comments
 (0)