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
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
overflow: hidden;
}

.SuspenseRectsScaledRect[data-visible='false'] > .SuspenseRectsBoundaryChildren {
overflow: initial;
}

.SuspenseRectsRect {
box-shadow: var(--elevation-4);
pointer-events: all;
Expand All @@ -31,6 +35,11 @@
outline-color: var(--color-background-selected);
}

.SuspenseRectsScaledRect[data-visible='false'] {
pointer-events: none;
outline-width: 0;
}

/* highlight this boundary */
.SuspenseRectsBoundary:hover:not(:has(.SuspenseRectsBoundary:hover)) > .SuspenseRectsRect, .SuspenseRectsBoundary[data-highlighted='true'] > .SuspenseRectsRect {
background-color: var(--color-background-hover);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@ import {
function ScaledRect({
className,
rect,
visible,
...props
}: {
className: string,
rect: Rect,
visible: boolean,
...
}): React$Node {
const viewBox = useContext(ViewBox);
Expand All @@ -50,6 +52,7 @@ function ScaledRect({
<div
{...props}
className={styles.SuspenseRectsScaledRect + ' ' + className}
data-visible={visible}
style={{
width,
height,
Expand All @@ -68,6 +71,7 @@ function SuspenseRects({
const store = useContext(StoreContext);
const treeDispatch = useContext(TreeDispatcherContext);
const suspenseTreeDispatch = useContext(SuspenseTreeDispatcherContext);
const {uniqueSuspendersOnly} = useContext(SuspenseTreeStateContext);

const {inspectedElementID} = useContext(TreeStateContext);

Expand All @@ -79,6 +83,7 @@ function SuspenseRects({
// getSuspenseByID will have already warned
return null;
}
const visible = suspense.hasUniqueSuspenders || !uniqueSuspendersOnly;

function handleClick(event: SyntheticMouseEvent) {
if (event.defaultPrevented) {
Expand Down Expand Up @@ -117,9 +122,13 @@ function SuspenseRects({
const boundingBox = getBoundingBox(suspense.rects);

return (
<ScaledRect rect={boundingBox} className={styles.SuspenseRectsBoundary}>
<ScaledRect
rect={boundingBox}
className={styles.SuspenseRectsBoundary}
visible={visible}>
<ViewBox.Provider value={boundingBox}>
{suspense.rects !== null &&
{visible &&
suspense.rects !== null &&
suspense.rects.map((rect, index) => {
return (
<ScaledRect
Expand Down Expand Up @@ -245,6 +254,7 @@ function SuspenseRectsContainer(): React$Node {
// TODO: This relies on a full re-render of all children when the Suspense tree changes.
const {roots} = useContext(SuspenseTreeStateContext);

// TODO: bbox does not consider uniqueSuspendersOnly filter
const boundingBox = getDocumentBoundingRect(store, roots);

const boundingBoxWidth = boundingBox.width;
Expand Down
58 changes: 50 additions & 8 deletions packages/react-devtools-shell/src/app/SuspenseTree/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,12 @@ function EmptySuspense() {
// $FlowFixMe[missing-local-annot]
function PrimaryFallbackTest({initialSuspend}) {
const [suspend, setSuspend] = useState(initialSuspend);
const fallbackStep = useTestSequence('fallback', Fallback1, Fallback2);
const primaryStep = useTestSequence('primary', Primary1, Primary2);
const [fallbackStepIndex, fallbackStep] = useTestSequence(
'fallback',
Fallback1,
Fallback2,
);
const [, primaryStep] = useTestSequence('primary', Primary1, Primary2);
return (
<Fragment>
<label>
Expand All @@ -198,7 +202,11 @@ function PrimaryFallbackTest({initialSuspend}) {
</label>
<br />
<Suspense fallback={fallbackStep}>
{suspend ? <Never /> : primaryStep}
{suspend ? (
<Never id={`primary-fallback-test-${fallbackStepIndex}`} />
) : (
primaryStep
)}
</Suspense>
</Fragment>
);
Expand Down Expand Up @@ -227,7 +235,7 @@ function useTestSequence(label: string, T1: any => any, T2: any => any) {
{next} <T2 prop={step}>goodbye</T2>
</Fragment>,
];
return allSteps[step];
return [step, allSteps[step]];
}

function NestedSuspenseTest() {
Expand All @@ -252,7 +260,7 @@ function Parent() {
</Suspense>
<br />
<Suspense fallback={<Fallback1>This will never load</Fallback1>}>
<Never />
<Never id="parent-never" />
</Suspense>
<br />
<b>
Expand Down Expand Up @@ -298,14 +306,48 @@ function LoadLater() {
Loaded! Click to suspend again.
</Primary1>
) : (
<Never />
<Never id="load-later" />
)}
</Suspense>
);
}

function Never() {
throw new Promise(resolve => {});
function readRecord(promise: any): any {
if (typeof React.use === 'function') {
return React.use(promise);
}
switch (promise.status) {
case 'pending':
throw promise;
case 'rejected':
throw promise.reason;
case 'fulfilled':
return promise.value;
default:
promise.status = 'pending';
promise.then(
value => {
promise.status = 'fulfilled';
promise.value = value;
},
reason => {
promise.status = 'rejected';
promise.reason = reason;
},
);
throw promise;
}
}

const nevers = new Map<string, Promise<empty>>();
function Never({id}: {id: string}) {
let promise = nevers.get(id);
if (!promise) {
promise = new Promise(() => {});
(promise as any).displayName = id;
nevers.set(id, promise);
}
readRecord(promise);
}

function Fallback1({prop, ...rest}: any) {
Expand Down
Loading