wagtail-livepreview icon indicating copy to clipboard operation
wagtail-livepreview copied to clipboard

Live preview in separate window does not work when iframe is closed

Open Quadric opened this issue 5 years ago • 1 comments

When i click "live preview" button it opens a new window with page preview. It refreshes in "real time" when i modify my page form so this works OK - but it stops working when i "hide" the iframe on right side of page form. If i show it again the separate full windows refreshes again.

// EDIT OK i see that when i turn off iframe form does not make POST to live_preview thats why this separate full windows does not see changes when refreshes body.

Do you have any idea why it happens and how to fix it?

Quadric avatar Oct 28 '19 08:10 Quadric

Hey @Quadric

I have the JavaScript not sending updates in the Wagtail admin when the live preview iframe is closed. My thinking was: if the iframe is closed the server shouldn't need to support requests it's not going to use. But I hadn't thought about the livepreview in a new window situation.

I'd like to stick to my original idea of not sending requests to the server if the iframe is closed, but adding livepreview window support is definitely important. I think there could be a very simple solution; it could be as easy as a file or simple query lookup. My idea is.. if someone clicked the Live Preview button it will open a new tab — it could also send a request to the server to create a file (or table row) to mark the page as "currently in live preview window". When that flag is active, the JavaScript could continue to send updates to the server even if the iframe is closed. The flag would need an active-until timestamp that's no more than 1 minute a head of right now, this way when the livepreview window is closed (and there isn't JavaScript support to detect when the window is closed) and the iframe is also closed, it doesn't keep sending requests to the server.

That's just my initial idea ¯_(ツ)_/¯ Im happy to discuss other ideas or improvements though! And I'm also happy to take PRSs!

KalobTaulien avatar Feb 17 '20 03:02 KalobTaulien