Skip to content

fix: Don't raise TypeScript errors when hydating document#1304

Merged
eps1lon merged 1 commit intotesting-library:mainfrom
eps1lon:hydrate-document
Apr 23, 2024
Merged

fix: Don't raise TypeScript errors when hydating document#1304
eps1lon merged 1 commit intotesting-library:mainfrom
eps1lon:hydrate-document

Conversation

@eps1lon
Copy link
Member

@eps1lon eps1lon commented Apr 22, 2024

Closes #1250

As a follow-up, we need to make @types/react-dom a peer dependency. Since react-dom is a peer, the types also need to be peer. Otherwise you would get the wrong version of @types/react-dom if you'd install React 19.

@codesandbox-ci
Copy link

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 6c1fdf7:

Sandbox Source
react-testing-library-examples Configuration

@eps1lon eps1lon changed the title Don't raise TypeScript errors when hydating document fix:Don't raise TypeScript errors when hydating document Apr 22, 2024
@eps1lon eps1lon changed the title fix:Don't raise TypeScript errors when hydating document fix: Don't raise TypeScript errors when hydating document Apr 22, 2024
@eps1lon eps1lon requested a review from MatanBobi April 22, 2024 12:43
Copy link
Member

@MatanBobi MatanBobi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to merge this as a fix before merging the peer deps change?

@eps1lon
Copy link
Member Author

eps1lon commented Apr 23, 2024

Do we want to merge this as a fix before merging the peer deps change?

Yeah, I also want to wait a week (or until React 19 alpha comes out) before merging #1305

@eps1lon eps1lon merged commit 067d0c6 into testing-library:main Apr 23, 2024
@eps1lon eps1lon deleted the hydrate-document branch April 23, 2024 10:21
@AviVahl
Copy link

AviVahl commented Apr 24, 2024

@eps1lon we see type errors since this change:

node_modules/@testing-library/react/types/index.d.ts:129:52 - error TS2344: Type 'Container' does not satisfy the constraint 'Element | DocumentFragment'.
  Type 'Document | Container' is not assignable to type 'Element | DocumentFragment'.
    Type 'Document' is not assignable to type 'Element | DocumentFragment'.
      Type 'Document' is missing the following properties from type 'Element': attributes, classList, className, clientHeight, and 100 more.
        Type 'Container' is not assignable to type 'DocumentFragment'.
          Type 'Document | Container' is not assignable to type 'DocumentFragment'.
            Type 'Document' is not assignable to type 'DocumentFragment'.
              Types of property 'ownerDocument' are incompatible.
                Type 'null' is not assignable to type 'Document'.

can be reproduced with:

mkdir check-testinglib
cd check-testinglib
npm init -y
npm i react react-dom @types/react @types/react-dom typescript @testing-library/react
npx tsc --init --outDir dist --skipLibCheck false
echo "export * from '@testing-library/react';" > test.ts
npx tsc --noEmit

izzieSD pushed a commit to Izzie132/legit that referenced this pull request Feb 19, 2026
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [@testing-library/react](https://github.com/testing-library/react-testing-library) | devDependencies | major | [`^14.1.2` -> `^15.0.0`](https://renovatebot.com/diffs/npm/@testing-library%2freact/14.2.1/15.0.5) |

---

### Release Notes

<details>
<summary>testing-library/react-testing-library (@&#8203;testing-library/react)</summary>

### [`v15.0.5`](https://github.com/testing-library/react-testing-library/releases/tag/v15.0.5)

[Compare Source](testing-library/react-testing-library@v15.0.4...v15.0.5)

##### Bug Fixes

-   Stop restricting `container` option based on `hydrate` ([#&#8203;1313](testing-library/react-testing-library#1313)) ([d143f46](testing-library/react-testing-library@d143f46))

### [`v15.0.4`](https://github.com/testing-library/react-testing-library/releases/tag/v15.0.4)

[Compare Source](testing-library/react-testing-library@v15.0.3...v15.0.4)

##### Bug Fixes

-   Ensure `renderHook` options extend options for `render` ([#&#8203;1308](testing-library/react-testing-library#1308)) ([48282c2](testing-library/react-testing-library@48282c2))

### [`v15.0.3`](https://github.com/testing-library/react-testing-library/releases/tag/v15.0.3)

[Compare Source](testing-library/react-testing-library@v15.0.2...v15.0.3)

##### Bug Fixes

-   Don't raise TypeScript errors when hydating `document` ([#&#8203;1304](testing-library/react-testing-library#1304)) ([067d0c6](testing-library/react-testing-library@067d0c6))

### [`v15.0.2`](https://github.com/testing-library/react-testing-library/releases/tag/v15.0.2)

[Compare Source](testing-library/react-testing-library@v15.0.1...v15.0.2)

##### Bug Fixes

-   Improve `legacyRoot` error message ([#&#8203;1301](testing-library/react-testing-library#1301)) ([c63b873](testing-library/react-testing-library@c63b873))

### [`v15.0.1`](https://github.com/testing-library/react-testing-library/releases/tag/v15.0.1)

[Compare Source](testing-library/react-testing-library@v15.0.0...v15.0.1)

##### Bug Fixes

-   Stop using nullish coalescing ([#&#8203;1299](testing-library/react-testing-library#1299)) ([1645d21](testing-library/react-testing-library@1645d21))

### [`v15.0.0`](https://github.com/testing-library/react-testing-library/releases/tag/v15.0.0)

[Compare Source](testing-library/react-testing-library@v14.3.1...v15.0.0)

##### Relea...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Test layout.tsx file without having validateDOMNesting warning

3 participants