question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Dom is not removed when unmounting for Layer components

See original GitHub issue

This 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

  1. Clone the repository
  2. Run yarn
  3. 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:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:11 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
ShimiSuncommented, Feb 10, 2020

@mateeyow this issue is addressed on https://github.com/grommet/grommet/pull/3737, thank you for reporting.

0reactions
mateeyowcommented, Feb 11, 2020

@ShimiSun thank you.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found