MarshallOfSound / react-electron-web-view

A simple wrapper to make Electrons WebView compatible with React
MIT License
65 stars 30 forks source link

Unexpected issue with 'did-attach' event handler #3

Closed runningdemo closed 7 years ago

runningdemo commented 7 years ago

The did-attach handler code:

const WebView = require('react-electron-web-view');

I put this <WebView/> in a div element. Then every time I toggle the div CSS property from display: none to display: block the did-attach event handler get called. That will causes event hander set on <WebView/> element be attached many times.

I attempt to dig more into how does did-attach event work, but I can't find information about the event. Can you give me some document link about the did-attach event. So I can help on this issue.

MarshallOfSound commented 7 years ago

@liaa You shouldn't really hide a WebView by setting display: none. You should even unmount completely if you want to destroy it, or use flex: 0 / width: 0 to conceal it.

runningdemo commented 7 years ago

I know flex:0 / width: 0 can make an element disappear visually. But the did-attach event behaves really odd when its parent element's property display changed. So I want to dig more into why this odd behave happens. I can't find more information when I search google about html element did-attach event or electron webview did-attach event. Or should I dig into electron source code to find it, thanks.

MarshallOfSound commented 7 years ago

@liaa I believe it is just the way guest contents work in Chromium. They automatically detach and attach when they toggle between visible and not visible.