<?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>297232</bug_id>
          
          <creation_ts>2025-08-11 12:24:14 -0700</creation_ts>
          <short_desc>REGRESSION (Safari 18.5): `@media print` does not work when nested</short_desc>
          <delta_ts>2025-08-18 10:31:52 -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>CSS</component>
          <version>Safari 18</version>
          <rep_platform>All</rep_platform>
          <op_sys>All</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>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Jordan Pittman">jordan</reporter>
          <assigned_to name="Matthieu Dubet">m_dubet</assigned_to>
          <cc>koivisto</cc>
    
    <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>2135699</commentid>
    <comment_count>0</comment_count>
      <attachid>476359</attachid>
    <who name="Jordan Pittman">jordan</who>
    <bug_when>2025-08-11 12:24:14 -0700</bug_when>
    <thetext>Created attachment 476359
Example document demonstrating the bug

If you print a page with the following in Safari you&apos;ll see that the div is still visible:

```html
&lt;style&gt;
  .hidden {
    @media print {
      display: none;
    }
  }
&lt;/style&gt;
&lt;div class=&quot;hidden&quot;&gt;FAIL if visible on print&lt;/div&gt;
```

This is *not* the case if the media query wraps the rules as this works:

```html
&lt;style&gt;
  .hidden {
    @media print {
      display: none;
    }
  }
&lt;/style&gt;
&lt;div class=&quot;hidden&quot;&gt;FAIL if visible on print&lt;/div&gt;
```

I haven&apos;t yet found a workaround that allows nesting to work here in Safari.

Tested on:
- macOS 15, macOS 26, iOS 18, iOS 26

- Safari 17.3–18.4 (works)
- Safari 18.5–18.6 (broken)
- Safari 26 and TP (broken)
- Webkit Nightly (broken)
- Firefox (works)
- Chrome (works)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2135705</commentid>
    <comment_count>1</comment_count>
    <who name="Jordan Pittman">jordan</who>
    <bug_when>2025-08-11 12:31:41 -0700</bug_when>
    <thetext>I meant to put the nightly/build archive version I tested which was the latest as of this bug report: 298509@main</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2135749</commentid>
    <comment_count>2</comment_count>
    <who name="Jordan Pittman">jordan</who>
    <bug_when>2025-08-11 14:28:26 -0700</bug_when>
    <thetext>Whoops I typo&apos;d the second one. The example file is correct though.

Was supposed to be this:
```html
&lt;style&gt;
  @media print {
    .hidden {
      display: none;
    }
  }
&lt;/style&gt;
&lt;div class=&quot;hidden&quot;&gt;FAIL if visible on print&lt;/div&gt;
```</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2135793</commentid>
    <comment_count>3</comment_count>
    <who name="Alexey Proskuryakov">ap</who>
    <bug_when>2025-08-11 16:28:38 -0700</bug_when>
    <thetext>Thank you for such detailed regression information, and the minimized test case!</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2135794</commentid>
    <comment_count>4</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2025-08-11 16:28:49 -0700</bug_when>
    <thetext>&lt;rdar://problem/158081814&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2136462</commentid>
    <comment_count>5</comment_count>
    <who name="Matthieu Dubet">m_dubet</who>
    <bug_when>2025-08-14 06:09:54 -0700</bug_when>
    <thetext>Pull request: https://github.com/WebKit/WebKit/pull/49387</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2137167</commentid>
    <comment_count>6</comment_count>
    <who name="EWS">ews-feeder</who>
    <bug_when>2025-08-18 10:31:50 -0700</bug_when>
    <thetext>Committed 298843@main (e001647e607b): &lt;https://commits.webkit.org/298843@main&gt;

Reviewed commits have been landed. Closing PR #49387 and removing active labels.</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>476359</attachid>
            <date>2025-08-11 12:24:14 -0700</date>
            <delta_ts>2025-08-11 12:24:14 -0700</delta_ts>
            <desc>Example document demonstrating the bug</desc>
            <filename>bug.html</filename>
            <type>text/html</type>
            <size>390</size>
            <attacher name="Jordan Pittman">jordan</attacher>
            
              <data encoding="base64">PCFkb2N0eXBlIGh0bWw+CjxzdHlsZT4KICAucHJpbnQtaGlkZGVuLW5lc3RlZCB7CiAgICBAbWVk
aWEgcHJpbnQgewogICAgICBkaXNwbGF5OiBub25lOwogICAgfQogIH0KICBAbWVkaWEgcHJpbnQg
ewogICAgLnByaW50LWhpZGRlbi13cmFwcGVkIHsKICAgICAgZGlzcGxheTogbm9uZTsKICAgIH0K
ICB9Cjwvc3R5bGU+CjxkaXYgY2xhc3M9InByaW50LWhpZGRlbi1uZXN0ZWQiPkZBSUwgaWYgdmlz
aWJsZSBvbiBwcmludCAobmVzdGVkKTwvZGl2Pgo8ZGl2IGNsYXNzPSJwcmludC1oaWRkZW4td3Jh
cHBlZCI+RkFJTCBpZiB2aXNpYmxlIG9uIHByaW50ICh3cmFwcGVkKTwvZGl2Pgo8YnV0dG9uIG9u
Y2xpY2s9IndpbmRvdy5wcmludCgpIj5QcmludCB0aGlzIHBhZ2U8L2J1dHRvbj4K
</data>

          </attachment>
      

    </bug>

</bugzilla>