Skip to content

Commit 0cf6399

Browse files
author
Brian Vaughn
committed
Merged master; moved event registration from enqueueUpdate to scheduleWork
2 parents eb2107c + a32c727 commit 0cf6399

35 files changed

+2313
-1778
lines changed

packages/create-subscription/src/createSubscription.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,13 @@ export function createSubscription<Property, Value>(
8787

8888
componentDidUpdate(prevProps, prevState) {
8989
if (this.state.source !== prevState.source) {
90-
this.unsubscribe(prevState);
90+
this.unsubscribe();
9191
this.subscribe();
9292
}
9393
}
9494

9595
componentWillUnmount() {
96-
this.unsubscribe(this.state);
96+
this.unsubscribe();
9797

9898
// Track mounted to avoid calling setState after unmounting
9999
// For source like Promises that can't be unsubscribed from.
@@ -147,7 +147,7 @@ export function createSubscription<Property, Value>(
147147
}
148148
}
149149

150-
unsubscribe(state: State) {
150+
unsubscribe() {
151151
if (typeof this._unsubscribe === 'function') {
152152
this._unsubscribe();
153153
}

packages/react-dom/src/__tests__/ReactServerRenderingHydration.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,6 @@ describe('ReactDOMServerHydration', () => {
292292

293293
expect(() => ReactDOM.hydrate(markup, element)).toWarnDev(
294294
'Please update the following components to use componentDidMount instead: ComponentWithWarning',
295-
{withoutStack: true},
296295
);
297296
expect(element.textContent).toBe('Hi');
298297
});

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

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,7 @@ if (__DEV__) {
4040

4141
function createReactNoop(reconciler: Function, useMutation: boolean) {
4242
let scheduledCallback = null;
43-
4443
let instanceCounter = 0;
45-
let failInBeginPhase = false;
46-
let failInCompletePhase = false;
4744

4845
function appendChildToContainerOrInstance(
4946
parentInstance: Container | Instance,
@@ -167,9 +164,6 @@ function createReactNoop(reconciler: Function, useMutation: boolean) {
167164

168165
const sharedHostConfig = {
169166
getRootHostContext() {
170-
if (failInBeginPhase) {
171-
throw new Error('Error in host config.');
172-
}
173167
return NO_CONTEXT;
174168
},
175169

@@ -182,7 +176,7 @@ function createReactNoop(reconciler: Function, useMutation: boolean) {
182176
},
183177

184178
createInstance(type: string, props: Props): Instance {
185-
if (failInCompletePhase) {
179+
if (type === 'errorInCompletePhase') {
186180
throw new Error('Error in host config.');
187181
}
188182
const inst = {
@@ -217,6 +211,9 @@ function createReactNoop(reconciler: Function, useMutation: boolean) {
217211
oldProps: Props,
218212
newProps: Props,
219213
): null | {} {
214+
if (type === 'errorInCompletePhase') {
215+
throw new Error('Error in host config.');
216+
}
220217
if (oldProps === null) {
221218
throw new Error('Should have old props');
222219
}
@@ -227,6 +224,9 @@ function createReactNoop(reconciler: Function, useMutation: boolean) {
227224
},
228225

229226
shouldSetTextContent(type: string, props: Props): boolean {
227+
if (type === 'errorInBeginPhase') {
228+
throw new Error('Error in host config.');
229+
}
230230
return (
231231
typeof props.children === 'string' || typeof props.children === 'number'
232232
);
@@ -662,7 +662,10 @@ function createReactNoop(reconciler: Function, useMutation: boolean) {
662662
'- ' +
663663
// need to explicitly coerce Symbol to a string
664664
(fiber.type ? fiber.type.name || fiber.type.toString() : '[root]'),
665-
'[' + fiber.expirationTime + (fiber.pendingProps ? '*' : '') + ']',
665+
'[' +
666+
fiber.childExpirationTime +
667+
(fiber.pendingProps ? '*' : '') +
668+
']',
666669
);
667670
if (fiber.updateQueue) {
668671
logUpdateQueue(fiber.updateQueue, depth);
@@ -695,24 +698,6 @@ function createReactNoop(reconciler: Function, useMutation: boolean) {
695698
console.log(...bufferedLog);
696699
},
697700

698-
simulateErrorInHostConfigDuringBeginPhase(fn: () => void) {
699-
failInBeginPhase = true;
700-
try {
701-
fn();
702-
} finally {
703-
failInBeginPhase = false;
704-
}
705-
},
706-
707-
simulateErrorInHostConfigDuringCompletePhase(fn: () => void) {
708-
failInCompletePhase = true;
709-
try {
710-
fn();
711-
} finally {
712-
failInCompletePhase = false;
713-
}
714-
},
715-
716701
flushWithoutCommitting(
717702
expectedFlush: Array<mixed>,
718703
rootID: string = DEFAULT_ROOT_ID,

packages/react-reconciler/src/ReactCurrentFiber.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
FunctionalComponent,
1414
ClassComponent,
1515
HostComponent,
16+
Mode,
1617
} from 'shared/ReactTypeOfWork';
1718
import describeComponentFrame from 'shared/describeComponentFrame';
1819
import getComponentName from 'shared/getComponentName';
@@ -29,6 +30,7 @@ function describeFiber(fiber: Fiber): string {
2930
case FunctionalComponent:
3031
case ClassComponent:
3132
case HostComponent:
33+
case Mode:
3234
const owner = fiber._debugOwner;
3335
const source = fiber._debugSource;
3436
const name = getComponentName(fiber.type);

packages/react-reconciler/src/ReactFiber.js

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import type {ExpirationTime} from './ReactFiberExpirationTime';
1616
import type {UpdateQueue} from './ReactUpdateQueue';
1717
import type {Interaction} from 'interaction-tracking/src/InteractionTracking';
1818
import type {PendingInteractionMap} from './ReactFiberRoot';
19+
import type {ContextDependency} from './ReactFiberNewContext';
1920

2021
import invariant from 'shared/invariant';
2122
import {enableProfilerTimer} from 'shared/ReactFeatureFlags';
@@ -77,7 +78,7 @@ if (__DEV__) {
7778
// During the commit phase, the related interactions are termporarily stored in an Array,
7879
// So that class components within the sub-tree can associate cascading updates with those events.
7980
export type ProfilerStateNode = {|
80-
committedInteractions: Array<Interaction>,
81+
committedInteractions: Set<Interaction>,
8182
pendingInteractionMap: Map<ExpirationTime, Set<Interaction>>,
8283
|};
8384

@@ -137,6 +138,9 @@ export type Fiber = {|
137138
// The state used to create the output
138139
memoizedState: any,
139140

141+
// A linked-list of contexts that this fiber depends on
142+
firstContextDependency: ContextDependency<mixed> | null,
143+
140144
// Bitfield that describes properties about the fiber and its subtree. E.g.
141145
// the AsyncMode flag indicates whether the subtree should be async-by-
142146
// default. When a fiber is created, it inherits the mode of its
@@ -158,9 +162,12 @@ export type Fiber = {|
158162
lastEffect: Fiber | null,
159163

160164
// Represents a time in the future by which this work should be completed.
161-
// This is also used to quickly determine if a subtree has no pending changes.
165+
// Does not include work found in its subtree.
162166
expirationTime: ExpirationTime,
163167

168+
// This is used to quickly determine if a subtree has no pending changes.
169+
childExpirationTime: ExpirationTime,
170+
164171
// This is a pooled version of a Fiber. Every fiber that gets updated will
165172
// eventually have a pair. There are cases when we can clean up pairs to save
166173
// memory if we need to.
@@ -226,6 +233,7 @@ function FiberNode(
226233
this.memoizedProps = null;
227234
this.updateQueue = null;
228235
this.memoizedState = null;
236+
this.firstContextDependency = null;
229237

230238
this.mode = mode;
231239

@@ -237,6 +245,7 @@ function FiberNode(
237245
this.lastEffect = null;
238246

239247
this.expirationTime = NoWork;
248+
this.childExpirationTime = NoWork;
240249

241250
this.alternate = null;
242251

@@ -338,12 +347,21 @@ export function createWorkInProgress(
338347
}
339348
}
340349

341-
workInProgress.expirationTime = expirationTime;
350+
// Don't touching the subtree's expiration time, which has not changed.
351+
workInProgress.childExpirationTime = current.childExpirationTime;
352+
if (pendingProps !== current.pendingProps) {
353+
// This fiber has new props.
354+
workInProgress.expirationTime = expirationTime;
355+
} else {
356+
// This fiber's props have not changed.
357+
workInProgress.expirationTime = current.expirationTime;
358+
}
342359

343360
workInProgress.child = current.child;
344361
workInProgress.memoizedProps = current.memoizedProps;
345362
workInProgress.memoizedState = current.memoizedState;
346363
workInProgress.updateQueue = current.updateQueue;
364+
workInProgress.firstContextDependency = current.firstContextDependency;
347365

348366
// These will be overridden during the parent's reconciliation
349367
workInProgress.sibling = current.sibling;
@@ -556,7 +574,7 @@ export function createFiberFromProfiler(
556574
// Map of expiration time to interaction events.
557575
// Populated when state updates are enqueued during a tracked interaction.
558576
fiber.stateNode = {
559-
committedInteractions: [],
577+
committedInteractions: new Set(),
560578
pendingInteractionMap,
561579
};
562580

@@ -633,12 +651,14 @@ export function assignFiberPropertiesInDEV(
633651
target.memoizedProps = source.memoizedProps;
634652
target.updateQueue = source.updateQueue;
635653
target.memoizedState = source.memoizedState;
654+
target.firstContextDependency = source.firstContextDependency;
636655
target.mode = source.mode;
637656
target.effectTag = source.effectTag;
638657
target.nextEffect = source.nextEffect;
639658
target.firstEffect = source.firstEffect;
640659
target.lastEffect = source.lastEffect;
641660
target.expirationTime = source.expirationTime;
661+
target.childExpirationTime = source.childExpirationTime;
642662
target.alternate = source.alternate;
643663
if (enableProfilerTimer) {
644664
target.actualDuration = source.actualDuration;

0 commit comments

Comments
 (0)