Bug 39286 - SVG DOM inside an embed isn't preserved when display:none is set
Summary: SVG DOM inside an embed isn't preserved when display:none is set
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: SVG (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P2 Normal
Assignee: Nobody
: 45389 (view as bug list)
Depends on: 45049
  Show dependency treegraph
Reported: 2010-05-18 05:19 PDT by steve.horsley
Modified: 2011-12-10 01:36 PST (History)
6 users (show)

See Also:

reduced test case (1.11 KB, text/html)
2010-05-18 13:30 PDT, Alexey Proskuryakov
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description steve.horsley 2010-05-18 05:19:12 PDT
An SVG graph is drawn in the DOM by javascript. If the div is hidden and then restored(by setting Display to "none" and back to "block"), all the dynamic DOM elements have disappeared. Also, after hidihg and re-showing the graph, the non-dynamic SVG <g> element can no longer have dynamically generated children added to it.

The URL gives a small demo of the problem. I can hide the graph by setting the div visibility to "hidden" and the graph is still there after setting it visible again, but in this case it still occupies screen space which I don't want. So
Comment 1 steve.horsley 2010-05-18 05:22:07 PDT
I couldn't get the nightly build to run. The problem I'm reporting is present on Google Chrome on XP version (45376) and also on Chromium on Linux version 5.0.342.9 (43360) Ubuntu.
Comment 2 Alexey Proskuryakov 2010-05-18 13:26:58 PDT
This is almost the same as bug 27775, but with SVG instead of a plug-in. But in this case, there is an easy workaround - there is no need to use <embed> to display SVG, it can be inserted directly into HTML content, or into an iframe.
Comment 3 Alexey Proskuryakov 2010-05-18 13:30:17 PDT
Created attachment 56408 [details]
reduced test case
Comment 4 steve.horsley 2010-05-27 00:25:22 PDT
Yes, inlining the SVG into xhtml is a usable workround, thanks. Of course, that means serving different pages to different browsers (IE) which is a nuisance, but that's not Chromium's problem, and on the other hand it opens new possibilities for modern browsers.
Comment 5 Mike Capp 2010-10-18 06:07:46 PDT
Confirming on Chrome 6.0.472.63 and Safari 5.0.2, both on Win2003.

Steve, have you tried combining visibility:hidden with position:absolute as a workaround? That ought to prevent it messing up layout.
Comment 6 Darin Adler 2010-10-18 08:17:43 PDT
*** Bug 45389 has been marked as a duplicate of this bug. ***
Comment 7 steve.horsley 2010-10-19 03:42:31 PDT
"Steve, have you tried combining visibility:hidden with position:absolute as a workaround?"

No, I went for XHTML in the end. I realised that if I serve XHTML, then Firefox users could save the whole active page as a file for later reference (right-click, save page as...), which is a useful thing for them to be able to do. 

It's a shame that doesn't work in Chromium too, but Chromium also saves the dynamic DOM content as static SVG so you get double-images when viewing the saved file.
Comment 8 Eric Seidel (no email) 2011-12-09 16:02:56 PST
The reduction can't work due to data: urls having unique origins (at least in Chrome):

Unsafe JavaScript attempt to access frame with URL data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="0 0 1000 400"><g id="layer1"/></svg> from frame with URL https://bug-39286-attachments.webkit.org/attachment.cgi?id=56408. Domains, protocols and ports must match.
attachment.cgi:8Uncaught TypeError: Cannot call method 'getElementById' of undefined