-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(react): update useId to match id on server and client (#6369)
Co-authored-by: Andrea N. Cardona <andreancardona@gmail.com> Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
- Loading branch information
1 parent
555038d
commit 6d3e3dc
Showing
2 changed files
with
73 additions
and
3 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
packages/react/src/internal/__tests__/useId.server-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/** | ||
* Copyright IBM Corp. 2016, 2020 | ||
* | ||
* This source code is licensed under the Apache-2.0 license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @jest-environment node | ||
*/ | ||
|
||
import React from 'react'; | ||
import { renderToString } from 'react-dom/server'; | ||
import { useId } from '../useId'; | ||
|
||
describe('useId SSR', () => { | ||
it('should not generate an id on the server', () => { | ||
function Test() { | ||
const id = useId('test'); | ||
return <span id={id}>test</span>; | ||
} | ||
const markup = renderToString(<Test />); | ||
expect(markup.indexOf('id="')).toBe(-1); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters