Skip to content
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

Support hidden deprioritization in Batched Mode #15533

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions packages/react-reconciler/src/ReactFiberBeginWork.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,7 @@ import {
Never,
computeAsyncExpiration,
} from './ReactFiberExpirationTime';
import {
ConcurrentMode,
NoMode,
ProfileMode,
StrictMode,
BatchedMode,
} from './ReactTypeOfMode';
import {NoMode, ProfileMode, StrictMode, BatchedMode} from './ReactTypeOfMode';
import {
shouldSetTextContent,
shouldDeprioritizeSubtree,
Expand Down Expand Up @@ -980,7 +974,7 @@ function updateHostComponent(current, workInProgress, renderExpirationTime) {

// Check the host config to see if the children are offscreen/hidden.
if (
workInProgress.mode & ConcurrentMode &&
workInProgress.mode & BatchedMode &&
renderExpirationTime !== Never &&
shouldDeprioritizeSubtree(type, nextProps)
) {
Expand Down Expand Up @@ -2257,7 +2251,7 @@ function beginWork(
case HostComponent:
pushHostContext(workInProgress);
if (
workInProgress.mode & ConcurrentMode &&
workInProgress.mode & BatchedMode &&
renderExpirationTime !== Never &&
shouldDeprioritizeSubtree(workInProgress.type, newProps)
) {
Expand Down
5 changes: 5 additions & 0 deletions packages/react-reconciler/src/ReactFiberScheduler.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ import {
BatchedMode,
ConcurrentMode,
} from './ReactTypeOfMode';
import {ConcurrentRoot} from 'shared/ReactRootTags';
import {
HostRoot,
ClassComponent,
Expand Down Expand Up @@ -776,6 +777,10 @@ function renderRoot(
'Should not already be working.',
);

if (root.tag !== ConcurrentRoot) {
isSync = true;
}

if (enableUserTimingAPI && expirationTime !== Sync) {
const didExpire = isSync;
stopRequestCallbackTimer(didExpire);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,46 @@ describe('ReactBatchedMode', () => {
expect(Scheduler).toFlushExpired(['A1']);
expect(root).toMatchRenderedOutput('A1B1');
});

it('hidden subtrees are deprioritized but not yieldy', () => {
const {useEffect} = React;

const root = ReactNoop.createSyncRoot();
function App() {
useEffect(() => Scheduler.yieldValue('Commit'));
return (
<Suspense fallback={<Text text="Loading..." />}>
<div hidden={true}>
<Text text="A" />
<Text text="B" />
<Text text="C" />
</div>
<div>
<Text text="D" />
<Text text="E" />
<Text text="F" />
</div>
</Suspense>
);
}

root.render(<App />);
expect(Scheduler).toFlushAndYieldThrough(['D', 'E', 'F', 'Commit']);
expect(root).toMatchRenderedOutput(
<React.Fragment>
<div hidden={true} />
<div>DEF</div>
</React.Fragment>,
);

Scheduler.unstable_flushNumberOfYields(1);
expect(Scheduler).toHaveYielded(['A', 'B', 'C']);
Scheduler.flushAll();
expect(root).toMatchRenderedOutput(
<React.Fragment>
<div hidden={true}>ABC</div>
<div>DEF</div>
</React.Fragment>,
);
});
});