Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update or replace? #34

Closed
AlgoTrader opened this issue Nov 12, 2020 · 6 comments
Closed

Update or replace? #34

AlgoTrader opened this issue Nov 12, 2020 · 6 comments

Comments

@AlgoTrader
Copy link

AlgoTrader commented Nov 12, 2020

I have a question, Portal adds new content to some element, but I would like to get replacing. I have a DOM element that can be shared among many <Portal> tags.

Is it possible that every new Portal render just replaces the content of the DOM element but not just adds there?

@romkor
Copy link
Owner

romkor commented Nov 13, 2020

It's not possible with current implementation, because Portal is inserted in target using appendChild.
Replace can be a bit hard because of need to destroy svelte components before replacing them to avoid memory leaks.

@AlgoTrader
Copy link
Author

There is no need to destroy the component immediatly. I copied the code and added just three lines. I clean all the dom children before appendChild. It works, but does not look clean. Then component leave anyway. Any ideas?

@AlgoTrader
Copy link
Author

AlgoTrader commented Nov 13, 2020

I have situation when several portals compete for the single target, the last one wins. I have to control it. The example is modals. Opening a new modal removes the previous one

@johannchopin
Copy link
Contributor

@AlgoTrader It's possible in Svelte but I guess it's not the intend of a Portal so this feature would be a little off-topic for this component.

@romkor
Copy link
Owner

romkor commented Nov 13, 2020

I clean all the dom children before appendChild

@AlgoTrader it can lead to memory leaks if you just remove all inner elements including svelte rendered components.

@romkor
Copy link
Owner

romkor commented Nov 13, 2020

As I said current implementation of svelte-portal do not allow you safely replace target's content. And I do not plan to add this feature in near future, so I will close this issue.

@romkor romkor closed this as completed Nov 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants