<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>145244</bug_id>
          
          <creation_ts>2015-05-20 22:30:32 -0700</creation_ts>
          <short_desc>Page fails to update CSS sometimes when styles are dynamically injected into the page</short_desc>
          <delta_ts>2015-05-21 06:46:14 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>Layout and Rendering</component>
          <version>528+ (Nightly build)</version>
          <rep_platform>Mac (Intel)</rep_platform>
          <op_sys>OS X 10.10</op_sys>
          <bug_status>NEW</bug_status>
          <resolution></resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter>dak</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>dak</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1096488</commentid>
    <comment_count>0</comment_count>
    <who name="">dak</who>
    <bug_when>2015-05-20 22:30:32 -0700</bug_when>
    <thetext>WebKit is apparently failing to update its CSS and redraw the page when &lt;style&gt; tags are dynamically injected into a page.

In the failing code, the &lt;style&gt; tags are being injected inside of the body tag (as &lt;style scoped&gt; — scoped isn&apos;t supported yet, but the styles should still apply globally). I&apos;ve not yet confirmed whether or not this is a necessary condition for the issue.

I&apos;ve been attempting to create a simplified test case for this issue, but have so far been unable to do so. There may be an element of complexity/timing necessary for the issue to manifest itself. At the moment, the issue can be seen at http://32demclub.com (code at https://github.com/DerekKent/32demclub/tree/d0b2dd6dc146b40ea2a7541f1e46522e7eda7711/dist).

I&apos;ll update this issue with a test case if/when I&apos;m able to produce one.

Running the following code after the page has rendered fixes the issue:
```
// Updates the CSS, but some DOM elements are missing
var head = $(&apos;head&apos;);
var style = $(&apos;&lt;style&gt;&apos;);
head.append(style);
style.remove();

// Restores missing DOM elements
$(&apos;#main&apos;).get(0).parentNode.style.cssText += &apos;;-webkit-transform:rotateZ(0deg)&apos;;
$(&apos;#main&apos;).get(0).parentNode.offsetHeight;
$(&apos;#main&apos;).get(0).parentNode.style.cssText += &apos;;-webkit-transform:none&apos;;
```</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1096490</commentid>
    <comment_count>1</comment_count>
    <who name="">dak</who>
    <bug_when>2015-05-20 22:35:16 -0700</bug_when>
    <thetext>Note also that the issue is only apparent on a fresh load with no CSS cached.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1096571</commentid>
    <comment_count>2</comment_count>
    <who name="">dak</who>
    <bug_when>2015-05-21 06:46:14 -0700</bug_when>
    <thetext>It appears that under certain conditions, injected stylesheets are not initially appearing in `document.styleSheets` when injected with a &lt;style&gt; tag somewhere other than the &lt;head&gt;.

Forcing the styles to be recalculated fixes the issue.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>