Skip to content

Commit dadeb06

Browse files
committed
Stub host config methods to suspend commit phase
This adds some new methods to the host config, but does not implement them yet. The purpose of these methods will be to allow the renderer to suspend right the commit phase without suspending render, like to wait for CSS to load before updating the screen. More context will be given subsequent steps. I didn't follow the `supportsHydration` pattern for optional host config methods because this feature seems pretty generally useful to any renderer, and declaring a no-op implementation is trivial. I didn't update the docs for react-reconciler yet because this very likely isn't the final layering. I'll document once the contract has stablized more.
1 parent 493a786 commit dadeb06

File tree

9 files changed

+154
-0
lines changed

9 files changed

+154
-0
lines changed

packages/react-art/src/ReactARTHostConfig.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,18 @@ export function requestPostPaintCallback(callback: (time: number) => void) {
459459
// noop
460460
}
461461

462+
export function shouldSuspendMount(instance, type, newProps) {
463+
return null;
464+
}
465+
466+
export function shouldSuspendUpdate(instance, type, oldProps, newProps) {
467+
return null;
468+
}
469+
470+
export function waitForCommitToBeReady(suspenseyThings) {
471+
return null;
472+
}
473+
462474
// eslint-disable-next-line no-undef
463475
export function prepareRendererToRender(container: Container): void {
464476
// noop

packages/react-dom-bindings/src/client/ReactDOMHostConfig.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ export type ChildSet = void; // Unused
156156
export type TimeoutHandle = TimeoutID;
157157
export type NoTimeout = -1;
158158
export type RendererInspectionConfig = $ReadOnly<{}>;
159+
export type SuspendCommitPayload = null;
159160

160161
type SelectionInformation = {
161162
focusedElem: null | HTMLElement,
@@ -1608,6 +1609,30 @@ export function requestPostPaintCallback(callback: (time: number) => void) {
16081609
localRequestAnimationFrame(time => callback(time));
16091610
});
16101611
}
1612+
1613+
export function shouldSuspendMount(
1614+
instance: Instance,
1615+
type: string,
1616+
newProps: Props,
1617+
): SuspendCommitPayload | null {
1618+
return null;
1619+
}
1620+
1621+
export function shouldSuspendUpdate(
1622+
instance: Instance,
1623+
type: string,
1624+
oldProps: Props,
1625+
newProps: Props,
1626+
): SuspendCommitPayload | null {
1627+
return null;
1628+
}
1629+
1630+
export function waitForCommitToBeReady(
1631+
suspenseyThings: Array<SuspendCommitPayload> | null,
1632+
): null {
1633+
return null;
1634+
}
1635+
16111636
// -------------------
16121637
// Resources
16131638
// -------------------

packages/react-native-renderer/src/ReactFabricHostConfig.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ export type RendererInspectionConfig = $ReadOnly<{
8787
) => void,
8888
}>;
8989

90+
export type SuspendCommitPayload = null;
91+
9092
// TODO: Remove this conditional once all changes have propagated.
9193
if (registerEventHandler) {
9294
/**
@@ -418,6 +420,29 @@ export function requestPostPaintCallback(callback: (time: number) => void) {
418420
// noop
419421
}
420422

423+
export function shouldSuspendMount(
424+
instance: Instance,
425+
type: string,
426+
newProps: Props,
427+
): SuspendCommitPayload | null {
428+
return null;
429+
}
430+
431+
export function shouldSuspendUpdate(
432+
instance: Instance,
433+
type: string,
434+
oldProps: Props,
435+
newProps: Props,
436+
): SuspendCommitPayload | null {
437+
return null;
438+
}
439+
440+
export function waitForCommitToBeReady(
441+
suspenseyThings: Array<SuspendCommitPayload> | null,
442+
): null {
443+
return null;
444+
}
445+
421446
export function prepareRendererToRender(container: Container): void {
422447
// noop
423448
}

packages/react-native-renderer/src/ReactNativeHostConfig.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ export type RendererInspectionConfig = $ReadOnly<{
5555
) => void,
5656
}>;
5757

58+
export type SuspendCommitPayload = null;
59+
5860
const UPDATE_SIGNAL = {};
5961
if (__DEV__) {
6062
Object.freeze(UPDATE_SIGNAL);
@@ -522,6 +524,29 @@ export function requestPostPaintCallback(callback: (time: number) => void) {
522524
// noop
523525
}
524526

527+
export function shouldSuspendMount(
528+
instance: Instance,
529+
type: string,
530+
newProps: Props,
531+
): SuspendCommitPayload | null {
532+
return null;
533+
}
534+
535+
export function shouldSuspendUpdate(
536+
instance: Instance,
537+
type: string,
538+
oldProps: Props,
539+
newProps: Props,
540+
): SuspendCommitPayload | null {
541+
return null;
542+
}
543+
544+
export function waitForCommitToBeReady(
545+
suspenseyThings: Array<SuspendCommitPayload> | null,
546+
): null {
547+
return null;
548+
}
549+
525550
export function prepareRendererToRender(container: Container): void {
526551
// noop
527552
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ export const {
2828
createLegacyRoot,
2929
getChildrenAsJSX,
3030
getPendingChildrenAsJSX,
31+
getSuspenseyThingStatus,
32+
resolveSuspenseyThing,
33+
resetSuspenseyThingCache,
3134
createPortal,
3235
render,
3336
renderLegacySyncRoot,

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ type CreateRootOptions = {
7272
...
7373
};
7474

75+
type SuspendCommitPayload = string;
76+
7577
const NO_CONTEXT = {};
7678
const UPPERCASE_CONTEXT = {};
7779
const UPDATE_SIGNAL = {};
@@ -480,6 +482,30 @@ function createReactNoop(reconciler: Function, useMutation: boolean) {
480482
const endTime = Scheduler.unstable_now();
481483
callback(endTime);
482484
},
485+
486+
shouldSuspendMount(
487+
instance: Instance,
488+
type: string,
489+
newProps: Props,
490+
): SuspendCommitPayload | null {
491+
return null;
492+
},
493+
494+
shouldSuspendUpdate(
495+
instance: Instance,
496+
type: string,
497+
oldProps: Props,
498+
newProps: Props,
499+
): SuspendCommitPayload | null {
500+
return null;
501+
},
502+
503+
waitForCommitToBeReady(
504+
suspenseyThings: Array<SuspendCommitPayload> | null,
505+
): null {
506+
return null;
507+
},
508+
483509
prepareRendererToRender() {},
484510
resetRendererAfterRender() {},
485511
};

packages/react-reconciler/src/__tests__/ReactFiberHostContext-test.internal.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,15 @@ describe('ReactFiberHostContext', () => {
7171
return DefaultEventPriority;
7272
},
7373
requestPostPaintCallback: function () {},
74+
shouldSuspendMount(instance, type, newProps) {
75+
return null;
76+
},
77+
shouldSuspendUpdate(instance, type, oldProps, newProps) {
78+
return null;
79+
},
80+
waitForCommitToBeReady(suspenseyThings) {
81+
return null;
82+
},
7483
prepareRendererToRender: function () {},
7584
resetRendererAfterRender: function () {},
7685
supportsMutation: true,

packages/react-reconciler/src/forks/ReactFiberHostConfig.custom.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export opaque type ChildSet = mixed; // eslint-disable-line no-undef
3838
export opaque type TimeoutHandle = mixed; // eslint-disable-line no-undef
3939
export opaque type NoTimeout = mixed; // eslint-disable-line no-undef
4040
export opaque type RendererInspectionConfig = mixed; // eslint-disable-line no-undef
41+
export opaque type SuspendCommitPayload = mixed; // eslint-disable-line no-undef
4142
export type EventResponder = any;
4243

4344
export const getPublicInstance = $$$hostConfig.getPublicInstance;
@@ -68,6 +69,9 @@ export const getInstanceFromScope = $$$hostConfig.getInstanceFromScope;
6869
export const getCurrentEventPriority = $$$hostConfig.getCurrentEventPriority;
6970
export const detachDeletedInstance = $$$hostConfig.detachDeletedInstance;
7071
export const requestPostPaintCallback = $$$hostConfig.requestPostPaintCallback;
72+
export const shouldSuspendMount = $$$hostConfig.shouldSuspendMount;
73+
export const shouldSuspendUpdate = $$$hostConfig.shouldSuspendUpdate;
74+
export const waitForCommitToBeReady = $$$hostConfig.waitForCommitToBeReady;
7175
export const prepareRendererToRender = $$$hostConfig.prepareRendererToRender;
7276
export const resetRendererAfterRender = $$$hostConfig.resetRendererAfterRender;
7377

packages/react-test-renderer/src/ReactTestHostConfig.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ export type EventResponder = any;
4242

4343
export type RendererInspectionConfig = $ReadOnly<{}>;
4444

45+
export type SuspendCommitPayload = null;
46+
4547
export * from 'react-reconciler/src/ReactFiberHostConfigWithNoPersistence';
4648
export * from 'react-reconciler/src/ReactFiberHostConfigWithNoHydration';
4749
export * from 'react-reconciler/src/ReactFiberHostConfigWithNoTestSelectors';
@@ -324,6 +326,29 @@ export function requestPostPaintCallback(callback: (time: number) => void) {
324326
// noop
325327
}
326328

329+
export function shouldSuspendMount(
330+
instance: Instance,
331+
type: string,
332+
newProps: Props,
333+
): SuspendCommitPayload | null {
334+
return null;
335+
}
336+
337+
export function shouldSuspendUpdate(
338+
instance: Instance,
339+
type: string,
340+
oldProps: Props,
341+
newProps: Props,
342+
): SuspendCommitPayload | null {
343+
return null;
344+
}
345+
346+
export function waitForCommitToBeReady(
347+
suspenseyThings: Array<SuspendCommitPayload> | null,
348+
): null {
349+
return null;
350+
}
351+
327352
export function prepareRendererToRender(container: Container): void {
328353
// noop
329354
}

0 commit comments

Comments
 (0)