Skip to content

Commit

Permalink
Add test for render phase updates
Browse files Browse the repository at this point in the history
Noticed this while fixing the previous bug
  • Loading branch information
acdlite committed Nov 2, 2021
1 parent de5f63f commit 23372a5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
28 changes: 28 additions & 0 deletions packages/react-dom/src/__tests__/ReactDOMUseId-test.js
Expand Up @@ -16,6 +16,7 @@ let ReactDOMFizzServer;
let Stream;
let Suspense;
let useId;
let useState;
let document;
let writable;
let container;
Expand All @@ -35,6 +36,7 @@ describe('useId', () => {
Stream = require('stream');
Suspense = React.Suspense;
useId = React.useId;
useState = React.useState;

// Test Environment
const jsdom = new JSDOM(
Expand Down Expand Up @@ -342,6 +344,32 @@ describe('useId', () => {
`);
});

test('local render phase updates', async () => {
function App({swap}) {
const [count, setCount] = useState(0);
if (count < 3) {
setCount(count + 1);
}
return useId();
}

await serverAct(async () => {
const {pipe} = ReactDOMFizzServer.renderToPipeableStream(<App />);
pipe(writable);
});
await clientAct(async () => {
ReactDOM.hydrateRoot(container, <App />);
});
expect(container).toMatchInlineSnapshot(`
<div
id="container"
>
R:0
<!-- -->
</div>
`);
});

test('basic incremental hydration', async () => {
function App() {
return (
Expand Down
2 changes: 1 addition & 1 deletion packages/react-server/src/ReactFizzHooks.js
Expand Up @@ -199,7 +199,7 @@ export function finishHooks(
// work-in-progress hooks and applying the additional updates on top. Keep
// restarting until no more updates are scheduled.
didScheduleRenderPhaseUpdate = false;
// TODO: Reset localIdCounter
localIdCounter = 0;
numberOfReRenders += 1;

// Start over from the beginning of the list
Expand Down

0 comments on commit 23372a5

Please sign in to comment.