<?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>216240</bug_id>
          
          <creation_ts>2020-09-07 03:49:52 -0700</creation_ts>
          <short_desc>vw units doesn&apos;t get updated inside shadow trees as frame is resized</short_desc>
          <delta_ts>2022-07-05 12:10:35 -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>Safari 13</version>
          <rep_platform>Mac</rep_platform>
          <op_sys>macOS 10.14</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Major</bug_severity>
          <target_milestone>---</target_milestone>
          
          <blocked>148695</blocked>
          <everconfirmed>1</everconfirmed>
          <reporter name="Roman Prudnikov">rayproudnikoff</reporter>
          <assigned_to name="Ryosuke Niwa">rniwa</assigned_to>
          <cc>bfulgham</cc>
    
    <cc>hi</cc>
    
    <cc>koivisto</cc>
    
    <cc>rniwa</cc>
    
    <cc>simon.fraser</cc>
    
    <cc>vahan.hartooni</cc>
    
    <cc>webkit-bug-importer</cc>
    
    <cc>zalan</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1686334</commentid>
    <comment_count>0</comment_count>
    <who name="Roman Prudnikov">rayproudnikoff</who>
    <bug_when>2020-09-07 03:49:52 -0700</bug_when>
    <thetext>Summary:
Elements inside a custom element with a shadow tree render strangely if they&apos;re positioned fixed/absolute with vw units from left/right. First render looks correct, but if the page has been resized in width, the element stays the same, not following its left/right property, resulting in being outside of the viewport.

Reproduce:
https://jsfiddle.net/tuk1905w/3/

1. Create a custom element
2. Attach Shadow with &quot;mode: open&quot;
3. Append an element
4. Add styling to that element so it has &quot;position: fixed&quot; and &quot;left: calc(100vw - 100px)&quot;
5. Resize the window changing its width
6. The element positioned strangely, not the way when it&apos;s outside a shadow tree

Workaround (the way I fixed it):
https://jsfiddle.net/y4azr6t5/

On the resize handler I set a custom value to `window.innerWidth * 0.01` and use that custom value to position the element inside the shadow tree.

JS:
```
  const vw = window.innerWidth * 0.01
  document.documentElement.style.setProperty(&quot;--vw&quot;, `${vw}px`)
```
CSS:
```
button {
  left: calc((var(--vw, 1vw) * 100) - 200px);
}
```

Note:
Interesting that if I open web inspector and change any value of that positioned element Safari rerenders it correctly. But it works only until next resize.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1686587</commentid>
    <comment_count>1</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2020-09-08 09:43:36 -0700</bug_when>
    <thetext>&lt;rdar://problem/68513285&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1874083</commentid>
    <comment_count>2</comment_count>
    <who name="Vahan Hartooni">vahan.hartooni</who>
    <bug_when>2022-06-03 17:32:02 -0700</bug_when>
    <thetext>This doesn&apos;t just affect positioning, but dimensions as well. Take for example this example: https://jsfiddle.net/auzekghL/

When you resize the window, the blue box doesn&apos;t update it&apos;s width or height to fit the window.

Compare that to this blue box which does: https://jsfiddle.net/1jyacbzh/

Both blue boxes have these two css rules:

  height: calc(100vh - 50px);
  width: 100vw;

But the first one is in a shadow dom.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1874332</commentid>
    <comment_count>3</comment_count>
    <who name="Vahan Hartooni">vahan.hartooni</who>
    <bug_when>2022-06-06 11:35:16 -0700</bug_when>
    <thetext>There is a workaround where you can apply `width: 100vw` on the `:host`: https://jsfiddle.net/3kxn0veh/

Unfortunately, you can&apos;t utilize the same technique on height: https://jsfiddle.net/3nktrqw9/</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1880540</commentid>
    <comment_count>4</comment_count>
    <who name="Ryosuke Niwa">rniwa</who>
    <bug_when>2022-07-04 10:48:02 -0700</bug_when>
    <thetext>This is a bug in Document::updateViewportUnitsOnResize(). It needs to iterate over all shadow roots &amp; invalidate styles instead of just at the document level.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1880541</commentid>
    <comment_count>5</comment_count>
      <attachid>460657</attachid>
    <who name="Ryosuke Niwa">rniwa</who>
    <bug_when>2022-07-04 10:55:49 -0700</bug_when>
    <thetext>Created attachment 460657
WIP</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1880554</commentid>
    <comment_count>6</comment_count>
    <who name="Ryosuke Niwa">rniwa</who>
    <bug_when>2022-07-04 11:21:13 -0700</bug_when>
    <thetext>Pull request: https://github.com/WebKit/WebKit/pull/2061</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1880566</commentid>
    <comment_count>7</comment_count>
    <who name="Ryosuke Niwa">rniwa</who>
    <bug_when>2022-07-04 12:14:58 -0700</bug_when>
    <thetext>Pull request: https://github.com/WebKit/WebKit/pull/2062</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1880759</commentid>
    <comment_count>8</comment_count>
    <who name="EWS">ews-feeder</who>
    <bug_when>2022-07-05 12:10:32 -0700</bug_when>
    <thetext>Committed 252149@main (50df76018d84): &lt;https://commits.webkit.org/252149@main&gt;

Reviewed commits have been landed. Closing PR #2062 and removing active labels.</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>460657</attachid>
            <date>2022-07-04 10:55:49 -0700</date>
            <delta_ts>2022-07-04 10:55:49 -0700</delta_ts>
            <desc>WIP</desc>
            <filename>wip216240.patch</filename>
            <type>text/plain</type>
            <size>1034</size>
            <attacher name="Ryosuke Niwa">rniwa</attacher>
            
              <data encoding="base64">ZGlmZiAtLWdpd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YXV0byogcmVuZGVyZXIgPSBlbGVtZW50LT5yZW5kZXJlcigpOworICAg
ICAgICAgICAgaWYgKHJlbmRlcmVyICYmIHJlbmRlcmVyLT5zdHlsZSgpLnVzZXNWaWV3cG9ydFVu
aXRzKCkpCisgICAgICAgICAgICAgICAgZWxlbWVudC0+aW52YWxpZGF0ZVN0eWxlKCk7CisgICAg
ICAgIH0KKyAgICB9CiB9CiAKIHZvaWQgRG9jdW1lbnQ6OnNldE5lZWRzRE9NV2luZG93UmVzaXpl
RXZlbnQoKQo=
</data>

          </attachment>
      

    </bug>

</bugzilla>