preact-portal icon indicating copy to clipboard operation
preact-portal copied to clipboard

Portal re-appends content in IE

Open gpoitch opened this issue 8 years ago • 16 comments

Simple counter, portal-ing the display elsewhere: http://jsfiddle.net/50gz1mde/2/

Works as expected in Chrome, Safari, Firefox In IE Edge, 11, 10, 9, it seemingly randomly duplicates the the portal content:

screen shot 2016-11-01 at 11 07 37 pm

gpoitch avatar Nov 02 '16 03:11 gpoitch

Hmm, very funky. Trying to think of what could cause this 🕵

developit avatar Nov 02 '16 03:11 developit

If I press the button rapidly, it works as expected. Pausing for a second or 2 then pressing it again triggers the bug. Very odd.

gpoitch avatar Nov 02 '16 03:11 gpoitch

I wonder... Is it possible there's a browser plugin or something mutating the DOM?

developit avatar Nov 02 '16 03:11 developit

Using a fresh, stock Edge and IE on a Windows 10 VM, so no plugins

gpoitch avatar Nov 02 '16 03:11 gpoitch

Good to know. Very weird ...

developit avatar Nov 02 '16 03:11 developit

@developit changing Portal's render function to return <div></div> instead of null fixes it. Maybe some kind of garbage collection issue?

gpoitch avatar Nov 02 '16 16:11 gpoitch

Very strange... yeah could be that or something funky with TextNode normalization

developit avatar Nov 02 '16 17:11 developit

Removing all whitespace from the jsx was my first attempt to fix, as I remember IE being weird with text nodes.

gpoitch avatar Nov 02 '16 17:11 gpoitch

Most times JSX will collapse it. I'll try to look deeper into this tonight!

developit avatar Nov 02 '16 17:11 developit

Just checked this again on preact 7.2.0 which I believe contains some fixes that may be related to this, but the issue still occurs. http://jsfiddle.net/50gz1mde/4/

gpoitch avatar Jan 25 '17 15:01 gpoitch

Strange, not sure why that would be.

developit avatar Jan 25 '17 22:01 developit

Yeah, am having the same experience with IE11 on this issue. Will try to see if I can get it to give up a specific case where this is consistently reproducible.

KrofDrakula avatar Feb 17 '17 13:02 KrofDrakula

OK, found a workaround for this issue if it helps debugging:

https://jsfiddle.net/pzaafu34/

The relevant bit is:

<Portal into="#target" ref={ref => this._portal = ref}>

For some reason, the reference assignment prevents the node from being duplicated when rerendering. I haven't pin-pointed the exact cause or reason why this would fix it, but it is a (mostly working) workaround for the time being. There are still some issues with event handlers.

KrofDrakula avatar Feb 20 '17 17:02 KrofDrakula

That makes sense - we were seeing that storing a reference to empty Text nodes in IE keeps them from being normalized away.

developit avatar Feb 20 '17 18:02 developit

The above workaround is still required in 8.0-beta.

KrofDrakula avatar Apr 06 '17 10:04 KrofDrakula

@KrofDrakula Thanks for sharing the workaround. Adding the ref assignment directly to the <Portal> element itself didn't work for me, but putting it on the direct child of the <Portal> element seems to work.

rmacklin avatar Sep 26 '17 02:09 rmacklin