Skip to content
This repository was archived by the owner on Dec 16, 2021. It is now read-only.
This repository was archived by the owner on Dec 16, 2021. It is now read-only.

Bug: Portals aren't unmounting #501

Open

Description

@edygarOliveira

Problem

Portals (#486) are never unmounted. https://codesandbox.io/s/wk6y1j8777

Expected Behavior

They should clear the target once they are unmounted. https://codesandbox.io/s/9znym0r8yp

Possible solution

Instead of a Functional Component, a regular class component calling unmountComponentAtNode on componentWillUnmount could solve it.

Activity

  1. dbergey commented on Sep 24, 2018

    @dbergey

    Including this file:

    import { createElement as h } from 'react';
    import { unmountComponentAtNode, unstable_renderSubtreeIntoContainer as renderSubtreeIntoContainer } from 'react-dom';
    
    class Portal {
    	componentWillUnmount() {
    		unmountComponentAtNode(this.props.container);
    	}
    	componentDidMount() {
    		renderSubtreeIntoContainer(this, this.props.vnode, this.props.container);
    	}
    	render() {
    		// render nothing at original location
    	}
    }
    
    export function createPortal(vnode, container) {
    	return h(Portal, { vnode, container });
    }
    

    and using the exported createPortal instead of the one in preact-compat solved it for me (as suggested in the 'possible solution' above).

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions