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

Bug: Portals aren't unmounting #501

Open
edygarOliveira opened this issue Aug 24, 2018 · 1 comment
Open

Bug: Portals aren't unmounting #501

edygarOliveira opened this issue Aug 24, 2018 · 1 comment

Comments

@edygarOliveira
Copy link

edygarOliveira commented Aug 24, 2018

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.

@dbergey
Copy link

dbergey commented Sep 24, 2018

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 subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants