Skip to content

Commit e03c92e

Browse files
committed
Update Context.Consumer inside suspended Suspense component
1 parent 79740da commit e03c92e

File tree

2 files changed

+59
-4
lines changed

2 files changed

+59
-4
lines changed

packages/react-reconciler/src/ReactFiberNewContext.new.js

-4
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,6 @@ export function scheduleWorkOnParentPath(
157157
!isSubsetOfLanes(alternate.childLanes, renderLanes)
158158
) {
159159
alternate.childLanes = mergeLanes(alternate.childLanes, renderLanes);
160-
} else {
161-
// Neither alternate was updated, which means the rest of the
162-
// ancestor path already has sufficient priority.
163-
break;
164160
}
165161
node = node.return;
166162
}

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

+59
Original file line numberDiff line numberDiff line change
@@ -1523,4 +1523,63 @@ describe('ReactSuspense', () => {
15231523
expect(root).toMatchRenderedOutput('new value');
15241524
});
15251525
});
1526+
1527+
it('updates context consumer within child of suspended suspense component when context updates', () => {
1528+
const {createContext, useState} = React;
1529+
1530+
const ValueContext = createContext(null);
1531+
1532+
const promiseThatNeverResolves = new Promise(() => {});
1533+
function Child() {
1534+
return (
1535+
<ValueContext.Consumer>
1536+
{value => {
1537+
Scheduler.unstable_yieldValue(`Received context value [${value}]`);
1538+
if (value === 'default') return <Text text="default" />;
1539+
throw promiseThatNeverResolves;
1540+
}}
1541+
</ValueContext.Consumer>
1542+
);
1543+
}
1544+
1545+
let setValue;
1546+
function Wrapper({children}) {
1547+
const [value, _setValue] = useState('default');
1548+
setValue = _setValue;
1549+
return (
1550+
<ValueContext.Provider value={value}>{children}</ValueContext.Provider>
1551+
);
1552+
}
1553+
1554+
function App() {
1555+
return (
1556+
<Wrapper>
1557+
<Suspense fallback={<Text text="Loading..." />}>
1558+
<Child />
1559+
</Suspense>
1560+
</Wrapper>
1561+
);
1562+
}
1563+
1564+
const root = ReactTestRenderer.create(<App />);
1565+
expect(Scheduler).toHaveYielded([
1566+
'Received context value [default]',
1567+
'default',
1568+
]);
1569+
expect(root).toMatchRenderedOutput('default');
1570+
1571+
act(() => setValue('new value'));
1572+
expect(Scheduler).toHaveYielded([
1573+
'Received context value [new value]',
1574+
'Loading...',
1575+
]);
1576+
expect(root).toMatchRenderedOutput('Loading...');
1577+
1578+
act(() => setValue('default'));
1579+
expect(Scheduler).toHaveYielded([
1580+
'Received context value [default]',
1581+
'default',
1582+
]);
1583+
expect(root).toMatchRenderedOutput('default');
1584+
});
15261585
});

0 commit comments

Comments
 (0)