Skip to content

Commit b045f18

Browse files
committed
[refactor] Add element type for Activity
1 parent 2980f27 commit b045f18

File tree

11 files changed

+84
-3
lines changed

11 files changed

+84
-3
lines changed

packages/react-devtools-shared/src/backend/fiber/renderer.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ import type {
146146
import type {Source} from 'react-devtools-shared/src/shared/types';
147147
import {getSourceLocationByFiber} from './DevToolsFiberComponentStack';
148148
import {formatOwnerStack} from '../shared/DevToolsOwnerStack';
149+
import {ActivityComponent} from 'react-reconciler/src/ReactWorkTags';
149150

150151
// Kinds
151152
const FIBER_INSTANCE = 0;
@@ -385,6 +386,7 @@ export function getInternalReactConstants(version: string): {
385386
YieldComponent: -1, // Removed
386387
Throw: 29,
387388
ViewTransitionComponent: 30, // Experimental
389+
ActivityComponent: 31,
388390
};
389391
} else if (gte(version, '17.0.0-alpha')) {
390392
ReactTypeOfWork = {
@@ -421,6 +423,7 @@ export function getInternalReactConstants(version: string): {
421423
YieldComponent: -1, // Removed
422424
Throw: -1, // Doesn't exist yet
423425
ViewTransitionComponent: -1, // Doesn't exist yet
426+
ActivityComponent: -1, // Doesn't exist yet
424427
};
425428
} else if (gte(version, '16.6.0-beta.0')) {
426429
ReactTypeOfWork = {
@@ -457,6 +460,7 @@ export function getInternalReactConstants(version: string): {
457460
YieldComponent: -1, // Removed
458461
Throw: -1, // Doesn't exist yet
459462
ViewTransitionComponent: -1, // Doesn't exist yet
463+
ActivityComponent: -1, // Doesn't exist yet
460464
};
461465
} else if (gte(version, '16.4.3-alpha')) {
462466
ReactTypeOfWork = {
@@ -493,6 +497,7 @@ export function getInternalReactConstants(version: string): {
493497
YieldComponent: -1, // Removed
494498
Throw: -1, // Doesn't exist yet
495499
ViewTransitionComponent: -1, // Doesn't exist yet
500+
ActivityComponent: -1, // Doesn't exist yet
496501
};
497502
} else {
498503
ReactTypeOfWork = {
@@ -529,6 +534,7 @@ export function getInternalReactConstants(version: string): {
529534
YieldComponent: 9,
530535
Throw: -1, // Doesn't exist yet
531536
ViewTransitionComponent: -1, // Doesn't exist yet
537+
ActivityComponent: -1, // Doesn't exist yet
532538
};
533539
}
534540
// **********************************************************
@@ -622,6 +628,8 @@ export function getInternalReactConstants(version: string): {
622628
}
623629

624630
switch (tag) {
631+
case ActivityComponent:
632+
return 'Activity';
625633
case CacheComponent:
626634
return 'Cache';
627635
case ClassComponent:
@@ -1480,6 +1488,7 @@ export function attach(
14801488
return true;
14811489
case HostPortal:
14821490
case HostText:
1491+
case ActivityComponent:
14831492
case LegacyHiddenComponent:
14841493
case OffscreenComponent:
14851494
case Throw:

packages/react-devtools-shared/src/backend/types.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ export type WorkTagMap = {
7777
YieldComponent: WorkTag,
7878
Throw: WorkTag,
7979
ViewTransitionComponent: WorkTag,
80+
ActivityComponent: WorkTag,
8081
};
8182

8283
export type HostInstance = Object;

packages/react-reconciler/src/ReactFiber.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ import {
7272
TracingMarkerComponent,
7373
Throw,
7474
ViewTransitionComponent,
75+
ActivityComponent,
7576
} from './ReactWorkTags';
7677
import {OffscreenVisible} from './ReactFiberActivityComponent';
7778
import {getComponentNameFromOwner} from 'react-reconciler/src/getComponentNameFromFiber';
@@ -108,6 +109,7 @@ import {
108109
REACT_TRACING_MARKER_TYPE,
109110
REACT_ELEMENT_TYPE,
110111
REACT_VIEW_TRANSITION_TYPE,
112+
REACT_ACTIVITY_TYPE,
111113
} from 'shared/ReactSymbols';
112114
import {TransitionTracingMarker} from './ReactFiberTracingMarkerComponent';
113115
import {
@@ -595,6 +597,8 @@ export function createFiberFromTypeAndProps(
595597
}
596598
} else {
597599
getTag: switch (type) {
600+
case REACT_ACTIVITY_TYPE:
601+
return createFiberFromActivity(pendingProps, mode, lanes, key);
598602
case REACT_FRAGMENT_TYPE:
599603
return createFiberFromFragment(pendingProps.children, mode, lanes, key);
600604
case REACT_STRICT_MODE_TYPE:
@@ -874,6 +878,17 @@ export function createFiberFromOffscreen(
874878
fiber.stateNode = primaryChildInstance;
875879
return fiber;
876880
}
881+
export function createFiberFromActivity(
882+
pendingProps: OffscreenProps,
883+
mode: TypeOfMode,
884+
lanes: Lanes,
885+
key: null | string,
886+
): Fiber {
887+
const fiber = createFiber(ActivityComponent, pendingProps, key, mode);
888+
fiber.elementType = REACT_ACTIVITY_TYPE;
889+
fiber.lanes = lanes;
890+
return fiber;
891+
}
877892

878893
export function createFiberFromViewTransition(
879894
pendingProps: ViewTransitionProps,

packages/react-reconciler/src/ReactFiberBeginWork.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ import {
7777
TracingMarkerComponent,
7878
Throw,
7979
ViewTransitionComponent,
80+
ActivityComponent,
8081
} from './ReactWorkTags';
8182
import {
8283
NoFlags,
@@ -867,6 +868,46 @@ function deferHiddenOffscreenComponent(
867868
// fork the function.
868869
const updateLegacyHiddenComponent = updateOffscreenComponent;
869870

871+
function updateActivityComponent(
872+
current: null | Fiber,
873+
workInProgress: Fiber,
874+
renderLanes: Lanes,
875+
) {
876+
const nextProps = workInProgress.pendingProps;
877+
const nextChildren = nextProps.children;
878+
const nextMode = nextProps.mode;
879+
const mode = workInProgress.mode;
880+
const offscreenChildProps: OffscreenProps = {
881+
mode: nextMode,
882+
children: nextChildren,
883+
};
884+
885+
if (current === null) {
886+
const primaryChildFragment = mountWorkInProgressOffscreenFiber(
887+
offscreenChildProps,
888+
mode,
889+
renderLanes,
890+
);
891+
primaryChildFragment.ref = workInProgress.ref;
892+
workInProgress.child = primaryChildFragment;
893+
primaryChildFragment.return = workInProgress;
894+
895+
return primaryChildFragment;
896+
} else {
897+
const currentChild: Fiber = (current.child: any);
898+
899+
const primaryChildFragment = updateWorkInProgressOffscreenFiber(
900+
currentChild,
901+
offscreenChildProps,
902+
);
903+
904+
primaryChildFragment.ref = workInProgress.ref;
905+
workInProgress.child = primaryChildFragment;
906+
primaryChildFragment.return = workInProgress;
907+
return primaryChildFragment;
908+
}
909+
}
910+
870911
function updateCacheComponent(
871912
current: Fiber | null,
872913
workInProgress: Fiber,
@@ -4024,6 +4065,9 @@ function beginWork(
40244065
}
40254066
break;
40264067
}
4068+
case ActivityComponent: {
4069+
return updateActivityComponent(current, workInProgress, renderLanes);
4070+
}
40274071
case OffscreenComponent: {
40284072
return updateOffscreenComponent(current, workInProgress, renderLanes);
40294073
}

packages/react-reconciler/src/ReactFiberCompleteWork.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ import {
7676
TracingMarkerComponent,
7777
Throw,
7878
ViewTransitionComponent,
79+
ActivityComponent,
7980
} from './ReactWorkTags';
8081
import {NoMode, ConcurrentMode, ProfileMode} from './ReactTypeOfMode';
8182
import {
@@ -959,6 +960,7 @@ function completeWork(
959960
}
960961
// Fallthrough
961962
}
963+
case ActivityComponent:
962964
case LazyComponent:
963965
case SimpleMemoComponent:
964966
case FunctionComponent:

packages/react-reconciler/src/ReactWorkTags.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ export type WorkTag =
3838
| 27
3939
| 28
4040
| 29
41-
| 30;
41+
| 30
42+
| 31;
4243

4344
export const FunctionComponent = 0;
4445
export const ClassComponent = 1;
@@ -69,3 +70,4 @@ export const HostSingleton = 27;
6970
export const IncompleteFunctionComponent = 28;
7071
export const Throw = 29;
7172
export const ViewTransitionComponent = 30;
73+
export const ActivityComponent = 31;

packages/react-reconciler/src/getComponentNameFromFiber.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import {
4747
TracingMarkerComponent,
4848
Throw,
4949
ViewTransitionComponent,
50+
ActivityComponent,
5051
} from 'react-reconciler/src/ReactWorkTags';
5152
import getComponentNameFromType from 'shared/getComponentNameFromType';
5253
import {REACT_STRICT_MODE_TYPE} from 'shared/ReactSymbols';
@@ -85,6 +86,8 @@ export function getComponentNameFromOwner(
8586
export default function getComponentNameFromFiber(fiber: Fiber): string | null {
8687
const {tag, type} = fiber;
8788
switch (tag) {
89+
case ActivityComponent:
90+
return 'Activity';
8891
case CacheComponent:
8992
return 'Cache';
9093
case ContextConsumer:

packages/react-server/src/ReactFizzServer.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ import {
154154
REACT_OFFSCREEN_TYPE,
155155
REACT_POSTPONE_TYPE,
156156
REACT_VIEW_TRANSITION_TYPE,
157+
REACT_ACTIVITY_TYPE,
157158
} from 'shared/ReactSymbols';
158159
import ReactSharedInternals from 'shared/ReactSharedInternals';
159160
import {
@@ -2261,6 +2262,7 @@ function renderElement(
22612262
task.keyPath = prevKeyPath;
22622263
return;
22632264
}
2265+
case REACT_ACTIVITY_TYPE:
22642266
case REACT_OFFSCREEN_TYPE: {
22652267
renderOffscreen(request, task, keyPath, props);
22662268
return;

packages/react/src/ReactClient.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
REACT_SUSPENSE_TYPE,
1616
REACT_SUSPENSE_LIST_TYPE,
1717
REACT_LEGACY_HIDDEN_TYPE,
18-
REACT_OFFSCREEN_TYPE,
18+
REACT_ACTIVITY_TYPE,
1919
REACT_SCOPE_TYPE,
2020
REACT_TRACING_MARKER_TYPE,
2121
REACT_VIEW_TRANSITION_TYPE,
@@ -116,7 +116,7 @@ export {
116116
useDeferredValue,
117117
REACT_SUSPENSE_LIST_TYPE as unstable_SuspenseList,
118118
REACT_LEGACY_HIDDEN_TYPE as unstable_LegacyHidden,
119-
REACT_OFFSCREEN_TYPE as unstable_Activity,
119+
REACT_ACTIVITY_TYPE as unstable_Activity,
120120
getCacheForType as unstable_getCacheForType,
121121
useCacheRefresh as unstable_useCacheRefresh,
122122
use,

packages/shared/ReactSymbols.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export const REACT_MEMO_TYPE: symbol = Symbol.for('react.memo');
3434
export const REACT_LAZY_TYPE: symbol = Symbol.for('react.lazy');
3535
export const REACT_SCOPE_TYPE: symbol = Symbol.for('react.scope');
3636
export const REACT_OFFSCREEN_TYPE: symbol = Symbol.for('react.offscreen');
37+
export const REACT_ACTIVITY_TYPE: symbol = Symbol.for('react.activity');
3738
export const REACT_LEGACY_HIDDEN_TYPE: symbol = Symbol.for(
3839
'react.legacy_hidden',
3940
);

packages/shared/isValidElementType.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
REACT_OFFSCREEN_TYPE,
2525
REACT_TRACING_MARKER_TYPE,
2626
REACT_VIEW_TRANSITION_TYPE,
27+
REACT_ACTIVITY_TYPE,
2728
} from 'shared/ReactSymbols';
2829
import {
2930
enableScopeAPI,
@@ -50,6 +51,7 @@ export default function isValidElementType(type: mixed): boolean {
5051
type === REACT_SUSPENSE_TYPE ||
5152
type === REACT_SUSPENSE_LIST_TYPE ||
5253
(enableLegacyHidden && type === REACT_LEGACY_HIDDEN_TYPE) ||
54+
type === REACT_ACTIVITY_TYPE ||
5355
type === REACT_OFFSCREEN_TYPE ||
5456
(enableScopeAPI && type === REACT_SCOPE_TYPE) ||
5557
(enableTransitionTracing && type === REACT_TRACING_MARKER_TYPE) ||

0 commit comments

Comments
 (0)