GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Don't ignore dependencies for render phase update (#16574) · react/react@01fb68b

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • packages
    • react-reconciler/src
      • ReactFiberHooks.js
    • react-refresh/src/__tests__
      • ReactFresh-test.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎packages/react-reconciler/src/ReactFiberHooks.js‎

Copy file name to clipboardExpand all lines: packages/react-reconciler/src/ReactFiberHooks.js
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,11 @@ export function renderWithHooks(
428428
do {
429429
didScheduleRenderPhaseUpdate = false;
430430
numberOfReRenders += 1;
431+
if (__DEV__) {
432+
// Even when hot reloading, allow dependencies to stabilize
433+
// after first render to prevent infinite render phase updates.
434+
ignorePreviousDependencies = false;
435+
}
431436

432437
// Start over from the beginning of the list
433438
nextCurrentHook = current !== null ? current.memoizedState : null;
Collapse file

‎packages/react-refresh/src/__tests__/ReactFresh-test.js‎

Copy file name to clipboardExpand all lines: packages/react-refresh/src/__tests__/ReactFresh-test.js
+43Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2350,6 +2350,49 @@ describe('ReactFresh', () => {
23502350
}
23512351
});
23522352

2353+
// This pattern is inspired by useSubscription and similar mechanisms.
2354+
it('does not get into infinite loops during render phase updates', () => {
2355+
if (__DEV__) {
2356+
render(() => {
2357+
function Hello() {
2358+
const source = React.useMemo(() => ({value: 10}), []);
2359+
const [state, setState] = React.useState({value: null});
2360+
if (state !== source) {
2361+
setState(source);
2362+
}
2363+
return <p style={{color: 'blue'}}>{state.value}</p>;
2364+
}
2365+
$RefreshReg$(Hello, 'Hello');
2366+
return Hello;
2367+
});
2368+
2369+
const el = container.firstChild;
2370+
expect(el.textContent).toBe('10');
2371+
expect(el.style.color).toBe('blue');
2372+
2373+
// Perform a hot update.
2374+
act(() => {
2375+
patch(() => {
2376+
function Hello() {
2377+
const source = React.useMemo(() => ({value: 20}), []);
2378+
const [state, setState] = React.useState({value: null});
2379+
if (state !== source) {
2380+
// This should perform a single render-phase update.
2381+
setState(source);
2382+
}
2383+
return <p style={{color: 'red'}}>{state.value}</p>;
2384+
}
2385+
$RefreshReg$(Hello, 'Hello');
2386+
return Hello;
2387+
});
2388+
});
2389+
2390+
expect(container.firstChild).toBe(el);
2391+
expect(el.textContent).toBe('20');
2392+
expect(el.style.color).toBe('red');
2393+
}
2394+
});
2395+
23532396
it('can hot reload offscreen components', () => {
23542397
if (__DEV__) {
23552398
const AppV1 = prepare(() => {

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.