Skip to content

Commit

Permalink
Add Offscreen component type
Browse files Browse the repository at this point in the history
Doesn't do anything special in this initial commit. Just acts like a
fragment.
  • Loading branch information
lunaruan authored and acdlite committed Apr 25, 2020
1 parent 1df756b commit ed01fda
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 1 deletion.
27 changes: 27 additions & 0 deletions packages/react-reconciler/src/ReactFiber.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import {
FundamentalComponent,
ScopeComponent,
Block,
OffscreenComponent,
} from './ReactWorkTags';
import getComponentName from 'shared/getComponentName';

Expand Down Expand Up @@ -87,6 +88,7 @@ import {
REACT_FUNDAMENTAL_TYPE,
REACT_SCOPE_TYPE,
REACT_BLOCK_TYPE,
REACT_OFFSCREEN_TYPE,
} from 'shared/ReactSymbols';

export type {Fiber};
Expand Down Expand Up @@ -511,6 +513,13 @@ export function createFiberFromTypeAndProps(
expirationTime,
key,
);
case REACT_OFFSCREEN_TYPE:
return createFiberFromOffscreen(
pendingProps,
mode,
expirationTime,
key,
);
default: {
if (typeof type === 'object' && type !== null) {
switch (type.$$typeof) {
Expand Down Expand Up @@ -728,6 +737,24 @@ export function createFiberFromSuspenseList(
return fiber;
}

export function createFiberFromOffscreen(
pendingProps: any,
mode: TypeOfMode,
expirationTime: ExpirationTimeOpaque,
key: null | string,
) {
const fiber = createFiber(OffscreenComponent, pendingProps, key, mode);
// TODO: The OffscreenComponent fiber shouldn't have a type. It has a tag.
// This needs to be fixed in getComponentName so that it relies on the tag
// instead.
if (__DEV__) {
fiber.type = REACT_OFFSCREEN_TYPE;
}
fiber.elementType = REACT_OFFSCREEN_TYPE;
fiber.expirationTime_opaque = expirationTime;
return fiber;
}

export function createFiberFromText(
content: string,
mode: TypeOfMode,
Expand Down
23 changes: 23 additions & 0 deletions packages/react-reconciler/src/ReactFiberBeginWork.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import {
FundamentalComponent,
ScopeComponent,
Block,
OffscreenComponent,
} from './ReactWorkTags';
import {
NoEffect,
Expand Down Expand Up @@ -555,6 +556,21 @@ function updateSimpleMemoComponent(
);
}

function updateOffscreenComponent(
current: Fiber | null,
workInProgress: Fiber,
renderExpirationTime: ExpirationTimeOpaque,
) {
const nextChildren = workInProgress.pendingProps;
reconcileChildren(
current,
workInProgress,
nextChildren,
renderExpirationTime,
);
return workInProgress.child;
}

function updateFragment(
current: Fiber | null,
workInProgress: Fiber,
Expand Down Expand Up @@ -3448,6 +3464,13 @@ function beginWork(
renderExpirationTime,
);
}
case OffscreenComponent: {
return updateOffscreenComponent(
current,
workInProgress,
renderExpirationTime,
);
}
case SimpleMemoComponent: {
return updateSimpleMemoComponent(
current,
Expand Down
3 changes: 3 additions & 0 deletions packages/react-reconciler/src/ReactFiberCompleteWork.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import {
FundamentalComponent,
ScopeComponent,
Block,
OffscreenComponent,
} from './ReactWorkTags';
import {NoMode, BlockingMode} from './ReactTypeOfMode';
import {Ref, Update, NoEffect, DidCapture} from './ReactSideEffectTags';
Expand Down Expand Up @@ -1287,6 +1288,8 @@ function completeWork(
return null;
}
break;
case OffscreenComponent:
return null;
}
invariant(
false,
Expand Down
4 changes: 3 additions & 1 deletion packages/react-reconciler/src/ReactWorkTags.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ export type WorkTag =
| 19
| 20
| 21
| 22;
| 22
| 23;

export const FunctionComponent = 0;
export const ClassComponent = 1;
Expand All @@ -55,3 +56,4 @@ export const SuspenseListComponent = 19;
export const FundamentalComponent = 20;
export const ScopeComponent = 21;
export const Block = 22;
export const OffscreenComponent = 23;
2 changes: 2 additions & 0 deletions packages/shared/ReactSymbols.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export let REACT_RESPONDER_TYPE = 0xead6;
export let REACT_SCOPE_TYPE = 0xead7;
export let REACT_OPAQUE_ID_TYPE = 0xeae0;
export let REACT_DEBUG_TRACING_MODE_TYPE = 0xeae1;
export let REACT_OFFSCREEN_TYPE = 0xeae2;

if (typeof Symbol === 'function' && Symbol.for) {
const symbolFor = Symbol.for;
Expand All @@ -54,6 +55,7 @@ if (typeof Symbol === 'function' && Symbol.for) {
REACT_SCOPE_TYPE = symbolFor('react.scope');
REACT_OPAQUE_ID_TYPE = symbolFor('react.opaque.id');
REACT_DEBUG_TRACING_MODE_TYPE = symbolFor('react.debug_trace_mode');
REACT_OFFSCREEN_TYPE = symbolFor('react.offscreen');
}

const MAYBE_ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator;
Expand Down

0 comments on commit ed01fda

Please sign in to comment.