WebKit Bugzilla
New
Browse
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
RESOLVED FIXED
216240
vw units doesn't get updated inside shadow trees as frame is resized
https://bugs.webkit.org/show_bug.cgi?id=216240
Summary
vw units doesn't get updated inside shadow trees as frame is resized
Roman Prudnikov
Reported
2020-09-07 03:49:52 PDT
Summary: Elements inside a custom element with a shadow tree render strangely if they'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 "mode: open" 3. Append an element 4. Add styling to that element so it has "position: fixed" and "left: calc(100vw - 100px)" 5. Resize the window changing its width 6. The element positioned strangely, not the way when it'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("--vw", `${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.
Attachments
WIP
(1.01 KB, patch)
2022-07-04 10:55 PDT
,
Ryosuke Niwa
no flags
Details
Formatted Diff
Diff
View All
Add attachment
proposed patch, testcase, etc.
Radar WebKit Bug Importer
Comment 1
2020-09-08 09:43:36 PDT
<
rdar://problem/68513285
>
Vahan Hartooni
Comment 2
2022-06-03 17:32:02 PDT
This doesn'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't update it'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.
Vahan Hartooni
Comment 3
2022-06-06 11:35:16 PDT
There is a workaround where you can apply `width: 100vw` on the `:host`:
https://jsfiddle.net/3kxn0veh/
Unfortunately, you can't utilize the same technique on height:
https://jsfiddle.net/3nktrqw9/
Ryosuke Niwa
Comment 4
2022-07-04 10:48:02 PDT
This is a bug in Document::updateViewportUnitsOnResize(). It needs to iterate over all shadow roots & invalidate styles instead of just at the document level.
Ryosuke Niwa
Comment 5
2022-07-04 10:55:49 PDT
Created
attachment 460657
[details]
WIP
Ryosuke Niwa
Comment 6
2022-07-04 11:21:13 PDT
Pull request:
https://github.com/WebKit/WebKit/pull/2061
Ryosuke Niwa
Comment 7
2022-07-04 12:14:58 PDT
Pull request:
https://github.com/WebKit/WebKit/pull/2062
EWS
Comment 8
2022-07-05 12:10:32 PDT
Committed
252149@main
(50df76018d84): <
https://commits.webkit.org/252149@main
> Reviewed commits have been landed. Closing PR #2062 and removing active labels.
Note
You need to
log in
before you can comment on or make changes to this bug.
Top of Page
Format For Printing
XML
Clone This Bug