Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

supportdocument containers in cleanup#1330

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
quisido wants to merge1 commit intotesting-library:main
base:main
Choose a base branch
Loading
fromquisido:patch-1

Conversation

quisido
Copy link

What:

Whencontainer is set todocument, the cleanup step fails:

TypeError: Cannot read properties of null (reading 'removeChild')

This is because the code assumesdocument.body exists:

    if (container.parentNode === document.body) {      document.body.removeChild(container);    }

In reality, bothcontainer.parentNodeanddocument.body arenull.

Why:

The tests erroneously fail.

How:

The attempt to remove the container from the body now only occurs when the body exists.

Checklist:

  • Documentation added to the
    docs site N/A
  • Tests
  • TypeScript definitions updated N/A
  • Ready to be merged

resolves#1329

@codesandbox-ciCodeSandbox CI
Copy link

codesandbox-cibot commentedMay 20, 2024
edited
Loading

This pull request is automatically built and testable inCodeSandbox.

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

Latest deployment of this branch, based on commit6cb2087:

SandboxSource
react-testing-library-examplesConfiguration

@eps1lon
Copy link
Member

Please add a test.

I don't understand whydocument.body would benull? Isn't that always defined?

@quisido
Copy link
Author

I don't know the setup, but is null when container is document. Locally, I fixed this by setting it to document.createElement('body').

I unfortunately do not have bandwidth to write a test for this, but the reproduction steps should be simple enough.

I ran into this specifically when writing a test for a NextJS root layout, which attempts to mount an HTML and body element. The docs say to use container: document when rendering your own HTML element, which fixed the previous error during test but introduced the OP error during cleanup.

@MatanBobi
Copy link
Member

@quisido thanks for taking the time to add this but we are not merging changes without proper coverage for them.

@quisido
Copy link
Author

@quisido thanks for taking the time to add this but we are not merging changes without proper coverage for them.

Understandable. The PR is welcome to be updated. I opened an issue for it for tracking as well. I can try updating tests as time permits, but I wanted the problem and solution to both be documented.

@MatanBobi
Copy link
Member

I tried writing a test for this but it passes in our tests becausedocument.body is notnull. I'm trying to figure out what's the difference in the setup.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@Hardanish-SinghHardanish-SinghHardanish-Singh approved these changes

At least 1 approving review is required to merge this pull request.

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

Whencontainer isdocument, cleanup steps fails with "TypeError: Cannot read properties of null (reading 'removeChild')"
4 participants
@quisido@eps1lon@MatanBobi@Hardanish-Singh

[8]ページ先頭

©2009-2025 Movatter.jp