You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While developing a site with plain HTML and React custom elements mixed together (using https://github.com/PixelsCommander/ReactiveElements), editing content with live preview makes all event listeners in the React custom elements to stop functioning after the first edit of some content.
This is probably due to the fact that React attaches a global event listener, and when the HTML is overwritten with new content fetched with AJAX, the event listener is attach to a non-existing document root and not working until you do a hard page refresh.
I took a look at LivePreview.js and did some local debugging and modifications and got it working by inserting a new <iframe> on each successfull update, instead of just overwriting the html of the existing <iframe>. By inserting a new <iframe>, the HTML document is a new instance, and all event listeners keeps working as expected.
Basically I changed handleSuccess in LivePreview.js to this:
This needs to be tidied up of course (for instance, the <iframe> should be replaced instead of appened to the container or else you end up with a lot of iframes), but is works as a proof of concept for a better approach to updating the iframe with new content.
The text was updated successfully, but these errors were encountered:
andersaloof
changed the title
Feature Request: Insert new <iframe> on each live preview update instead of just overwriting h
Feature Request: Insert new <iframe> on each live preview update
Oct 10, 2018
+1 for replacing $iframe on each update instead of appending to$iframeContainer. This way, plugins can still change the Live Preview structure (e.g. Breakpoint).
While developing a site with plain HTML and React custom elements mixed together (using https://github.com/PixelsCommander/ReactiveElements), editing content with live preview makes all event listeners in the React custom elements to stop functioning after the first edit of some content.
This is probably due to the fact that React attaches a global event listener, and when the HTML is overwritten with new content fetched with AJAX, the event listener is attach to a non-existing document root and not working until you do a hard page refresh.
A related issue to this feature request is #2120.
I took a look at
LivePreview.js
and did some local debugging and modifications and got it working by inserting a new<iframe>
on each successfull update, instead of just overwriting the html of the existing<iframe>
. By inserting a new<iframe>
, the HTML document is a new instance, and all event listeners keeps working as expected.Basically I changed
handleSuccess
inLivePreview.js
to this:This needs to be tidied up of course (for instance, the
<iframe>
should be replaced instead of appened to the container or else you end up with a lot of iframes), but is works as a proof of concept for a better approach to updating the iframe with new content.The text was updated successfully, but these errors were encountered: