Skip to content
Merged
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
8 changes: 5 additions & 3 deletions packages/react-art/src/ReactFiberConfigART.js
Original file line number Diff line number Diff line change
Expand Up @@ -609,11 +609,13 @@ export function preloadInstance(type, props) {
return true;
}

export function startSuspendingCommit() {}
export function startSuspendingCommit() {
return null;
}

export function suspendInstance(instance, type, props) {}
export function suspendInstance(state, instance, type, props) {}

export function suspendOnActiveViewTransition(container) {}
export function suspendOnActiveViewTransition(state, container) {}

export function waitForCommitToBeReady(timeoutOffset) {
return null;
Expand Down
43 changes: 12 additions & 31 deletions packages/react-dom-bindings/src/client/ReactFiberConfigDOM.js
Original file line number Diff line number Diff line change
Expand Up @@ -2081,6 +2081,7 @@ function forceLayout(ownerDocument: Document) {
}

export function startViewTransition(
suspendedState: null | SuspendedState,
rootContainer: Container,
transitionTypes: null | TransitionTypes,
mutationCallback: () => void,
Expand Down Expand Up @@ -2443,6 +2444,7 @@ function animateGesture(
}

export function startGestureTransition(
suspendedState: null | SuspendedState,
rootContainer: Container,
timeline: GestureTimeline,
rangeStart: number,
Expand Down Expand Up @@ -5904,18 +5906,17 @@ export function preloadResource(resource: Resource): boolean {
return true;
}

type SuspendedState = {
export opaque type SuspendedState = {
stylesheets: null | Map<StylesheetResource, HoistableRoot>,
count: number, // suspensey css and active view transitions
imgCount: number, // suspensey images
imgBytes: number, // number of bytes we estimate needing to download
waitingForImages: boolean, // false when we're no longer blocking on images
unsuspend: null | (() => void),
};
let suspendedState: null | SuspendedState = null;

export function startSuspendingCommit(): void {
suspendedState = {
export function startSuspendingCommit(): SuspendedState {
return {
stylesheets: null,
count: 0,
imgCount: 0,
Expand All @@ -5930,19 +5931,14 @@ export function startSuspendingCommit(): void {
}

export function suspendInstance(
state: SuspendedState,
instance: Instance,
type: Type,
props: Props,
): void {
if (!enableSuspenseyImages && !enableViewTransition) {
return;
}
if (suspendedState === null) {
throw new Error(
'Internal React Error: suspendedState null when it was expected to exists. Please report this as a React bug.',
);
}
const state = suspendedState;
if (
// $FlowFixMe[prop-missing]
typeof instance.decode === 'function' &&
Expand Down Expand Up @@ -5971,16 +5967,11 @@ export function suspendInstance(
}

export function suspendResource(
state: SuspendedState,
hoistableRoot: HoistableRoot,
resource: Resource,
props: any,
): void {
if (suspendedState === null) {
throw new Error(
'Internal React Error: suspendedState null when it was expected to exists. Please report this as a React bug.',
);
}
const state = suspendedState;
if (resource.type === 'stylesheet') {
if (typeof props.media === 'string') {
// If we don't currently match media we avoid suspending on this resource
Expand Down Expand Up @@ -6060,13 +6051,10 @@ export function suspendResource(
}
}

export function suspendOnActiveViewTransition(rootContainer: Container): void {
if (suspendedState === null) {
throw new Error(
'Internal React Error: suspendedState null when it was expected to exists. Please report this as a React bug.',
);
}
const state = suspendedState;
export function suspendOnActiveViewTransition(
state: SuspendedState,
rootContainer: Container,
): void {
const ownerDocument =
rootContainer.nodeType === DOCUMENT_NODE
? rootContainer
Expand All @@ -6090,16 +6078,9 @@ const SUSPENSEY_IMAGE_TIME_ESTIMATE = 500;
let estimatedBytesWithinLimit: number = 0;

export function waitForCommitToBeReady(
state: SuspendedState,
timeoutOffset: number,
): null | ((() => void) => () => void) {
if (suspendedState === null) {
throw new Error(
'Internal React Error: suspendedState null when it was expected to exists. Please report this as a React bug.',
);
}

const state = suspendedState;

if (state.stylesheets && state.count === 0) {
// We are not currently blocked but we have not inserted all stylesheets.
// If this insertion happens and loads or errors synchronously then we can
Expand Down
17 changes: 14 additions & 3 deletions packages/react-native-renderer/src/ReactFiberConfigFabric.js
Original file line number Diff line number Diff line change
Expand Up @@ -602,17 +602,28 @@ export function preloadInstance(
return true;
}

export function startSuspendingCommit(): void {}
export opaque type SuspendedState = null;

export function startSuspendingCommit(): SuspendedState {
return null;
}

export function suspendInstance(
state: SuspendedState,
instance: Instance,
type: Type,
props: Props,
): void {}

export function suspendOnActiveViewTransition(container: Container): void {}
export function suspendOnActiveViewTransition(
state: SuspendedState,
container: Container,
): void {}

export function waitForCommitToBeReady(timeoutOffset: number): null {
export function waitForCommitToBeReady(
state: SuspendedState,
timeoutOffset: number,
): null {
return null;
}

Expand Down
19 changes: 16 additions & 3 deletions packages/react-native-renderer/src/ReactFiberConfigNative.js
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,7 @@ export function hasInstanceAffectedParent(
}

export function startViewTransition(
suspendedState: null | SuspendedState,
rootContainer: Container,
transitionTypes: null | TransitionTypes,
mutationCallback: () => void,
Expand All @@ -684,6 +685,7 @@ export function startViewTransition(
export type RunningViewTransition = null;

export function startGestureTransition(
suspendedState: null | SuspendedState,
rootContainer: Container,
timeline: GestureTimeline,
rangeStart: number,
Expand Down Expand Up @@ -778,17 +780,28 @@ export function preloadInstance(
return true;
}

export function startSuspendingCommit(): void {}
export opaque type SuspendedState = null;

export function startSuspendingCommit(): SuspendedState {
return null;
}

export function suspendInstance(
state: SuspendedState,
instance: Instance,
type: Type,
props: Props,
): void {}

export function suspendOnActiveViewTransition(container: Container): void {}
export function suspendOnActiveViewTransition(
state: SuspendedState,
container: Container,
): void {}

export function waitForCommitToBeReady(timeoutOffset: number): null {
export function waitForCommitToBeReady(
state: SuspendedState,
timeoutOffset: number,
): null {
return null;
}

Expand Down
45 changes: 21 additions & 24 deletions packages/react-noop-renderer/src/createReactNoop.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ type SuspenseyCommitSubscription = {
commit: null | (() => void),
};

export opaque type SuspendedState = SuspenseyCommitSubscription;

export type TransitionStatus = mixed;

export type FormInstance = Instance;
Expand Down Expand Up @@ -311,17 +313,17 @@ function createReactNoop(reconciler: Function, useMutation: boolean) {
'pending' | 'fulfilled',
> | null = null;

// Represents a subscription for all the suspensey things that block a
// particular commit. Once they've all loaded, the commit phase can proceed.
let suspenseyCommitSubscription: SuspenseyCommitSubscription | null = null;

function startSuspendingCommit(): void {
// This is where we might suspend on things that aren't associated with a
// particular node, like document.fonts.ready.
suspenseyCommitSubscription = null;
function startSuspendingCommit(): SuspendedState {
// Represents a subscription for all the suspensey things that block a
// particular commit. Once they've all loaded, the commit phase can proceed.
return {
pendingCount: 0,
commit: null,
};
}

function suspendInstance(
state: SuspendedState,
instance: Instance,
type: string,
props: Props,
Expand All @@ -338,20 +340,13 @@ function createReactNoop(reconciler: Function, useMutation: boolean) {
if (record.status === 'fulfilled') {
// Already loaded.
} else if (record.status === 'pending') {
if (suspenseyCommitSubscription === null) {
suspenseyCommitSubscription = {
pendingCount: 1,
commit: null,
};
} else {
suspenseyCommitSubscription.pendingCount++;
}
state.pendingCount++;
// Stash the subscription on the record. In `resolveSuspenseyThing`,
// we'll use this fire the commit once all the things have loaded.
if (record.subscriptions === null) {
record.subscriptions = [];
}
record.subscriptions.push(suspenseyCommitSubscription);
record.subscriptions.push(state);
}
} else {
throw new Error(
Expand All @@ -362,15 +357,14 @@ function createReactNoop(reconciler: Function, useMutation: boolean) {
}

function waitForCommitToBeReady(
state: SuspendedState,
timeoutOffset: number,
): ((commit: () => mixed) => () => void) | null {
const subscription = suspenseyCommitSubscription;
if (subscription !== null) {
suspenseyCommitSubscription = null;
if (state.pendingCount > 0) {
return (commit: () => void) => {
subscription.commit = commit;
state.commit = commit;
const cancelCommit = () => {
subscription.commit = null;
state.commit = null;
};
return cancelCommit;
};
Expand Down Expand Up @@ -693,13 +687,16 @@ function createReactNoop(reconciler: Function, useMutation: boolean) {
startSuspendingCommit,
suspendInstance,

suspendResource(resource: mixed): void {
suspendResource(state: SuspendedState, resource: mixed): void {
throw new Error(
'Resources are not implemented for React Noop yet. This method should not be called',
);
},

suspendOnActiveViewTransition(container: Container): void {
suspendOnActiveViewTransition(
state: SuspendedState,
container: Container,
): void {
// Not implemented
},

Expand Down
Loading
Loading