Skip to content

Commit 23372a5

Browse files
committed
Add test for render phase updates
Noticed this while fixing the previous bug
1 parent de5f63f commit 23372a5

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

packages/react-dom/src/__tests__/ReactDOMUseId-test.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ let ReactDOMFizzServer;
1616
let Stream;
1717
let Suspense;
1818
let useId;
19+
let useState;
1920
let document;
2021
let writable;
2122
let container;
@@ -35,6 +36,7 @@ describe('useId', () => {
3536
Stream = require('stream');
3637
Suspense = React.Suspense;
3738
useId = React.useId;
39+
useState = React.useState;
3840

3941
// Test Environment
4042
const jsdom = new JSDOM(
@@ -342,6 +344,32 @@ describe('useId', () => {
342344
`);
343345
});
344346

347+
test('local render phase updates', async () => {
348+
function App({swap}) {
349+
const [count, setCount] = useState(0);
350+
if (count < 3) {
351+
setCount(count + 1);
352+
}
353+
return useId();
354+
}
355+
356+
await serverAct(async () => {
357+
const {pipe} = ReactDOMFizzServer.renderToPipeableStream(<App />);
358+
pipe(writable);
359+
});
360+
await clientAct(async () => {
361+
ReactDOM.hydrateRoot(container, <App />);
362+
});
363+
expect(container).toMatchInlineSnapshot(`
364+
<div
365+
id="container"
366+
>
367+
R:0
368+
<!-- -->
369+
</div>
370+
`);
371+
});
372+
345373
test('basic incremental hydration', async () => {
346374
function App() {
347375
return (

packages/react-server/src/ReactFizzHooks.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ export function finishHooks(
199199
// work-in-progress hooks and applying the additional updates on top. Keep
200200
// restarting until no more updates are scheduled.
201201
didScheduleRenderPhaseUpdate = false;
202-
// TODO: Reset localIdCounter
202+
localIdCounter = 0;
203203
numberOfReRenders += 1;
204204

205205
// Start over from the beginning of the list

0 commit comments

Comments
 (0)