Dom is not removed when unmounting for Layer components
See original GitHub issueThis might be related to issue #3623.
So I created a Modal
component that accepts a props of boolean. If props is false the component will not render anything, if props is true it should render the Layer
component along with its children.
Upon running the test with props to true, the test will pass correctly. But, upon adding a second test to check if the Modal component renders - it fails.
Expected Behavior
Test should pass and should not see the Modal
component on the DOM.
Actual Behavior
Tests fails if the previous.
URL, screen shot, or Codepen exhibiting the issue
You can check the repository here
OR just add this code.
// Modal.js
import React from 'react'
const Modal = ({ isOpen = false }) => {
if (!isOpen) { return null; }
return (
<div data-testid='modal'>
<span>You should see this</span>
</div>
)
}
export default Modal
// ModalSpec.js
import React from 'react'
import { render, cleanup } from '@testing-library/react'
import Modal from '../Modal'
describe('#Modal', () => {
afterEach(cleanup)
it('should be able to see the modal', () => {
const { getByTestId } = render(<Modal isOpen={true} />)
expect(getByTestId('modal')).toBeInTheDocument();
})
it('should not be able to see the modal', () => {
const { queryByTestId } = render(<Modal isOpen={false} />)
expect(queryByTestId('modal')).not.toBeInTheDocument()
})
})
Steps to Reproduce
- Clone the repository
- Run
yarn
- Run
yarn test
Your Environment
- Grommet version: ^2.9.0
- Browser Name and version: Terminal
- Operating System and version (desktop or mobile): MacOS Mojave (10.14.6)
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:11 (7 by maintainers)
Top Results From Across the Web
prevent component from unmounting when displayed in ...
1 Answer 1 · Store <A/> as a variable · Remove the inner <div/> ( <A/> will automatically be removed as well) ·...
Read more >Removing non visible views from the DOM while still being ...
Inactive views are not inside the DOM. When re-activating the views, the latest state is in place and the scroll state is kept....
Read more >How to Unmount a ReactJS Node - Pluralsight
Unmount a React Node. It's possible for a specific component to be removed from the DOM after completion of an operation.
Read more >Managing DOM components with ReactDOM - LogRocket Blog
Learn to expertly manage DOM components in a React app, including a deep dive into each ReactDOM method, with this comprehensive tutorial.
Read more >Reparenting is now possible with React - DEV Community ...
In fact, the DOM elements of the Card are recreated from scratch and ... Some open issues confirm that React does not yet...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@mateeyow this issue is addressed on https://github.com/grommet/grommet/pull/3737, thank you for reporting.
@ShimiSun thank you.