Skip to content

Commit 766af59

Browse files
authored
Move Scope API ref resolution to mutation phase (facebook#19264)
* Move Scope API ref resolution to mutation phase
1 parent c7805b8 commit 766af59

File tree

2 files changed

+38
-4
lines changed

2 files changed

+38
-4
lines changed

packages/react-reconciler/src/ReactFiberWorkLoop.new.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import {
2727
warnAboutUnmockedScheduler,
2828
deferRenderPhaseUpdateToNextBatch,
2929
decoupleUpdatePriorityFromScheduler,
30+
enableScopeAPI,
3031
} from 'shared/ReactFeatureFlags';
3132
import ReactSharedInternals from 'shared/ReactSharedInternals';
3233
import invariant from 'shared/invariant';
@@ -88,6 +89,7 @@ import {
8889
Block,
8990
OffscreenComponent,
9091
LegacyHiddenComponent,
92+
ScopeComponent,
9193
} from './ReactWorkTags';
9294
import {LegacyRoot} from './ReactRootTags';
9395
import {
@@ -2217,6 +2219,13 @@ function commitMutationEffects(root: FiberRoot, renderPriorityLevel) {
22172219
if (current !== null) {
22182220
commitDetachRef(current);
22192221
}
2222+
if (enableScopeAPI) {
2223+
// TODO: This is a temporary solution that allows us to transition away
2224+
// from React Flare on www.
2225+
if (nextEffect.tag === ScopeComponent) {
2226+
commitAttachRef(nextEffect);
2227+
}
2228+
}
22202229
}
22212230

22222231
// The following switch statement is only concerned about placement,
@@ -2287,8 +2296,16 @@ function commitLayoutEffects(root: FiberRoot, committedLanes: Lanes) {
22872296
commitLayoutEffectOnFiber(root, current, nextEffect, committedLanes);
22882297
}
22892298

2290-
if (effectTag & Ref) {
2291-
commitAttachRef(nextEffect);
2299+
if (enableScopeAPI) {
2300+
// TODO: This is a temporary solution that allows us to transition away
2301+
// from React Flare on www.
2302+
if (effectTag & Ref && nextEffect.tag !== ScopeComponent) {
2303+
commitAttachRef(nextEffect);
2304+
}
2305+
} else {
2306+
if (effectTag & Ref) {
2307+
commitAttachRef(nextEffect);
2308+
}
22922309
}
22932310

22942311
resetCurrentDebugFiberInDEV();

packages/react-reconciler/src/ReactFiberWorkLoop.old.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import {
2929
decoupleUpdatePriorityFromScheduler,
3030
enableDebugTracing,
3131
enableSchedulingProfiler,
32+
enableScopeAPI,
3233
} from 'shared/ReactFeatureFlags';
3334
import ReactSharedInternals from 'shared/ReactSharedInternals';
3435
import invariant from 'shared/invariant';
@@ -111,6 +112,7 @@ import {
111112
Block,
112113
OffscreenComponent,
113114
LegacyHiddenComponent,
115+
ScopeComponent,
114116
} from './ReactWorkTags';
115117
import {LegacyRoot} from './ReactRootTags';
116118
import {
@@ -2324,6 +2326,13 @@ function commitMutationEffects(root: FiberRoot, renderPriorityLevel) {
23242326
if (current !== null) {
23252327
commitDetachRef(current);
23262328
}
2329+
if (enableScopeAPI) {
2330+
// TODO: This is a temporary solution that allows us to transition away
2331+
// from React Flare on www.
2332+
if (nextEffect.tag === ScopeComponent) {
2333+
commitAttachRef(nextEffect);
2334+
}
2335+
}
23272336
}
23282337

23292338
// The following switch statement is only concerned about placement,
@@ -2404,8 +2413,16 @@ function commitLayoutEffects(root: FiberRoot, committedLanes: Lanes) {
24042413
commitLayoutEffectOnFiber(root, current, nextEffect, committedLanes);
24052414
}
24062415

2407-
if (effectTag & Ref) {
2408-
commitAttachRef(nextEffect);
2416+
if (enableScopeAPI) {
2417+
// TODO: This is a temporary solution that allows us to transition away
2418+
// from React Flare on www.
2419+
if (effectTag & Ref && nextEffect.tag !== ScopeComponent) {
2420+
commitAttachRef(nextEffect);
2421+
}
2422+
} else {
2423+
if (effectTag & Ref) {
2424+
commitAttachRef(nextEffect);
2425+
}
24092426
}
24102427

24112428
resetCurrentDebugFiberInDEV();

0 commit comments

Comments
 (0)