WebKit Bugzilla
New
Browse
Search+
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
NEW
328087
Shadow root added after a viewport change matches @media rules against the old viewport
https://bugs.webkit.org/show_bug.cgi?id=328087
Summary
Shadow root added after a viewport change matches @media rules against the ol...
Yury Semikhatsky
Reported
2026-10-19 10:46:05 PDT
Created
attachment 481908
[details]
repro A shadow root created after the viewport changes can resolve its @media rules against the previous viewport size, while matchMedia() in the same document already reports the new one. It happens when no shadow root using the same style sheet is in the document while the viewport changes. Steps to reproduce: 1. Open the attached shadow-media.html. The page resizes an iframe between 800px and 320px. Before each resize it removes the shadow root it added at the previous step. After the resize it adds a new shadow root whose <style> sets ::after content to "wide", or to "narrow" under @media (max-width: 500px), and compares it with matchMedia('(max-width: 500px)') in the iframe. A second run removes the previous shadow root only after the resize. Expected: At 320px the new shadow root says "narrow", like matchMedia(). Actual: In the first run, the shadow root added at 320px still says "wide". The second run is correct. Old shadow root removed before each resize: 800px: shadow root says wide, matchMedia says wide ok 320px: shadow root says wide, matchMedia says narrow <-- STALE 800px: shadow root says wide, matchMedia says wide ok 320px: shadow root says wide, matchMedia says narrow <-- STALE Old shadow root kept in the document during the resize: 800px: shadow root says wide, matchMedia says wide ok 320px: shadow root says narrow, matchMedia says narrow ok 800px: shadow root says wide, matchMedia says wide ok 320px: shadow root says narrow, matchMedia says narrow ok Reproduces in Safari Technology Preview (27.0, 21627.1.2.1) on macOS 26.7.1. Chrome 156 and Firefox 158 are correct in both runs. It is not a recent regression: it also reproduces with WebKit main from 2026-07-19, the oldest build I could test. Originally reported to Playwright, where web components created after page.setViewportSize() kept the layout for the previous size:
https://github.com/microsoft/playwright/issues/43501
Attachments
repro
(2.25 KB, text/html)
2026-10-19 10:46 PDT
,
Yury Semikhatsky
no flags
Details
View All
Add attachment
proposed patch, testcase, etc.
Radar WebKit Bug Importer
Comment 1
2026-10-19 19:39:02 PDT
<
rdar://problem/190481095
>
Ahmad Saleem
Comment 2
2026-10-19 19:40:22 PDT
Pull request:
https://github.com/WebKit/WebKit/pull/77596
Anthony Frehner
Comment 3
2026-10-28 04:15:55 PDT
At Shopify we have ran into this too -- thank Ahmad for getting a PR up!
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